Skip to content

Commit a4d26f1

Browse files
paul-walmsley-sifivemasahir0y
authored andcommitted
modpost: skip ELF local symbols during section mismatch check
During development of a serial console driver with a gcc 8.2.0 toolchain for RISC-V, the following modpost warning appeared: ---- WARNING: vmlinux.o(.data+0x19b10): Section mismatch in reference from the variable .LANCHOR1 to the function .init.text:sifive_serial_console_setup() The variable .LANCHOR1 references the function __init sifive_serial_console_setup() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console ---- ".LANCHOR1" is an ELF local symbol, automatically created by gcc's section anchor generation code: https://gcc.gnu.org/onlinedocs/gccint/Anchored-Addresses.html https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/varasm.c;h=cd9591a45617464946dcf9a126dde277d9de9804;hb=9fb89fa845c1b2e0a18d85ada0b077c84508ab78#l7473 This was verified by compiling the kernel with -fno-section-anchors and observing that the ".LANCHOR1" ELF local symbol disappeared, and modpost no longer warned about the section mismatch. The serial driver code idiom triggering the warning is standard Linux serial driver practice that has a specific whitelist inclusion in modpost.c. I'm neither a modpost nor an ELF expert, but naively, it doesn't seem useful for modpost to report section mismatch warnings caused by ELF local symbols by default. Local symbols have compiler-generated names, and thus bypass modpost's whitelisting algorithm, which relies on the presence of a non-autogenerated symbol name. This increases the likelihood that false positive warnings will be generated (as in the above case). Thus, disable section mismatch reporting on ELF local symbols. The rationale here is similar to that of commit 2e3a10a ("ARM: avoid ARM binutils leaking ELF local symbols") and of similar code already present in modpost.c: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/mod/modpost.c?h=v4.19-rc4&id=7876320f88802b22d4e2daf7eb027dd14175a0f8#n1256 This third version of the patch implements a suggestion from Masahiro Yamada <[email protected]> to restructure the code as an additional pattern matching step inside secref_whitelist(), and further improves the patch description. Signed-off-by: Paul Walmsley <[email protected]> Signed-off-by: Paul Walmsley <[email protected]> Acked-by: Sam Ravnborg <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 0126be3 commit a4d26f1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

scripts/mod/modpost.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,14 @@ static const struct sectioncheck *section_mismatch(
11631163
* fromsec = text section
11641164
* refsymname = *.constprop.*
11651165
*
1166+
* Pattern 6:
1167+
* Hide section mismatch warnings for ELF local symbols. The goal
1168+
* is to eliminate false positive modpost warnings caused by
1169+
* compiler-generated ELF local symbol names such as ".LANCHOR1".
1170+
* Autogenerated symbol names bypass modpost's "Pattern 2"
1171+
* whitelisting, which relies on pattern-matching against symbol
1172+
* names to work. (One situation where gcc can autogenerate ELF
1173+
* local symbols is when "-fsection-anchors" is used.)
11661174
**/
11671175
static int secref_whitelist(const struct sectioncheck *mismatch,
11681176
const char *fromsec, const char *fromsym,
@@ -1201,6 +1209,10 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
12011209
match(fromsym, optim_symbols))
12021210
return 0;
12031211

1212+
/* Check for pattern 6 */
1213+
if (strstarts(fromsym, ".L"))
1214+
return 0;
1215+
12041216
return 1;
12051217
}
12061218

0 commit comments

Comments
 (0)