From patchwork Thu Jun 1 12:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp276761vqr; Thu, 1 Jun 2023 05:18:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Y+Q5ljuqekC4iM3chT5S7uw5hG42i43lJmC4An4c/UFzs9eOWnyn/hZ4jHtSGE6aX9kjv X-Received: by 2002:a17:903:32c1:b0:1b1:9f8a:6c18 with SMTP id i1-20020a17090332c100b001b19f8a6c18mr1658770plr.25.1685621927839; Thu, 01 Jun 2023 05:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621927; cv=none; d=google.com; s=arc-20160816; b=1ABcVOLSweXZhqI1fbSleb+i9ltDfpnlrHZtQ2X98bpw1mrbfyvserKW5Pocip3Anr Z6B6Qp0GIJN+evmWO9FHuEfQfehLCU6SurIVbAz+AZXsCcZoliMLo0m1Of28hsV3GJOt 4W/jYJZnvbDZeHT4PMidHPk5WRWlaY3hA0oFY8KswuKkH4sPXMqXFqoNjYlj0nI5NZfp VlAor84lAVU6zSzgsfFC4KPAsgesQidqJ+FNaBqxhpwZ1K6N400iYZ0HQP9CUtBc4k+X 7z1VePXeXg+viSTLdK/4llLNeZOuw4u59P122wnOSy83WdWs8RxaidioY/94lQ2vn0aW cvFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5ljdHkPoU5MejoqBeV2J75M9dciUOY7wvi5BEm8GiXc=; b=Jp0oPMxtW0Gcuq7ApAA5KSAqfVrE+RHtl9gF2rP2fozTpNKgshoyZE83kREn8vuxun nG2M6mFoDeMAkF+4H4vA7NbNQikQewkz0dIGV1EU0NcRsiXuX4LVj09xYW7RisRtEGS1 RrXqCwJDN+eX6KGyHbqtZRZ5MKcUVMOXtHwR1HXRdQgJ5St9VpybVgZVQbKppN7/LHhb rO+Gu437WsApusJfczxKbPrAkMeBu9MvmxPfRei313+/bMteHcB9UsKJY3c7cI6RfNoS tSvAptz7O9kWUKAyzbkGWCpbSSTWSuWDzwhuQyFF6n5B7Wdx4n6TwtKCKslSyI1yNLnb mqBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dndPaLuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a170902eccf00b001ab2a9fcd3esi2840796plh.378.2023.06.01.05.18.33; Thu, 01 Jun 2023 05:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dndPaLuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233253AbjFAMK1 (ORCPT + 99 others); Thu, 1 Jun 2023 08:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232354AbjFAMKY (ORCPT ); Thu, 1 Jun 2023 08:10:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD9E9D; Thu, 1 Jun 2023 05:10:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 08E6263AD1; Thu, 1 Jun 2023 12:10:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55101C433A0; Thu, 1 Jun 2023 12:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621422; bh=55J1SOTttemYkQioALMfaeUBYxrKSl0Zn4cIRDrkVGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dndPaLuh9e+HMEwJ+Uk1OJvpmPjg4s25oxEMSJ1KuSM4fy8oEoacZZVcpsndxQUCz ICwcTH4nNkmN+pEObHcwbxr3urnb4XyNj4jdiIwFvifpNDph5ti5mCzeJ0OlvEzTaT n0WB5IbXLIp/BiQStZFKtHbtdjDB7NlEvRm19VBHyxwyD0SKJxl2xVkEYg0ajVyWF/ W7W+OuisE56taDpE3SLaWTJZV7DdDdGYPGC+uGn/YCid6cJPJUbTpDJeml5SUAY6Zp icewSeIoXae/2NS/4f6ehjkKpAXZCD+7P5Tgw9XWmhg64zfQoKWeUmAI0HrqRdjnes ccLksn7uCz5SA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Sam Ravnborg Subject: [PATCH 1/7] modpost: fix section mismatch message for R_ARM_ABS32 Date: Thu, 1 Jun 2023 21:09:55 +0900 Message-Id: <20230601121001.1071533-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502698211324629?= X-GMAIL-MSGID: =?utf-8?q?1767502698211324629?= addend_arm_rel() processes R_ARM_ABS32 in a wrong way. Here, test code. [test code 1] #include int __initdata foo; int get_foo(void) { return foo; } If you compile it with ARM versatile_defconfig, modpost will show the symbol name, (unknown). WARNING: modpost: vmlinux.o: section mismatch in reference: get_foo (section: .text) -> (unknown) (section: .init.data) (You need to use GNU linker instead of LLD to reproduce it.) If you compile it for other architectures, modpost will show the correct symbol name. WARNING: modpost: vmlinux.o: section mismatch in reference: get_foo (section: .text) -> foo (section: .init.data) For R_ARM_ABS32, addend_arm_rel() sets r->r_addend to a wrong value. I just mimicked the code in arch/arm/kernel/module.c. However, there is more difficulty for ARM. Here, test code. [test code 2] #include int __initdata foo; int get_foo(void) { return foo; } int __initdata bar; int get_bar(void) { return bar; } With this commit applied, modpost will show the following messages for ARM versatile_defconfig: WARNING: modpost: vmlinux.o: section mismatch in reference: get_foo (section: .text) -> foo (section: .init.data) WARNING: modpost: vmlinux.o: section mismatch in reference: get_bar (section: .text) -> foo (section: .init.data) The reference from 'get_bar' to 'foo' seems wrong. I have no solution for this because it is true in assembly level. In the following output, relocation at 0x1c is no longer associated with 'bar'. The two relocation entries point to the same symbol, and the offset to 'bar' is encoded in the instruction 'r0, [r3, #4]'. Disassembly of section .text: 00000000 : 0: e59f3004 ldr r3, [pc, #4] @ c 4: e5930000 ldr r0, [r3] 8: e12fff1e bx lr c: 00000000 .word 0x00000000 00000010 : 10: e59f3004 ldr r3, [pc, #4] @ 1c 14: e5930004 ldr r0, [r3, #4] 18: e12fff1e bx lr 1c: 00000000 .word 0x00000000 Relocation section '.rel.text' at offset 0x244 contains 2 entries: Offset Info Type Sym.Value Sym. Name 0000000c 00000c02 R_ARM_ABS32 00000000 .init.data 0000001c 00000c02 R_ARM_ABS32 00000000 .init.data When find_elf_symbol() gets into a situation where relsym->st_name is zero, there is no guarantee to get the symbol name as written in C. I am keeping the current logic because it is useful in many architectures, but the symbol name is not always correct depending on the optimization. I left some comments in find_tosym(). Fixes: 56a974fa2d59 ("kbuild: make better section mismatch reports on arm") Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 7031e5da62e5..c68dad45ace2 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1094,6 +1094,10 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf64_Sword addr, if (relsym->st_name != 0) return relsym; + /* + * Strive to find a better symbol name, but the resulting name may not + * match the symbol referenced in the original code. + */ relsym_secindex = get_secindex(elf, relsym); for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { if (get_secindex(elf, sym) != relsym_secindex) @@ -1276,12 +1280,14 @@ static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); + Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info); + void *loc = reloc_location(elf, sechdr, r); + uint32_t inst; switch (r_typ) { case R_ARM_ABS32: - /* From ARM ABI: (S + A) | T */ - r->r_addend = (int)(long) - (elf->symtab_start + ELF_R_SYM(r->r_info)); + inst = TO_NATIVE(*(uint32_t *)loc); + r->r_addend = inst + sym->st_value; break; case R_ARM_PC24: case R_ARM_CALL: From patchwork Thu Jun 1 12:09:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp271938vqr; Thu, 1 Jun 2023 05:12:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64jvSLcdCWuwNSMrHl2q8025BnJTJUI4IYVdcGvH/eWeKgCOXOR93mZ7FEErI2/MWGng4l X-Received: by 2002:a05:6a21:100f:b0:10b:9527:7127 with SMTP id nk15-20020a056a21100f00b0010b95277127mr5162579pzb.20.1685621555339; Thu, 01 Jun 2023 05:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621555; cv=none; d=google.com; s=arc-20160816; b=LaT4NYaFaDrHf8dDRgGM91tZpKQcv5jGQu5AcEf3sBKHrgeaklmHHi5/PUDvC9pvJ9 EPD/IdqAkVeh6LZyQySvYdVmorThPnKKeGY5irfruvlKEV2gcYzoqnFTgz860tsUwgPQ 0yKO0PCn4RcJeQsEiEE/Hf1kakzDBYw+mazVw+y0XVMYFEOH16TwdYAqcsaWBW1rphfn mXIjOYSUPv9WaWg5o3m8cKm9IO5r8XqjyDKWCRX8yl/yf7OWst4813OBk08xgU2sj0GJ /1VVRWu5b2JJR/mBYcB6wpLbMP1dzcRSVdza4s8yhvjAcg+b15u8YEJEefmMq7pcZib4 vBXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VleltZEWy4frUbHgyCM/V9lHRfeI2EcU8uutQw7GIzU=; b=z+eFJovkvR+ZpVOX2YdLfN/mE8+1hm9DI5wiqoIKqGYXrXQcaV8PUj+qA+dU5+E7p0 Le2U2F1ekCY40Nbb+zlT7k0oda4IpkV6Qw8k+vYjfixdHyawNVrYVVBs1e/wK0lkSWVy 2RzjwMNJjln3vZUeWHRffVRpFhkzzdvxcCzYVWqobrdD+iCfLyz1y0SFQUc+Ygo0+Oz3 9KK6IidwjuGpuAUEpOuI6HDWKNMFA8Zyitc7ML1CGTJFSi6U4RWHptUBZ7HWQim6JazA xheEtcy0qzxCBe99VYTIqeGLi4nvD/tl+h5xhKyeSew6IwWD1k6PXaHZYnE/SjxynW5k OzHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AceQvPqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b001adb857fc79si2770563plr.105.2023.06.01.05.12.23; Thu, 01 Jun 2023 05:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AceQvPqR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233276AbjFAMKa (ORCPT + 99 others); Thu, 1 Jun 2023 08:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233247AbjFAMK0 (ORCPT ); Thu, 1 Jun 2023 08:10:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF6F3D7; Thu, 1 Jun 2023 05:10:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8BFA6637B9; Thu, 1 Jun 2023 12:10:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDFB2C433EF; Thu, 1 Jun 2023 12:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621425; bh=PEcdZVhDuhBQ+xzAg//irJiyn8poLhX+cHlMc0n1u9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AceQvPqRM3KtwlgBB5UkRQbl23xq46V7w8u3OwmU6aIrg9u2A62nZGZqxv9Gxn3/j sUDJgsIcdKhl0IHak3JXYxLL0pi2bIvIBu6f+2wk3Z/GvE3ZCraPlnKp9pDbblONYI /ZTpP312891+mBwMGF3SvOAp19x9RJkGSHP+umt4j2eP4iaqTbQv9VIX90mY9w4MPv DRiPoIRK+RenTigsgxon9ZuF38xV/MyW5xwBCpmggPwQZMdzX7VnM9Og0A2neWmHwu W7XOmmrJoabLtV2kTGz2QCfsDBvatNbG8XVKoPxoyOI3yc+ryRtL/Y6RLa60LoWn2g MW62ColJsDfWQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Russell King , Rusty Russell , Sam Ravnborg , Tony Lindgren Subject: [PATCH 2/7] modpost: fix section mismatch message for R_ARM_{PC24,CALL,JUMP24} Date: Thu, 1 Jun 2023 21:09:56 +0900 Message-Id: <20230601121001.1071533-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502308364001084?= X-GMAIL-MSGID: =?utf-8?q?1767502308364001084?= addend_arm_rel() processes R_ARM_PC24, R_ARM_CALL, R_ARM_JUMP24 in a wrong way. Here, test code. [test code for R_ARM_JUMP24] .section .init.text,"ax" bar: bx lr .section .text,"ax" .globl foo foo: b bar [test code for R_ARM_CALL] .section .init.text,"ax" bar: bx lr .section .text,"ax" .globl foo foo: push {lr} bl bar pop {pc} If you compile it with ARM multi_v7_defconfig, modpost will show the symbol name, (unknown). WARNING: modpost: vmlinux.o: section mismatch in reference: foo (section: .text) -> (unknown) (section: .init.text) (You need to use GNU linker instead of LLD to reproduce it.) Fix the code to make modpost show the correct symbol name. I imported (with adjustment) sign_extend32() from include/linux/bitops.h. The '+8' is the compensation for pc-relative instruction. It is documented in "ELF for the Arm Architecture" [1]. "If the relocation is pc-relative then compensation for the PC bias (the PC value is 8 bytes ahead of the executing instruction in Arm state and 4 bytes in Thumb state) must be encoded in the relocation by the object producer." [1]: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst Fixes: 56a974fa2d59 ("kbuild: make better section mismatch reports on arm") Fixes: 6e2e340b59d2 ("ARM: 7324/1: modpost: Fix section warnings for ARM for many compilers") Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c68dad45ace2..e47bba7cfad2 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1277,12 +1277,20 @@ static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) #define R_ARM_THM_JUMP19 51 #endif +static int32_t sign_extend32(int32_t value, int index) +{ + uint8_t shift = 31 - index; + + return (int32_t)(value << shift) >> shift; +} + static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info); void *loc = reloc_location(elf, sechdr, r); uint32_t inst; + int32_t offset; switch (r_typ) { case R_ARM_ABS32: @@ -1292,6 +1300,10 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) case R_ARM_PC24: case R_ARM_CALL: case R_ARM_JUMP24: + inst = TO_NATIVE(*(uint32_t *)loc); + offset = sign_extend32((inst & 0x00ffffff) << 2, 25); + r->r_addend = offset + sym->st_value + 8; + break; case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: case R_ARM_THM_JUMP19: From patchwork Thu Jun 1 12:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp274938vqr; Thu, 1 Jun 2023 05:16:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7I+YF5IT3F3+QXw7PJ9Joo2vq8YvLLxvv0p0G76RIs5eB1veh5EdKPY3KpPjlnLRh/PU5E X-Received: by 2002:a05:6a20:605:b0:10c:3557:399a with SMTP id 5-20020a056a20060500b0010c3557399amr5292698pzl.49.1685621788085; Thu, 01 Jun 2023 05:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621788; cv=none; d=google.com; s=arc-20160816; b=M82L0KBGOOdaXBX+7V+LZOWO0jsOaFdUlqu5K6vvrzlypz2wQng4MKiUdHSJkVIVGs PPZ+Wa/PyP6u5M4W6oacedibWnWlgh8/xaWLuvLMJc00Mbxky1TgdK9kepJuihnpNV/r gPT29DjQAOco66eZVATktuIJLEkmrBKMLt3/jHXm1LHTDJpXjSAw9EM4xtE6aAWa4QI7 xf0b1DCABCnLsIxM3k243Txud+Iz4Y3rzQmRjXEvbSlWAbOeL6LDpApnE3HNQT7gvydK jLYjNfYUcE125nTaKRyHtsFOMrwpqcpsp/s1AnLWqbU/7D7vRcoZ1Ujehp3vPZ8vikyE D1EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IQntcjI7vDuW0F68zq155wS08PSrji0bEUDrJVrP5Xk=; b=unY5CWSmVrWlm+hT48miEKtIK2B2tI95vILUh6VrjB0KRU0nMXiskeiHuY+6jNyHiT eMzBiNcL3IUgqlrzWkMkw2ZTL+2dma4wrJ29iHY2jQyLHTqxdkuE+2Srsq65fdlp4P0o RyH3q/PS3xfhhY+vqz8rkgsI81GTrJpVeOnb/jd8/uA9dyDHEOudO31sM5o1owuj2zz+ dW79Y1y42cGfcrbgcVEhW5F/0srwztib99ENZk9gdsyCJvRpUEVQEWCxr9WGZ6r8goMy rhf3ay1hiNYu4s4T0Vl16XARAothqCtsmI9wkLVJoDIrMyQy44c86W0CMpvnU1vKKOf4 lVWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrhuaH7L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a185-20020a624dc2000000b0063d5f645cacsi5428747pfb.116.2023.06.01.05.16.15; Thu, 01 Jun 2023 05:16:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrhuaH7L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233297AbjFAMKd (ORCPT + 99 others); Thu, 1 Jun 2023 08:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233266AbjFAMK3 (ORCPT ); Thu, 1 Jun 2023 08:10:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD32FC; Thu, 1 Jun 2023 05:10:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6B4463AD1; Thu, 1 Jun 2023 12:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6299FC433A0; Thu, 1 Jun 2023 12:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621427; bh=l8pAEKo80YCNxNTbkTmM13VW7qxFsKV/QhE7nwuJWrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KrhuaH7LZ/RQ/+MSwWzLiNquVNkd0wGhx/fRtIGdvLCiXXpQqO2FqmGhcSWZXYD1C FIGbKvip4KGcAUy48afS7bWi3lsEKbIf1OedIGJKxtK441R00ObOih5QJnDOpWiFnf LaZzKgcngiLE0AKqyN7xALGJWRlEQ790MDueiPj6itTFSTpBnOE8Lx5nnKSqh/2lpb Nnq5CrlxdbfQoXLODJdV6mQOhNlUsZTwrmSCwrTh9vQIMrnS7lVAbhR76z+dopkW7j IVT7pjpIOUaS8kPmMYR9GplggmIeUn9NeMJiKDIxuyuzAWT9zdprm09VicLdOO8lkv 6T+yeXs8xDLbw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 3/7] modpost: detect section mismatch for R_ARM_{MOVW_ABS_NC,MOVT_ABS} Date: Thu, 1 Jun 2023 21:09:57 +0900 Message-Id: <20230601121001.1071533-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502551653951537?= X-GMAIL-MSGID: =?utf-8?q?1767502551653951537?= For ARM defconfig (i.e. multi_v7_defconfig), modpost fails to detect some types of section mismatches. [test code] #include int __initdata foo; int get_foo(void) { return foo; } It is apparently a bad reference, but modpost does not report anything. The test code above produces the following relocations. Relocation section '.rel.text' at offset 0x200 contains 2 entries: Offset Info Type Sym.Value Sym. Name 00000000 0000062b R_ARM_MOVW_ABS_NC 00000000 .LANCHOR0 00000004 0000062c R_ARM_MOVT_ABS 00000000 .LANCHOR0 Currently, R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS are just skipped. Add code to handle them. I checked arch/arm/kernel/module.c to learn how the offset is encoded in the instruction. The referenced symbol in relocation might be a local anchor. If is_valid_name() returns false, let's search for a better symbol name. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index e47bba7cfad2..5a5e802b160c 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1078,7 +1078,7 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) /** * Find symbol based on relocation record info. * In some cases the symbol supplied is a valid symbol so - * return refsym. If st_name != 0 we assume this is a valid symbol. + * return refsym. If is_valid_name() == true, we assume this is a valid symbol. * In other cases the symbol needs to be looked up in the symbol table * based on section and address. * **/ @@ -1091,7 +1091,7 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf64_Sword addr, Elf64_Sword d; unsigned int relsym_secindex; - if (relsym->st_name != 0) + if (is_valid_name(elf, relsym)) return relsym; /* @@ -1297,6 +1297,13 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) inst = TO_NATIVE(*(uint32_t *)loc); r->r_addend = inst + sym->st_value; break; + case R_ARM_MOVW_ABS_NC: + case R_ARM_MOVT_ABS: + inst = TO_NATIVE(*(uint32_t *)loc); + offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), + 15); + r->r_addend = offset + sym->st_value; + break; case R_ARM_PC24: case R_ARM_CALL: case R_ARM_JUMP24: From patchwork Thu Jun 1 12:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp272098vqr; Thu, 1 Jun 2023 05:12:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44qHSgbyvrsxgzF93i3JJ/3/GFdQxZgZKN80CWqEqXEGNsR5IA8WW3F2wWfL7z4yPZmKcZ X-Received: by 2002:a17:90a:ca01:b0:247:8029:fb30 with SMTP id x1-20020a17090aca0100b002478029fb30mr5624505pjt.42.1685621569105; Thu, 01 Jun 2023 05:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621569; cv=none; d=google.com; s=arc-20160816; b=gxEPBJTRqdkssaiH6FyPQAt4fmLwwy3BuYCvs2el19XTuCXmJPieHRN7nIncapsp30 U809FDQLpmIyWQM+/kP5groJQD1eW+ub5eYkI6ZPinutNmMbhmoofd3QunImeuXBbYG2 fIVEOC4Dd/7SIn3C17bO+A+cLv8rJJKprZh1oarWwX3b54jlOax9RaPvi0JUvlrSKiL8 qaB3JUSDz7F4DHZ1G4f5SUQBakZ5O0ZnttAeDRoWNcca1PcOaLpi7at0ZxSK57794koE oUE/XjpQKG3I1LLRrUf+DVvuFM14zTbpK66RbLPdpzqS74Be/FDRWGA7lJZueBqk/WKX 6s4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sd6A36aMnYQSsnd7diYRryIQd/oDFMYHULlW9YfGxms=; b=AOL5vcs50l6MySQtvi2dQ19O31pzGsMoHLkB3yxrnIk2PR3yQkHK5mMwyi1/2peuFO F2tdY4nc/rNir44ol2KUw7uMvVOS4mdHBjG45oDEFR5rxbd/whDzCI2ifPN+OWuOsyKB teScJMhri2Ugheh0UqGdNGUMLtdvu1PzF8Ipzk96CwUpGSITsLn7BQQPqwB1TYsawjE0 AyMJmaaEy82WSLLiKhKJe+e9y+tiZ9/oB2t5OeeO6gDXW0cipE9IBCwroUop+wPPs13R MYWqQV5H8HFStjPtqtYrnoxFVpLrum4zEI88gJCADnQY867RrTIIeJjL17a1ej+M7/Ce MUJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hGgyvVuZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x19-20020a17090a531300b00252b824d13esi1076929pjh.30.2023.06.01.05.12.36; Thu, 01 Jun 2023 05:12:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hGgyvVuZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232499AbjFAMK4 (ORCPT + 99 others); Thu, 1 Jun 2023 08:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbjFAMKg (ORCPT ); Thu, 1 Jun 2023 08:10:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1DD185; Thu, 1 Jun 2023 05:10:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E16D8641A9; Thu, 1 Jun 2023 12:10:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96BC9C433EF; Thu, 1 Jun 2023 12:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621429; bh=TumhD82QuLF3iemxAixVbZIrBkyosIOpPKFtYaO9xHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hGgyvVuZ5OVhoGMX5ceciMv+KWLO8ZPAesvX1NWRUurLKmwfbYvxzOqdr54Vue2/6 EOVfYclvxj7ruH6+I9anSh7koqj0GmxAq+VSrJLipKoykEL2pJSeOQqNdGZaE5eed4 RnhpQY9NeXw2fskX+uNs0feNwN51vqkrP84jkz9DaminwiWeNNP1hbq/fON/6JiW/W 9mOPaHzGkMdioEcOZUH4pH14c7a6HJzJizPXBAtfuvNbaTrXjMRUpnzl7K0tf1W3PT Y6kZ9OqTIBHmqYwhuSiSkKpt7RqU539SLl29uSg8l3wUJubpTIWu2W9634H5YzReiz f4Z4hPIw0Sw8w== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 4/7] modpost: refactor find_fromsym() and find_tosym() Date: Thu, 1 Jun 2023 21:09:58 +0900 Message-Id: <20230601121001.1071533-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502322887325228?= X-GMAIL-MSGID: =?utf-8?q?1767502322887325228?= find_fromsym() and find_tosym() are similar - both of them iterate in the .symtab section and return the nearest symbol. The difference between them is that find_tosym() allows a negative distance, but the distance must be less than 20. Factor out the common part into find_nearest_sym(). Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 95 ++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 59 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 5a5e802b160c..32d56efe3f3b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1075,81 +1075,58 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) return !is_mapping_symbol(name); } -/** - * Find symbol based on relocation record info. - * In some cases the symbol supplied is a valid symbol so - * return refsym. If is_valid_name() == true, we assume this is a valid symbol. - * In other cases the symbol needs to be looked up in the symbol table - * based on section and address. - * **/ -static Elf_Sym *find_tosym(struct elf_info *elf, Elf64_Sword addr, - Elf_Sym *relsym) +/* Look up the nearest symbol based on the section and the address */ +static Elf_Sym *find_nearest_sym(struct elf_info *elf, Elf_Addr addr, + unsigned int secndx, bool allow_negative, + Elf_Addr min_distance) { Elf_Sym *sym; Elf_Sym *near = NULL; - Elf64_Sword distance = 20; - Elf64_Sword d; - unsigned int relsym_secindex; - - if (is_valid_name(elf, relsym)) - return relsym; - - /* - * Strive to find a better symbol name, but the resulting name may not - * match the symbol referenced in the original code. - */ - relsym_secindex = get_secindex(elf, relsym); - for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { - if (get_secindex(elf, sym) != relsym_secindex) - continue; - if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) - continue; - if (!is_valid_name(elf, sym)) - continue; - if (sym->st_value == addr) - return sym; - /* Find a symbol nearby - addr are maybe negative */ - d = sym->st_value - addr; - if (d < 0) - d = addr - sym->st_value; - if (d < distance) { - distance = d; - near = sym; - } - } - /* We need a close match */ - if (distance < 20) - return near; - else - return NULL; -} - -/* - * Find symbols before or equal addr and after addr - in the section sec. - * If we find two symbols with equal offset prefer one with a valid name. - * The ELF format may have a better way to detect what type of symbol - * it is, but this works for now. - **/ -static Elf_Sym *find_fromsym(struct elf_info *elf, Elf_Addr addr, - unsigned int secndx) -{ - Elf_Sym *sym; - Elf_Sym *near = NULL; - Elf_Addr distance = ~0; + Elf_Addr distance; for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { if (get_secindex(elf, sym) != secndx) continue; if (!is_valid_name(elf, sym)) continue; - if (sym->st_value <= addr && addr - sym->st_value <= distance) { + + if (addr >= sym->st_value) distance = addr - sym->st_value; + else if (allow_negative) + distance = sym->st_value - addr; + else + continue; + + if (distance <= min_distance) { + min_distance = distance; near = sym; } + + if (min_distance == 0) + break; } return near; } +static Elf_Sym *find_fromsym(struct elf_info *elf, Elf_Addr addr, + unsigned int secndx) +{ + return find_nearest_sym(elf, addr, secndx, false, ~0); +} + +static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym) +{ + /* If the supplied symbol has a valid name, return it */ + if (is_valid_name(elf, sym)) + return sym; + + /* + * Strive to find a better symbol name, but the resulting name may not + * match the symbol referenced in the original code. + */ + return find_nearest_sym(elf, addr, get_secindex(elf, sym), true, 20); +} + static bool is_executable_section(struct elf_info *elf, unsigned int secndx) { if (secndx > elf->num_sections) From patchwork Thu Jun 1 12:09:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp272178vqr; Thu, 1 Jun 2023 05:12:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qPHqqVYFiW52EuZHjaTF8PCX7tFIFvC69p+O1pvp6fak7zKEGB5tn+c3eM47d4GzNTEuy X-Received: by 2002:a05:6358:52d3:b0:123:3812:7caa with SMTP id z19-20020a05635852d300b0012338127caamr8260386rwz.24.1685621576012; Thu, 01 Jun 2023 05:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621575; cv=none; d=google.com; s=arc-20160816; b=KdhB0ephDGKuo2STBYuKPA9pkryXz0LbfwW2Qgp+LQqUrXoIWuEWFm1co7fIex9Khf H4HBb/+WGNfT3ofW4VRg8nN94IxA4aA/DleavTlYOGv+Razw5QiQV09r8lGMhlsmz/T1 uu+F4ADV3/WSWx4dTVXPVJ8iuRLWhh+cP12aTABJ0eTqz4y/F9EnoE6v9vC9lUICYhVO T3K5e7pbLnwFvX5F6EhKAqTGZ3JcniCw0buvhFqQwIAaXRhbROHW2mjub3uoZY0XpsV8 Fl0T/WwGNn4eXSwAWHfrG66cB73I9hktmHY5VxAj1b9/HaP90bWbgc8pgYa3vlnmLVcF OV7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/VYR0D9TcG/zmvJ//RL49lW/CWro6MEYLa2V5UlnBpI=; b=jTGmzUe6geVCXj4GMNdqU0ePRNOrMLjLylm825p81QqL1ydrsPFacUM2gaJFSAoM/D HSsiEoPh8Eh9nIanIeGs6gozKuBpFxcmEjF1B6m4J+rGYoPICvJ57jE/7A9qCrfHz244 sGvvL4DA/GVukGxrFatVY8VsUPhYTfjqGM2DO7mNuaI5BqfWIZ9ZCdjZvGTWKDRdqf9S nd5H3JpCxJURdRlF1uWO1zmESYV3ux+FE27cLm2AIyYgQSpXqqTkoTb83fcY1KC2x5s4 YhUCOiv9RicwPgD2gfe0cy3mriPv/wAsFHeNihB+wpZvL8gmnW69hwYVN9c4xoiCC4gb xuUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ycj27leB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a17090abc8500b00256c97def8fsi1061748pjr.26.2023.06.01.05.12.43; Thu, 01 Jun 2023 05:12:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ycj27leB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233417AbjFAMLG (ORCPT + 99 others); Thu, 1 Jun 2023 08:11:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233263AbjFAMKp (ORCPT ); Thu, 1 Jun 2023 08:10:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A64FF197; Thu, 1 Jun 2023 05:10:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3E8A9643ED; Thu, 1 Jun 2023 12:10:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7128C4339C; Thu, 1 Jun 2023 12:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621431; bh=AZOSF7tPW49wr8oQ2E4HJeege/cPwYFZ1zz3AnaRfDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ycj27leB07TjGM8InrVlCfTP55GIaTEEQCCqpplZ9wFi+5TpOkJp11ZdLVyxCRsQo 2AzTbHoMHU4YukYqoQInAYk23Ii5jE613W5EsfzrrrnqqUxUSF1hUb61LiSoxi0SSg 0Di4jQW/p33oiQzdwJHd04iNqZ6pr4EWi+MGYE9WHrATJMzvP964qXqyL0Iw/8Xzux +KnzIgwRghfnQGKOVpXY29177mcq3tJ8ptW6p3lqDhMdJisEcRWl2sRw5bZJrFECi8 XqJHSYq1j9TuryuWKAzQYU4CWy5Z+mqQR4LP/zjkfCCWY551eBjG9lMC2Batq6cthK etcxud9XI2WAg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 5/7] modpost: detect section mismatch for R_ARM_THM_{MOVW_ABS_NC,MOVT_ABS} Date: Thu, 1 Jun 2023 21:09:59 +0900 Message-Id: <20230601121001.1071533-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502329592770251?= X-GMAIL-MSGID: =?utf-8?q?1767502329592770251?= When CONFIG_THUMB2_KERNEL is enabled, modpost fails to detect some types of section mismatches. [test code] #include int __initdata foo; int get_foo(void) { return foo; } It is apparently a bad reference, but modpost does not report anything. The test code above produces the following relocations. Relocation section '.rel.text' at offset 0x1e8 contains 2 entries: Offset Info Type Sym.Value Sym. Name 00000000 0000052f R_ARM_THM_MOVW_AB 00000000 .LANCHOR0 00000004 00000530 R_ARM_THM_MOVT_AB 00000000 .LANCHOR0 Currently, R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_ABS are just skipped. Add code to handle them. I checked arch/arm/kernel/module.c to learn how the offset is encoded in the instruction. One more thing to note for Thumb instructions - the st_value is an odd value, so you need to mask the bit 0 to get the offset. Otherwise, you will get an off-by-one error in the nearest symbol look-up. It is documented in "ELF for the ARM Architecture" [1]: * If the symbol addresses a Thumb instruction, its value is the address of the instruction with bit zero set (in a relocatable object, the section offset with bit zero set). * For the purposes of relocation the value used shall be the address of the instruction (st_value & ~1). [1]: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 32d56efe3f3b..528aa9175e84 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1082,7 +1082,8 @@ static Elf_Sym *find_nearest_sym(struct elf_info *elf, Elf_Addr addr, { Elf_Sym *sym; Elf_Sym *near = NULL; - Elf_Addr distance; + Elf_Addr sym_addr, distance; + bool is_arm = (elf->hdr->e_machine == EM_ARM); for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { if (get_secindex(elf, sym) != secndx) @@ -1090,10 +1091,19 @@ static Elf_Sym *find_nearest_sym(struct elf_info *elf, Elf_Addr addr, if (!is_valid_name(elf, sym)) continue; - if (addr >= sym->st_value) - distance = addr - sym->st_value; + sym_addr = sym->st_value; + + /* + * For ARM Thumb instruction, the bit 0 of st_value is set. + * Mask it to get the address. + */ + if (is_arm) + sym_addr &= ~1; + + if (addr >= sym_addr) + distance = addr - sym_addr; else if (allow_negative) - distance = sym->st_value - addr; + distance = sym_addr - addr; else continue; @@ -1266,7 +1276,7 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) unsigned int r_typ = ELF_R_TYPE(r->r_info); Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info); void *loc = reloc_location(elf, sechdr, r); - uint32_t inst; + uint32_t inst, upper, lower; int32_t offset; switch (r_typ) { @@ -1288,6 +1298,17 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) offset = sign_extend32((inst & 0x00ffffff) << 2, 25); r->r_addend = offset + sym->st_value + 8; break; + case R_ARM_THM_MOVW_ABS_NC: + case R_ARM_THM_MOVT_ABS: + upper = TO_NATIVE(*(uint16_t *)loc); + lower = TO_NATIVE(*((uint16_t *)loc + 1)); + offset = sign_extend32(((upper & 0x000f) << 12) | + ((upper & 0x0400) << 1) | + ((lower & 0x7000) >> 4) | + (lower & 0x00ff), + 15); + r->r_addend = offset + sym->st_value; + break; case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: case R_ARM_THM_JUMP19: From patchwork Thu Jun 1 12:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp276506vqr; Thu, 1 Jun 2023 05:18:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77i4StGrUGw0nlHMgcGCc+Lff1VRlfeFqcetdIwcFwlOr+MQmUGjF24HvZNs02Txp1uaUw X-Received: by 2002:a05:6a20:3c8f:b0:10c:a627:7ede with SMTP id b15-20020a056a203c8f00b0010ca6277edemr7326685pzj.58.1685621909784; Thu, 01 Jun 2023 05:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621909; cv=none; d=google.com; s=arc-20160816; b=MkI9xlO+Yt9tQ5rO5VYIlwWqdH1TCktqcUGJ43epho8a6pXO2Fk3bvbJWVOD7gjma+ PPP1hWsV+ZQRhAgP5XcOwA2A7A4WBRFhKIndcQfFV6bCN7t43dASgFTr5rGk9gPul7XC ESJKBYvhDUmjgTciQAzgLPNO0XuI9H2nqpP1GKIckf3tI/vXctzmjSrEBtpODX+c9Y2i OdVdDfp6+NEOAoRnMXXKbChySWmRwS3YcGN4e73IHiPNxKBPL3tBUEwJTv5j8z8ggaI5 gnapWnux/F02NlAO36WVrq9+Ec8UF14at29huia8jBY4PFoX+os46o4RRujQ5TKKIrKT g5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=enAYfB8hRKp+QdyEG8cVXCn12lOrxPNAZTERiZjHdh8=; b=qOwuV5jc9RAwhsmyOwHti3zqYxyV/YeZvE9FuNDDNBQLZoTtebu3LE2D6hYeMpRgMk K2WDMvX3VqPrIDNIIvKmtGGyv1/mi0AEtA7P8js49l1llHc2BuXMtxlwLtK0xEh33mN2 BiArpdvFqGGrgwyfII2gf0vYbvEimLjclPuAaRq/BxG5hEvrkBtoBeXOgJBzeEsjAa09 C7PfIifJf0FgSNnjD+CL1VL6im0TGtOFYKDHP7T//xwo44gJ18WWpBXu/iAKkbZA9WpO +XvQKHnnP3i7MXttTrBnM86G6uJVe7Ss7xRZcU7/Wu8jOlx2wVL4BTdhNk/WjJrW/3Gw v2Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q8NKzkee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i67-20020a636d46000000b0053f228ce43bsi2800651pgc.569.2023.06.01.05.18.16; Thu, 01 Jun 2023 05:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q8NKzkee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233356AbjFAMLT (ORCPT + 99 others); Thu, 1 Jun 2023 08:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbjFAMKr (ORCPT ); Thu, 1 Jun 2023 08:10:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DE301B8; Thu, 1 Jun 2023 05:10:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 125AF643FB; Thu, 1 Jun 2023 12:10:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DCA2C433A4; Thu, 1 Jun 2023 12:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621434; bh=eRGe47kX3cGM5w4r8Dems50P7VdGPg3OOcR4aC02b70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q8NKzkee9vISUaZPJodekn7NPcjTrI7T4bZTLzyDUPhJPCb/VPXyphc66ouv2Ccqv x9KwiLJsSMx0NJa1lQynQ7F5ckRdFc45kCK/rzI/I+uPAsZd5gLLgQ5LS61xSOJX5i 2KMSa3pPcU8TjwFyxQul8yT4Bw/bFQHpSTxPXCCpo86tFbTi4d0blMBWVRAfimemUY nXNHvmbcUuktNWNcjr1nvh1Ny9lYyI+eC03OxqMdkMJeJQfP9JMtWNs4bOY19xXJ/t L8IiodTAQOPzflB4mGhCKNEKBhdvpgN4Cywsl0flQMC6sYvGrCtnKJmIWEVoOw2noA RVFF8L9HCvfVw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , "David A. Long" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Russell King , Rusty Russell Subject: [PATCH 6/7] modpost: fix section_mismatch message for R_ARM_THM_{CALL,JUMP24,JUMP19} Date: Thu, 1 Jun 2023 21:10:00 +0900 Message-Id: <20230601121001.1071533-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767502679560900745?= X-GMAIL-MSGID: =?utf-8?q?1767502679560900745?= addend_arm_rel() processes R_ARM_THM_CALL, R_ARM_THM_JUMP24, R_ARM_THM_JUMP19 in a wrong way. Here, test code. [test code for R_ARM_THM_JUMP24]   .section .init.text,"ax"   bar:           bx      lr   .section .text,"ax"   .globl foo   foo:           b       bar [test code for R_ARM_THM_CALL]   .section .init.text,"ax"   bar:           bx      lr   .section .text,"ax"   .globl foo   foo:           push    {lr}           bl      bar           pop     {pc} If you compile it with CONFIG_THUMB2_KERNEL=y, modpost will show the symbol name, (unknown).   WARNING: modpost: vmlinux.o: section mismatch in reference: foo (section: .text) -> (unknown) (section: .init.text) (You need to use GNU linker instead of LLD to reproduce it.) Fix the code to make modpost show the correct symbol name. I checked arch/arm/kernel/module.c to learn the encoding of R_ARM_THM_CALL and R_ARM_THM_JUMP24. The module does not support R_ARM_THM_JUMP19, but I checked its encoding in ARM ARM. The '+4' is the compensation for pc-relative instruction. It is documented in "ELF for the Arm Architecture" [1].   "If the relocation is pc-relative then compensation for the PC bias   (the PC value is 8 bytes ahead of the executing instruction in Arm   state and 4 bytes in Thumb state) must be encoded in the relocation   by the object producer." [1]: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst Fixes: c9698e5cd6ad ("ARM: 7964/1: Detect section mismatches in thumb relocations") Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 53 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 528aa9175e84..55d142bb000b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1276,7 +1276,7 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) unsigned int r_typ = ELF_R_TYPE(r->r_info); Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info); void *loc = reloc_location(elf, sechdr, r); - uint32_t inst, upper, lower; + uint32_t inst, upper, lower, sign, j1, j2; int32_t offset; switch (r_typ) { @@ -1309,13 +1309,54 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 15); r->r_addend = offset + sym->st_value; break; + case R_ARM_THM_JUMP19: + /* + * Encoding T3: + * S = upper[10] + * imm6 = upper[5:0] + * J1 = lower[13] + * J2 = lower[11] + * imm11 = lower[10:0] + * imm32 = SignExtend(S:J2:J1:imm6:imm11:'0') + */ + upper = TO_NATIVE(*(uint16_t *)loc); + lower = TO_NATIVE(*((uint16_t *)loc + 1)); + + sign = (upper >> 10) & 1; + j1 = (lower >> 13) & 1; + j2 = (lower >> 11) & 1; + offset = sign_extend32((sign << 20) | (j2 << 19) | (j1 << 18) | + ((upper & 0x03f) << 12) | + ((lower & 0x07ff) << 1), + 20); + r->r_addend = offset + sym->st_value + 4; + break; case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: - case R_ARM_THM_JUMP19: - /* From ARM ABI: ((S + A) | T) - P */ - r->r_addend = (int)(long)(elf->hdr + - sechdr->sh_offset + - (r->r_offset - sechdr->sh_addr)); + /* + * Encoding T4: + * S = upper[10] + * imm10 = upper[9:0] + * J1 = lower[13] + * J2 = lower[11] + * imm11 = lower[10:0] + * I1 = NOT(J1 XOR S) + * I2 = NOT(J2 XOR S) + * imm32 = SignExtend(S:I1:I2:imm10:imm11:'0') + */ + upper = TO_NATIVE(*(uint16_t *)loc); + lower = TO_NATIVE(*((uint16_t *)loc + 1)); + + sign = (upper >> 10) & 1; + j1 = (lower >> 13) & 1; + j2 = (lower >> 11) & 1; + offset = sign_extend32((sign << 24) | + ((~(j1 ^ sign) & 1) << 23) | + ((~(j2 ^ sign) & 1) << 22) | + ((upper & 0x03ff) << 12) | + ((lower & 0x07ff) << 1), + 24); + r->r_addend = offset + sym->st_value + 4; break; default: return 1; From patchwork Thu Jun 1 12:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 101923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp281340vqr; Thu, 1 Jun 2023 05:24:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZsmJmSDxARGJGmO97fCrDJTB6bdCrqAcXk59IgSBWKOwLEh/ETX7nsHyloJqis1pxzn6M X-Received: by 2002:a17:903:1249:b0:1ae:50cc:455 with SMTP id u9-20020a170903124900b001ae50cc0455mr6629747plh.39.1685622290165; Thu, 01 Jun 2023 05:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685622290; cv=none; d=google.com; s=arc-20160816; b=xVpBgn9hs8XwznwE3TMkuwYMsppiMebqYyFCDsvFCw8YGNtlIjFdrbHMQ01j2AxJoE 45439IjFSj4BToP+4n6w866NeAh89Wdmmpn7wgaFmBM0/cF6BWygbB45S9AImfdbaeqm hU1I5Wh0cqP+SxxnR2zIxKor5k9fcbjaVF696WVAB8fl0/ZIfCKB4lz0qsHpCfB4FraM AqlTH8ayes8xTSBfKM1p1lLseASjQYjrMtLGb0T1WKizkvyJReNNJfl1KJO70ErdfvJR gOryohkrSp6iTADDQXZ8O1AWpZ1G3RVe0cxFcaAMu8EfMvYyIYV5C8OenSz9YWiYbcUy YVAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=il7LD4+xBXxX0/9FrnLKW/4wqN0RtYA+SprkFoGDivM=; b=CqijaOtG8WygBSXv9bR1kOhtmCcTzwZd5hs3RVCJSII/PjwgTladv1zYhLKwJzSUzJ dlsq3++MHLmVohtXdA91E+ICQN0soFlmcKwLfYib5bnz4iJjGW1a527/lioPIG+Q3r53 k3gZkhAwTec3vC3omhhdodHCE1N/rnI2y1BnJiRaoofo05Lvz+aNcjs4bpyeUQ2quxFY jIepGxSdeLsxpKFnjwh8K8+MVL0XKRGkzF4e7Ne1VWJCDqz0JTkrNDjzkCqtwZLDUF3Z 4QxL/5Y9CFwg7P5kHeJ0lUVFz8qsiXsPtslwKY5euTx+MLhexkS8gSH5OSexgefOrGDv VW/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SbJwf4gm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a170902ed1300b001b176ba9f0fsi2684166pld.273.2023.06.01.05.24.35; Thu, 01 Jun 2023 05:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SbJwf4gm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233306AbjFAMLf (ORCPT + 99 others); Thu, 1 Jun 2023 08:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbjFAMKt (ORCPT ); Thu, 1 Jun 2023 08:10:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A8DEE50; Thu, 1 Jun 2023 05:10:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 282C2641A9; Thu, 1 Jun 2023 12:10:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1781C433A0; Thu, 1 Jun 2023 12:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621436; bh=eMacqv00K8bJeMNK92sV1H4jFGoCI1e91wlVYvSCA6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SbJwf4gmpXiXBcoZnqcOtwMctCfgu2govvYcmytWmux8JMSq+1RHR2N8rpx5KZ6UF 61/5EPxVCs0pxoO+Cl7pnYYQdM5MLEND+6FtFQW07RgnQDL0wPPTjpytv2U9+o3u8w K4m/fy0y5W+ZffGmTazVcbnRCHk9hfC5uNOrOXXL/rGv+WrlFRPr8bYFK2Egu7vrnv rNqA92cuyyZ30DO+n2qxlQyMyzhdXr0tjpdf4DSQRxxMiU0SZnqzhYibEkuE+Lg+I1 rTiYQDHSJiFa+EobEK9N1ZeM2SvTguMeOX45UOjKaIc11CEEFiA9L7TA7Bp8rBJed+ Inyd6OuukOmzw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 7/7] modpost: detect section mismatch for R_ARM_REL32 Date: Thu, 1 Jun 2023 21:10:01 +0900 Message-Id: <20230601121001.1071533-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767503078503003867?= X-GMAIL-MSGID: =?utf-8?q?1767503078503003867?= For ARM, modpost fails to detect some types of section mismatches. [test code] .section .init.data,"aw" bar: .long 0 .section .data,"aw" .globl foo foo: .long bar - . It is apparently a bad reference, but modpost does not report anything. The test code above produces the following relocations. Relocation section '.rel.data' at offset 0xe8 contains 1 entry: Offset Info Type Sym.Value Sym. Name 00000000 00000403 R_ARM_REL32 00000000 .init.data Currently, R_ARM_REL32 is just skipped. Handle it like R_ARM_ABS32. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 55d142bb000b..9f0c87064ca5 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1281,6 +1281,7 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) switch (r_typ) { case R_ARM_ABS32: + case R_ARM_REL32: inst = TO_NATIVE(*(uint32_t *)loc); r->r_addend = inst + sym->st_value; break;