Commit e882e89b authored by Masahiro Yamada's avatar Masahiro Yamada

modpost: add sym_add_unresolved() helper

Add a small helper, sym_add_unresolved() to ease the further
refactoring.

Remove the 'weak' argument from alloc_symbol() because it is sensible
only for unresolved symbols.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent 325eba05
...@@ -236,14 +236,12 @@ static inline unsigned int tdb_hash(const char *name) ...@@ -236,14 +236,12 @@ static inline unsigned int tdb_hash(const char *name)
* Allocate a new symbols for use in the hash of exported symbols or * Allocate a new symbols for use in the hash of exported symbols or
* the list of unresolved symbols per module * the list of unresolved symbols per module
**/ **/
static struct symbol *alloc_symbol(const char *name, bool weak, static struct symbol *alloc_symbol(const char *name, struct symbol *next)
struct symbol *next)
{ {
struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
strcpy(s->name, name); strcpy(s->name, name);
s->weak = weak;
s->next = next; s->next = next;
s->is_static = true; s->is_static = true;
return s; return s;
...@@ -256,11 +254,17 @@ static struct symbol *new_symbol(const char *name, struct module *module, ...@@ -256,11 +254,17 @@ static struct symbol *new_symbol(const char *name, struct module *module,
unsigned int hash; unsigned int hash;
hash = tdb_hash(name) % SYMBOL_HASH_SIZE; hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
symbolhash[hash] = alloc_symbol(name, false, symbolhash[hash]); symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
return symbolhash[hash]; return symbolhash[hash];
} }
static void sym_add_unresolved(const char *name, struct module *mod, bool weak)
{
mod->unres = alloc_symbol(name, mod->unres);
mod->unres->weak = weak;
}
static struct symbol *find_symbol(const char *name) static struct symbol *find_symbol(const char *name)
{ {
struct symbol *s; struct symbol *s;
...@@ -712,9 +716,8 @@ static void handle_symbol(struct module *mod, struct elf_info *info, ...@@ -712,9 +716,8 @@ static void handle_symbol(struct module *mod, struct elf_info *info,
} }
} }
mod->unres = alloc_symbol(symname, sym_add_unresolved(symname, mod,
ELF_ST_BIND(sym->st_info) == STB_WEAK, ELF_ST_BIND(sym->st_info) == STB_WEAK);
mod->unres);
break; break;
default: default:
/* All exported symbols */ /* All exported symbols */
...@@ -2082,7 +2085,7 @@ static void read_symbols(const char *modname) ...@@ -2082,7 +2085,7 @@ static void read_symbols(const char *modname)
* the automatic versioning doesn't pick it up, but it's really * the automatic versioning doesn't pick it up, but it's really
* important anyhow */ * important anyhow */
if (modversions) if (modversions)
mod->unres = alloc_symbol("module_layout", false, mod->unres); sym_add_unresolved("module_layout", mod, false);
} }
static void read_symbols_from_files(const char *filename) static void read_symbols_from_files(const char *filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment