Skip to content

Commit 6d62b1c

Browse files
committed
modpost: check static EXPORT_SYMBOL* by modpost again
Commit 31cb50b ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost") moved the static EXPORT_SYMBOL* check from the mostpost to a shell script because I thought it must be checked per compilation unit to avoid false negatives. I came up with an idea to do this in modpost, against combined ELF files. The relocation entries in ELF will find the correct exported symbol even if there exist symbols with the same name in different compilation units. Again, the same sample code. Makefile: obj-y += foo1.o foo2.o foo1.c: #include <linux/export.h> static void foo(void) {} EXPORT_SYMBOL(foo); foo2.c: void foo(void) {} Then, modpost can catch it correctly. MODPOST Module.symvers ERROR: modpost: vmlinux: local symbol 'foo' was exported Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent 7d59313 commit 6d62b1c

3 files changed

Lines changed: 7 additions & 74 deletions

File tree

scripts/Makefile.build

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,13 @@ cmd_gen_ksymdeps = \
222222
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
223223
endif
224224

225-
cmd_check_local_export = $(srctree)/scripts/check-local-export $@
226-
227225
ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
228226
cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi)))
229227
endif
230228

231229
define rule_cc_o_c
232230
$(call cmd_and_fixdep,cc_o_c)
233231
$(call cmd,gen_ksymdeps)
234-
$(call cmd,check_local_export)
235232
$(call cmd,checksrc)
236233
$(call cmd,checkdoc)
237234
$(call cmd,gen_objtooldep)
@@ -243,7 +240,6 @@ endef
243240
define rule_as_o_S
244241
$(call cmd_and_fixdep,as_o_S)
245242
$(call cmd,gen_ksymdeps)
246-
$(call cmd,check_local_export)
247243
$(call cmd,gen_objtooldep)
248244
$(call cmd,gen_symversions_S)
249245
$(call cmd,warn_shared_object)

scripts/check-local-export

Lines changed: 0 additions & 70 deletions
This file was deleted.

scripts/mod/modpost.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,13 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf,
12101210
return;
12111211
}
12121212

1213+
if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
1214+
ELF_ST_BIND(sym->st_info) != STB_WEAK) {
1215+
error("%s: local symbol '%s' was exported\n", mod->name,
1216+
label_name + strlen(prefix));
1217+
return;
1218+
}
1219+
12131220
name = sym_name(elf, sym);
12141221
if (strcmp(label_name + strlen(prefix), name)) {
12151222
error("%s: .export_symbol section references '%s', but it does not seem to be an export symbol\n",

0 commit comments

Comments
 (0)