From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F808280CC1; Thu, 16 Jul 2026 05:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784179923; cv=none; b=gAFYAL4ZLyNdEv7JEPijbIFwmPNQ/31wPpTsNVJ4gbV+YYrt7iFxh+aJULap7mpL+AMwJcV+uIW6YVbDZLQeEOrkLd5ufO8u/O7TFWdRoCAmCWC6RQNBlFSY7/+LnYwAbMiLb52FQT2asoRRXgk/y29oD87Qoemx7wgbMmvwApQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784179923; c=relaxed/simple; bh=K0/fBpvEVREYxAiLlkvLaBfaiGgV73UlQbngXGM401c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o1PLUxwjTqdg5a93V4D9f5BrQGrA/r2GXgv11bdlCcqmt4PWkbMLtq6c4VwTlPW1xrXpDFr/N9BUtXxu/Fl4mY/iohw6+4FcUIAcRH0RajWxirQA50Zwq/z+rFp+eBTHwKAxqDxzFwfPsnJY0Q9JsLFAOMSiKaorWFIYweXsNJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pTHEJbrT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pTHEJbrT" Received: by smtp.kernel.org (Postfix) with ESMTPS id EB017C2BCC9; Thu, 16 Jul 2026 05:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784179923; bh=K0/fBpvEVREYxAiLlkvLaBfaiGgV73UlQbngXGM401c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pTHEJbrTAB4h/ToeJQ/nV7mPrkm7baTfm9LUP/JbnPIBGjH/hQHzwTXcyJ+k25TGX +sq1EtecKRe2CwDhUZJa2u16qG1vY1FZUY+3BbTcwhXXILTDPo+jNaEed9cpR3vfG5 iB1yDsRF91MpqSPCs1WFNFAhRWK8vTnP7FdnXl6ddigq+X2ni31a3F8Hx+3MVRNPke y/wY6S1kuyjYRQJcOW4dXZNgIIPdEmYWmo6v18EN0zujj5CfHTcLxUfDGE0JDEzhOr SuUin9uUQYwHAbN+yzMUvrmADQ0pPu/zdHpzjgbnkKilVAy3TlGXRxzVkp6Mu2NVCp 5X5H4OiarQLNQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD830C44511; Thu, 16 Jul 2026 05:32:02 +0000 (UTC) From: Jia Wang via B4 Relay Date: Thu, 16 Jul 2026 13:31:49 +0800 Subject: [PATCH 1/2] modpost: ignore generated GCOV and RISC-V local relocs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-modpost-v1-1-8eab36cc7310@ultrarisc.com> References: <20260716-modpost-v1-0-8eab36cc7310@ultrarisc.com> In-Reply-To: <20260716-modpost-v1-0-8eab36cc7310@ultrarisc.com> To: Nathan Chancellor , Nicolas Schier , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Jia Wang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784179921; l=6237; i=wangjia@ultrarisc.com; s=20260515; h=from:subject:message-id; bh=Qmcrh0ELG719bfZpzSpb/gjTYnW7s0pXlwROWQGT5ys=; b=MjwTgun4996uhG+72Cge2Wt8gh9lXuzarMQqAKiDdWhEPqtokFnkCGZq1qwlRPlu0T5iJKfuJ TLL9keOWHMSDHujPLTMdvuryg9oHoTjpjuBC8JMCwKOGa5WVOaIjVXT X-Developer-Key: i=wangjia@ultrarisc.com; a=ed25519; pk=wGVm18siRScehKOkOz0WKxgxDy7IezHEszhnN4/TUCY= X-Endpoint-Received: by B4 Relay for wangjia@ultrarisc.com/20260515 with auth_id=779 X-Original-From: Jia Wang Reply-To: wangjia@ultrarisc.com From: Jia Wang GCOV_PROFILE_ALL can make GCC emit constructor and metadata symbols that reference init or exit sections. modpost may then report section mismatches through generated symbols such as _sub_I_* and __gcov_.*, even though those references do not describe a normal section lifetime dependency in kernel code. RISC-V also uses local branch and PC-relative relocation pairs that can resolve through compiler local or mapping symbols near init or exit code. Treating those local relocations as ordinary lifetime references creates a large number of bogus section mismatch warnings. Teach modpost to keep the raw target symbol for generated-symbol checks and pass the relocation type into the mismatch filter. Ignore GCOV constructor and metadata symbols, compiler mapping symbols, and RISC-V local branch or PC-relative relocations when they target init or exit sections. This was seen with an rv32 randconfig using KCONFIG_SEED=3D277518 with CONFIG_GCOV_PROFILE_ALL=3Dy, CONFIG_KCOV_INSTRUMENT_ALL=3Dy and CONFIG_DEBUG_INFO_BTF=3Dy, where modpost emitted a large number of bogus .text to .init.text section mismatch warnings through generated GCOV and local RISC-V symbols. This keeps named symbol section mismatch diagnostics while avoiding the warning flood from compiler-generated references. Signed-off-by: Jia Wang --- scripts/mod/modpost.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index a7b72a81d248..6869822446bd 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -951,8 +951,50 @@ static const struct sectioncheck *section_mismatch( * refsymname =3D *.constprop.* * **/ +#ifndef R_RISCV_BRANCH +#define R_RISCV_BRANCH 16 +#endif + +#ifndef R_RISCV_PCREL_HI20 +#define R_RISCV_PCREL_HI20 23 +#endif + +#ifndef R_RISCV_PCREL_LO12_I +#define R_RISCV_PCREL_LO12_I 24 +#endif + +#ifndef R_RISCV_PCREL_LO12_S +#define R_RISCV_PCREL_LO12_S 25 +#endif + +#ifndef R_RISCV_RVC_BRANCH +#define R_RISCV_RVC_BRANCH 44 +#endif + +#ifndef R_RISCV_RVC_JUMP +#define R_RISCV_RVC_JUMP 45 +#endif + +static bool is_gcov_generated_symbol(const char *sym) +{ + return strstarts(sym, "_sub_I_") || + strstarts(sym, "__gcov_."); +} + +static bool is_riscv_local_reloc(unsigned int r_type) +{ + return r_type =3D=3D R_RISCV_BRANCH || + r_type =3D=3D R_RISCV_RVC_BRANCH || + r_type =3D=3D R_RISCV_RVC_JUMP || + r_type =3D=3D R_RISCV_PCREL_HI20 || + r_type =3D=3D R_RISCV_PCREL_LO12_I || + r_type =3D=3D R_RISCV_PCREL_LO12_S; +} + static int secref_whitelist(const char *fromsec, const char *fromsym, - const char *tosec, const char *tosym) + const char *tosec, const char *tosym, + const char *raw_tosym, unsigned int r_type, + unsigned int e_machine) { /* Check for pattern 1 */ if (match(tosec, PATTERNS(ALL_INIT_DATA_SECTIONS)) && @@ -981,6 +1023,21 @@ static int secref_whitelist(const char *fromsec, cons= t char *fromsym, if (match(tosym, PATTERNS("__init_begin", "_sinittext", "_einittext"))) return 0; =20 + /* + * Compiler-generated local labels and GCOV constructors can produce + * relocations that are later reported as section mismatches against + * nearby init/exit symbols. Do not use those generated symbols as + * evidence of a real section lifetime dependency. + */ + if (match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) && + (is_mapping_symbol(raw_tosym) || is_gcov_generated_symbol(fromsym))) + return 0; + + if (e_machine =3D=3D EM_RISCV && + is_riscv_local_reloc(r_type) && + match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS))) + return 0; + /* Check for pattern 5 */ if (match(fromsec, PATTERNS(ALL_TEXT_SECTIONS)) && match(tosec, PATTERNS(ALL_INIT_SECTIONS)) && @@ -1025,21 +1082,25 @@ static void default_mismatch_handler(const char *mo= dname, struct elf_info *elf, const struct sectioncheck* const mismatch, Elf_Sym *tsym, unsigned int fsecndx, const char *fromsec, Elf_Addr faddr, - const char *tosec, Elf_Addr taddr) + const char *tosec, Elf_Addr taddr, + unsigned int r_type) { Elf_Sym *from; const char *tosym; const char *fromsym; char taddr_str[16]; + const char *raw_tosym; =20 from =3D find_fromsym(elf, faddr, fsecndx); fromsym =3D sym_name(elf, from); =20 + raw_tosym =3D sym_name(elf, tsym); tsym =3D find_tosym(elf, taddr, tsym); tosym =3D sym_name(elf, tsym); =20 /* check whitelist - we may ignore it */ - if (!secref_whitelist(fromsec, fromsym, tosec, tosym)) + if (!secref_whitelist(fromsec, fromsym, tosec, tosym, raw_tosym, + r_type, elf->hdr->e_machine)) return; =20 sec_mismatch_count++; @@ -1152,7 +1213,8 @@ static void check_export_symbol(struct module *mod, s= truct elf_info *elf, static void check_section_mismatch(struct module *mod, struct elf_info *el= f, Elf_Sym *sym, unsigned int fsecndx, const char *fromsec, - Elf_Addr faddr, Elf_Addr taddr) + Elf_Addr faddr, Elf_Addr taddr, + unsigned int r_type) { const char *tosec =3D sec_name(elf, get_secindex(elf, sym)); const struct sectioncheck *mismatch; @@ -1168,7 +1230,7 @@ static void check_section_mismatch(struct module *mod= , struct elf_info *elf, =20 default_mismatch_handler(mod->name, elf, mismatch, sym, fsecndx, fromsec, faddr, - tosec, taddr); + tosec, taddr, r_type); } =20 static Elf_Addr addend_386_rel(uint32_t *location, unsigned int r_type) @@ -1382,7 +1444,8 @@ static void section_rela(struct module *mod, struct e= lf_info *elf, } =20 check_section_mismatch(mod, elf, tsym, - fsecndx, fromsec, r_offset, taddr); + fsecndx, fromsec, r_offset, taddr, + r_type); } } =20 @@ -1419,7 +1482,8 @@ static void section_rel(struct module *mod, struct el= f_info *elf, } =20 check_section_mismatch(mod, elf, tsym, - fsecndx, fromsec, r_offset, taddr); + fsecndx, fromsec, r_offset, taddr, + r_type); } } =20 --=20 2.34.1 From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F732278156; Thu, 16 Jul 2026 05:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784179923; cv=none; b=E2GYsTB/GXaBo9p4m7RqlFQEGjRgf9AQiSyySIhEPX1z3wtjaUeB/+LNyZMT0DcG+Wt0VfthGGTFGvFUKdkMpTlCFbscu3DTRTo+sG+j68M23RSsA6DdXrph8LSzBvAJvSVlTVdxvnjhWf2/4bcxnunGzk+YtUMOz7Pa39i2hoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784179923; c=relaxed/simple; bh=3Q0vryF+5lbA0CL/FU1QlEBnnVpEBBCyvs3z8P+VlO0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LMCvzlLGifsW47bHCz0hNc3707AErnhZnCYKUZY2Fhiuqgmg1d2JaCEmPHtxqjRwELxxPbXoi67d30wIfk0QppSqzY0rl4q8oEMZ+oeyU8DObgtZwtHdYl/Kipf6xISY7ZsaqMJehTtoL74z9/Qk1TC+vcb39jZ4RrVSUFQm25U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WyXGZoHE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WyXGZoHE" Received: by smtp.kernel.org (Postfix) with ESMTPS id 06939C2BCF5; Thu, 16 Jul 2026 05:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784179923; bh=3Q0vryF+5lbA0CL/FU1QlEBnnVpEBBCyvs3z8P+VlO0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WyXGZoHEKYeMDS/XHao1XBXyCkblFtOuLwg2OROf2gJkvAZxl4n7Q8hiDaY6Srd2z sl4DN4Ytoavfqy/K7zXBmYrpM4Nbqy+Dt1kEEduCjUZ63gza3NY8FitUMMuVqCo9+b EpAmYC3ZZhiq42qjvvgL6dmW9vJ1V+W1mE6dN2kqVE7MIkFriDBvifgi2Y0cLDI2XI fIDjgg+3ncWHpQU3qqQiz5+7QRdvKIj2nZu0SJGrwZeT4KyiTDVYdU7U2RKqagWdGq Z4zxX5XNgmDMMj7hIH8gTVOCBd1pRa3O8+XzBJCjzfBzUiKhhbOcmsREgqZKDr6RIz PTTYUOMiQd9PA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC5E2C44501; Thu, 16 Jul 2026 05:32:02 +0000 (UTC) From: Jia Wang via B4 Relay Date: Thu, 16 Jul 2026 13:31:50 +0800 Subject: [PATCH 2/2] modpost: handle RISC-V relative extable relocations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-modpost-v1-2-8eab36cc7310@ultrarisc.com> References: <20260716-modpost-v1-0-8eab36cc7310@ultrarisc.com> In-Reply-To: <20260716-modpost-v1-0-8eab36cc7310@ultrarisc.com> To: Nathan Chancellor , Nicolas Schier , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Jia Wang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784179921; l=4201; i=wangjia@ultrarisc.com; s=20260515; h=from:subject:message-id; bh=Q9Kl2WTnEgc/AGpok4mr/A3MQcvAYwsHz1JLGJEq9t8=; b=4mewT8X7Ur3HG+8XYP1s+yvdBIpVetFnR+mZb9M/hui6GV4SQChyjtuRkydw2zNCzqkB/hNOn 7PnbxmgAboSAD7tJc/c2fQpxNPkIes31RxXlCDzvuxg5FJuYB4X18IN X-Developer-Key: i=wangjia@ultrarisc.com; a=ed25519; pk=wGVm18siRScehKOkOz0WKxgxDy7IezHEszhnN4/TUCY= X-Endpoint-Received: by B4 Relay for wangjia@ultrarisc.com/20260515 with auth_id=779 X-Original-From: Jia Wang Reply-To: wangjia@ultrarisc.com From: Jia Wang RISC-V relative exception tables emit an R_RISCV_ADD32 and R_RISCV_SUB32 relocation pair for each field. modpost already ignores the SUB32 half, but still checks the ADD32 symbol section directly. After a relocatable link, that ADD32 symbol can name an unrelated local debug symbol. This makes modpost report that __ex_table references non-executable .debug* sections even though the original exception table entry points at text. Recognize the RISC-V ADD32/SUB32 pair for __ex_table. Ignore ADD32 entries that have been resolved to debug symbols, and otherwise validate the resolved relative target address against executable sections. This was seen with an rv32 randconfig using KCONFIG_SEED=3D4721 with CONFIG_MMU=3Dy and CONFIG_DEBUG_INFO=3Dy. The resulting vmlinux.o contains R_RISCV_ADD32/R_RISCV_SUB32 relocation pairs in __ex_table, and the fixed modpost run completes without the false .debug* section mismatch diagnostics. Signed-off-by: Jia Wang --- scripts/mod/modpost.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 79 insertions(+) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6869822446bd..04a12eebb381 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1356,6 +1356,10 @@ static Elf_Addr addend_mips_rel(uint32_t *location, = unsigned int r_type) #define EM_RISCV 243 #endif =20 +#ifndef R_RISCV_ADD32 +#define R_RISCV_ADD32 35 +#endif + #ifndef R_RISCV_SUB32 #define R_RISCV_SUB32 39 #endif @@ -1406,6 +1410,76 @@ static void get_rel_type_and_sym(struct elf_info *el= f, uint64_t r_info, *r_sym =3D ELF_R_SYM(r_info); } =20 +static bool section_contains_addr(struct elf_info *elf, unsigned int secnd= x, + Elf_Addr addr) +{ + Elf_Shdr *sechdr; + + if (secndx >=3D elf->num_sections) + return false; + + sechdr =3D &elf->sechdrs[secndx]; + + return addr >=3D sechdr->sh_addr && + addr - sechdr->sh_addr < sechdr->sh_size; +} + +static bool addr_is_executable(struct elf_info *elf, Elf_Addr addr) +{ + unsigned int i; + + for (i =3D 1; i < elf->num_sections; i++) { + if ((elf->sechdrs[i].sh_flags & SHF_EXECINSTR) && + section_contains_addr(elf, i, addr)) + return true; + } + + return false; +} + +static bool is_debug_section(const char *secname) +{ + return match(secname, PATTERNS(".debug*", ".zdebug*")); +} + +static bool riscv_extable_rela_valid(struct elf_info *elf, + const Elf_Rela *start, + const Elf_Rela *stop, + const Elf_Rela *rela, + Elf_Addr r_offset, + Elf_Sym *add_sym) +{ + Elf_Addr add_addr, sub_addr, target_addr; + unsigned int r_type, r_sym; + const Elf_Rela *pair; + Elf_Sym *sub_sym; + + /* + * RISC-V relative exception tables emit an ADD32/SUB32 pair for each + * field. After ld -r, the ADD32 symbol may name an unrelated local + * debug symbol. Otherwise, validate the resolved relative target. + */ + for (pair =3D start; pair < stop; pair++) { + get_rel_type_and_sym(elf, pair->r_info, &r_type, &r_sym); + if (TO_NATIVE(pair->r_offset) =3D=3D r_offset && + r_type =3D=3D R_RISCV_SUB32) + break; + } + + if (pair =3D=3D stop) + return false; + + sub_sym =3D elf->symtab_start + r_sym; + if (is_debug_section(sec_name(elf, get_secindex(elf, add_sym)))) + return true; + + add_addr =3D add_sym->st_value + TO_NATIVE(rela->r_addend); + sub_addr =3D sub_sym->st_value + TO_NATIVE(pair->r_addend); + target_addr =3D r_offset + add_addr - sub_addr; + + return addr_is_executable(elf, target_addr); +} + static void section_rela(struct module *mod, struct elf_info *elf, unsigned int fsecndx, const char *fromsec, const Elf_Rela *start, const Elf_Rela *stop) @@ -1428,6 +1502,11 @@ static void section_rela(struct module *mod, struct = elf_info *elf, if (!strcmp("__ex_table", fromsec) && r_type =3D=3D R_RISCV_SUB32) continue; + if (!strcmp("__ex_table", fromsec) && + r_type =3D=3D R_RISCV_ADD32 && + riscv_extable_rela_valid(elf, start, stop, rela, + r_offset, tsym)) + continue; break; case EM_LOONGARCH: switch (r_type) { --=20 2.34.1