Skip to content

Commit 69c4cc9

Browse files
committed
modpost: add sym_find_with_module() helper
find_symbol() returns the first symbol found in the hash table. This table is global, so it may return a symbol from an unexpected module. There is a case where we want to search for a symbol with a given name in a specified module. Add sym_find_with_module(), which receives the module pointer as the second argument. It is equivalent to find_module() if NULL is passed as the module pointer. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM-14 (x86-64)
1 parent 2a66c31 commit 69c4cc9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/mod/modpost.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
266266
list_add_tail(&sym->list, &mod->unresolved_symbols);
267267
}
268268

269-
static struct symbol *find_symbol(const char *name)
269+
static struct symbol *sym_find_with_module(const char *name, struct module *mod)
270270
{
271271
struct symbol *s;
272272

@@ -275,12 +275,17 @@ static struct symbol *find_symbol(const char *name)
275275
name++;
276276

277277
for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
278-
if (strcmp(s->name, name) == 0)
278+
if (strcmp(s->name, name) == 0 && (!mod || s->module == mod))
279279
return s;
280280
}
281281
return NULL;
282282
}
283283

284+
static struct symbol *find_symbol(const char *name)
285+
{
286+
return sym_find_with_module(name, NULL);
287+
}
288+
284289
struct namespace_list {
285290
struct list_head list;
286291
char namespace[];

0 commit comments

Comments
 (0)