@@ -164,6 +164,7 @@ struct symbol {
164164 struct module * module ;
165165 unsigned int crc ;
166166 int crc_valid ;
167+ const char * namespace ;
167168 unsigned int weak :1 ;
168169 unsigned int vmlinux :1 ; /* 1 if symbol is defined in vmlinux */
169170 unsigned int kernel :1 ; /* 1 if symbol is from kernel
@@ -233,6 +234,37 @@ static struct symbol *find_symbol(const char *name)
233234 return NULL ;
234235}
235236
237+ static bool contains_namespace (struct namespace_list * list ,
238+ const char * namespace )
239+ {
240+ struct namespace_list * ns_entry ;
241+
242+ for (ns_entry = list ; ns_entry != NULL ; ns_entry = ns_entry -> next )
243+ if (strcmp (ns_entry -> namespace , namespace ) == 0 )
244+ return true;
245+
246+ return false;
247+ }
248+
249+ static void add_namespace (struct namespace_list * * list , const char * namespace )
250+ {
251+ struct namespace_list * ns_entry ;
252+
253+ if (!contains_namespace (* list , namespace )) {
254+ ns_entry = NOFAIL (malloc (sizeof (struct namespace_list ) +
255+ strlen (namespace ) + 1 ));
256+ strcpy (ns_entry -> namespace , namespace );
257+ ns_entry -> next = * list ;
258+ * list = ns_entry ;
259+ }
260+ }
261+
262+ static bool module_imports_namespace (struct module * module ,
263+ const char * namespace )
264+ {
265+ return contains_namespace (module -> imported_namespaces , namespace );
266+ }
267+
236268static const struct {
237269 const char * str ;
238270 enum export export ;
@@ -312,23 +344,39 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
312344 return export_unknown ;
313345}
314346
347+ static const char * sym_extract_namespace (const char * * symname )
348+ {
349+ size_t n ;
350+ char * dupsymname ;
351+
352+ n = strcspn (* symname , "." );
353+ if (n < strlen (* symname ) - 1 ) {
354+ dupsymname = NOFAIL (strdup (* symname ));
355+ dupsymname [n ] = '\0' ;
356+ * symname = dupsymname ;
357+ return dupsymname + n + 1 ;
358+ }
359+
360+ return NULL ;
361+ }
362+
315363/**
316364 * Add an exported symbol - it may have already been added without a
317365 * CRC, in this case just update the CRC
318366 **/
319- static struct symbol * sym_add_exported (const char * name , struct module * mod ,
320- enum export export )
367+ static struct symbol * sym_add_exported (const char * name , const char * namespace ,
368+ struct module * mod , enum export export )
321369{
322370 struct symbol * s = find_symbol (name );
323371
324372 if (!s ) {
325373 s = new_symbol (name , mod , export );
374+ s -> namespace = namespace ;
326375 } else {
327376 if (!s -> preloaded ) {
328- warn ("%s: '%s' exported twice. Previous export "
329- "was in %s%s\n" , mod -> name , name ,
330- s -> module -> name ,
331- is_vmlinux (s -> module -> name ) ?"" :".ko" );
377+ warn ("%s: '%s' exported twice. Previous export was in %s%s\n" ,
378+ mod -> name , name , s -> module -> name ,
379+ is_vmlinux (s -> module -> name ) ? "" : ".ko" );
332380 } else {
333381 /* In case Module.symvers was out of date */
334382 s -> module = mod ;
@@ -620,6 +668,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
620668 unsigned int crc ;
621669 enum export export ;
622670 bool is_crc = false;
671+ const char * name , * namespace ;
623672
624673 if ((!is_vmlinux (mod -> name ) || mod -> is_dot_o ) &&
625674 strstarts (symname , "__ksymtab" ))
@@ -691,8 +740,9 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
691740 default :
692741 /* All exported symbols */
693742 if (strstarts (symname , "__ksymtab_" )) {
694- sym_add_exported (symname + strlen ("__ksymtab_" ), mod ,
695- export );
743+ name = symname + strlen ("__ksymtab_" );
744+ namespace = sym_extract_namespace (& name );
745+ sym_add_exported (name , namespace , mod , export );
696746 }
697747 if (strcmp (symname , "init_module" ) == 0 )
698748 mod -> has_init = 1 ;
@@ -1943,6 +1993,7 @@ static void read_symbols(const char *modname)
19431993 const char * symname ;
19441994 char * version ;
19451995 char * license ;
1996+ char * namespace ;
19461997 struct module * mod ;
19471998 struct elf_info info = { };
19481999 Elf_Sym * sym ;
@@ -1974,6 +2025,12 @@ static void read_symbols(const char *modname)
19742025 license = get_next_modinfo (& info , "license" , license );
19752026 }
19762027
2028+ namespace = get_modinfo (& info , "import_ns" );
2029+ while (namespace ) {
2030+ add_namespace (& mod -> imported_namespaces , namespace );
2031+ namespace = get_next_modinfo (& info , "import_ns" , namespace );
2032+ }
2033+
19772034 for (sym = info .symtab_start ; sym < info .symtab_stop ; sym ++ ) {
19782035 symname = remove_dot (info .strtab + sym -> st_name );
19792036
@@ -2118,6 +2175,13 @@ static int check_exports(struct module *mod)
21182175 basename ++ ;
21192176 else
21202177 basename = mod -> name ;
2178+
2179+ if (exp -> namespace &&
2180+ !module_imports_namespace (mod , exp -> namespace )) {
2181+ warn ("module %s uses symbol %s from namespace %s, but does not import it.\n" ,
2182+ basename , exp -> name , exp -> namespace );
2183+ }
2184+
21212185 if (!mod -> gpl_compatible )
21222186 check_for_gpl_usage (exp -> export , basename , exp -> name );
21232187 check_for_unused (exp -> export , basename , exp -> name );
@@ -2341,15 +2405,18 @@ static void read_dump(const char *fname, unsigned int kernel)
23412405 return ;
23422406
23432407 while ((line = get_next_line (& pos , file , size ))) {
2344- char * symname , * modname , * d , * export , * end ;
2408+ char * symname , * namespace , * modname , * d , * export , * end ;
23452409 unsigned int crc ;
23462410 struct module * mod ;
23472411 struct symbol * s ;
23482412
23492413 if (!(symname = strchr (line , '\t' )))
23502414 goto fail ;
23512415 * symname ++ = '\0' ;
2352- if (!(modname = strchr (symname , '\t' )))
2416+ if (!(namespace = strchr (symname , '\t' )))
2417+ goto fail ;
2418+ * namespace ++ = '\0' ;
2419+ if (!(modname = strchr (namespace , '\t' )))
23532420 goto fail ;
23542421 * modname ++ = '\0' ;
23552422 if ((export = strchr (modname , '\t' )) != NULL )
@@ -2366,7 +2433,8 @@ static void read_dump(const char *fname, unsigned int kernel)
23662433 mod = new_module (modname );
23672434 mod -> skip = 1 ;
23682435 }
2369- s = sym_add_exported (symname , mod , export_no (export ));
2436+ s = sym_add_exported (symname , namespace , mod ,
2437+ export_no (export ));
23702438 s -> kernel = kernel ;
23712439 s -> preloaded = 1 ;
23722440 sym_update_crc (symname , mod , crc , export_no (export ));
@@ -2395,16 +2463,20 @@ static void write_dump(const char *fname)
23952463{
23962464 struct buffer buf = { };
23972465 struct symbol * symbol ;
2466+ const char * namespace ;
23982467 int n ;
23992468
24002469 for (n = 0 ; n < SYMBOL_HASH_SIZE ; n ++ ) {
24012470 symbol = symbolhash [n ];
24022471 while (symbol ) {
2403- if (dump_sym (symbol ))
2404- buf_printf (& buf , "0x%08x\t%s\t%s\t%s\n" ,
2405- symbol -> crc , symbol -> name ,
2406- symbol -> module -> name ,
2407- export_str (symbol -> export ));
2472+ if (dump_sym (symbol )) {
2473+ namespace = symbol -> namespace ;
2474+ buf_printf (& buf , "0x%08x\t%s\t%s\t%s\t%s\n" ,
2475+ symbol -> crc , symbol -> name ,
2476+ namespace ? namespace : "" ,
2477+ symbol -> module -> name ,
2478+ export_str (symbol -> export ));
2479+ }
24082480 symbol = symbol -> next ;
24092481 }
24102482 }
0 commit comments