Skip to content

Commit 15bfc23

Browse files
evdenismasahir0y
authored andcommitted
modpost: check for static EXPORT_SYMBOL* functions
This patch adds a check to warn about static EXPORT_SYMBOL* functions during the modpost. In most of the cases, a static symbol marked for exporting is an odd combination that should be fixed either by deleting the exporting mark or by removing the static attribute and adding the appropriate declaration to headers. This check could help to detect the following problems: 1. 550113d ("i2c: add newly exported functions to the header, too") 2. 54638c6 ("net: phy: make exported variables non-static") 3. 98ef204 ("mm: remove the exporting of totalram_pages") 4. 73df167 ("s390/zcrypt: remove the exporting of ap_query_configuration") 5. a57caf8 ("sunrpc/cache: remove the exporting of cache_seq_next") 6. e4e4730 ("crypto: skcipher - remove the exporting of skcipher_walk_next") 7. 14b4c48 ("gve: Remove the exporting of gve_probe") 8. 9b79ee9 ("scsi: libsas: remove the exporting of sas_wait_eh") 9. ... The build time impact is very limited and is almost at the unnoticeable level (< 1 sec). Acked-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Denis Efremov <efremov@linux.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent d45331b commit 15bfc23

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/mod/modpost.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct symbol {
169169
unsigned int kernel:1; /* 1 if symbol is from kernel
170170
* (only for external modules) **/
171171
unsigned int preloaded:1; /* 1 if symbol from Module.symvers, or crc */
172+
unsigned int is_static:1; /* 1 if symbol is not global */
172173
enum export export; /* Type of export */
173174
char name[0];
174175
};
@@ -201,6 +202,7 @@ static struct symbol *alloc_symbol(const char *name, unsigned int weak,
201202
strcpy(s->name, name);
202203
s->weak = weak;
203204
s->next = next;
205+
s->is_static = 1;
204206
return s;
205207
}
206208

@@ -1980,6 +1982,21 @@ static void read_symbols(const char *modname)
19801982
handle_modversions(mod, &info, sym, symname);
19811983
handle_moddevtable(mod, &info, sym, symname);
19821984
}
1985+
1986+
// check for static EXPORT_SYMBOL_* functions && global vars
1987+
for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
1988+
unsigned char bind = ELF_ST_BIND(sym->st_info);
1989+
1990+
if (bind == STB_GLOBAL || bind == STB_WEAK) {
1991+
struct symbol *s =
1992+
find_symbol(remove_dot(info.strtab +
1993+
sym->st_name));
1994+
1995+
if (s)
1996+
s->is_static = 0;
1997+
}
1998+
}
1999+
19832000
if (!is_vmlinux(modname) || vmlinux_section_warnings)
19842001
check_sec_ref(mod, modname, &info);
19852002

@@ -2369,6 +2386,7 @@ static void read_dump(const char *fname, unsigned int kernel)
23692386
s = sym_add_exported(symname, mod, export_no(export));
23702387
s->kernel = kernel;
23712388
s->preloaded = 1;
2389+
s->is_static = 0;
23722390
sym_update_crc(symname, mod, crc, export_no(export));
23732391
}
23742392
release_file(file, size);
@@ -2425,6 +2443,7 @@ int main(int argc, char **argv)
24252443
char *dump_write = NULL, *files_source = NULL;
24262444
int opt;
24272445
int err;
2446+
int n;
24282447
struct ext_sym_list *extsym_iter;
24292448
struct ext_sym_list *extsym_start = NULL;
24302449

@@ -2520,6 +2539,19 @@ int main(int argc, char **argv)
25202539
if (sec_mismatch_count && sec_mismatch_fatal)
25212540
fatal("modpost: Section mismatches detected.\n"
25222541
"Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2542+
for (n = 0; n < SYMBOL_HASH_SIZE; n++) {
2543+
struct symbol *s = symbolhash[n];
2544+
2545+
while (s) {
2546+
if (s->is_static)
2547+
warn("\"%s\" [%s] is a static %s\n",
2548+
s->name, s->module->name,
2549+
export_str(s->export));
2550+
2551+
s = s->next;
2552+
}
2553+
}
2554+
25232555
free(buf.p);
25242556

25252557
return err;

0 commit comments

Comments
 (0)