Skip to content

Commit 9a7827b

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
objtool: Extract elf_symbol_add()
Create a common helper to add symbols. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 417a4dc commit 9a7827b

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

tools/objtool/elf.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,39 @@ static int read_sections(struct elf *elf)
290290
return 0;
291291
}
292292

293+
static void elf_add_symbol(struct elf *elf, struct symbol *sym)
294+
{
295+
struct list_head *entry;
296+
struct rb_node *pnode;
297+
298+
sym->type = GELF_ST_TYPE(sym->sym.st_info);
299+
sym->bind = GELF_ST_BIND(sym->sym.st_info);
300+
301+
sym->offset = sym->sym.st_value;
302+
sym->len = sym->sym.st_size;
303+
304+
rb_add(&sym->node, &sym->sec->symbol_tree, symbol_to_offset);
305+
pnode = rb_prev(&sym->node);
306+
if (pnode)
307+
entry = &rb_entry(pnode, struct symbol, node)->list;
308+
else
309+
entry = &sym->sec->symbol_list;
310+
list_add(&sym->list, entry);
311+
elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
312+
elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
313+
314+
/*
315+
* Don't store empty STT_NOTYPE symbols in the rbtree. They
316+
* can exist within a function, confusing the sorting.
317+
*/
318+
if (!sym->len)
319+
rb_erase(&sym->node, &sym->sec->symbol_tree);
320+
}
321+
293322
static int read_symbols(struct elf *elf)
294323
{
295324
struct section *symtab, *symtab_shndx, *sec;
296325
struct symbol *sym, *pfunc;
297-
struct list_head *entry;
298-
struct rb_node *pnode;
299326
int symbols_nr, i;
300327
char *coldstr;
301328
Elf_Data *shndx_data = NULL;
@@ -340,9 +367,6 @@ static int read_symbols(struct elf *elf)
340367
goto err;
341368
}
342369

343-
sym->type = GELF_ST_TYPE(sym->sym.st_info);
344-
sym->bind = GELF_ST_BIND(sym->sym.st_info);
345-
346370
if ((sym->sym.st_shndx > SHN_UNDEF &&
347371
sym->sym.st_shndx < SHN_LORESERVE) ||
348372
(shndx_data && sym->sym.st_shndx == SHN_XINDEX)) {
@@ -355,32 +379,14 @@ static int read_symbols(struct elf *elf)
355379
sym->name);
356380
goto err;
357381
}
358-
if (sym->type == STT_SECTION) {
382+
if (GELF_ST_TYPE(sym->sym.st_info) == STT_SECTION) {
359383
sym->name = sym->sec->name;
360384
sym->sec->sym = sym;
361385
}
362386
} else
363387
sym->sec = find_section_by_index(elf, 0);
364388

365-
sym->offset = sym->sym.st_value;
366-
sym->len = sym->sym.st_size;
367-
368-
rb_add(&sym->node, &sym->sec->symbol_tree, symbol_to_offset);
369-
pnode = rb_prev(&sym->node);
370-
if (pnode)
371-
entry = &rb_entry(pnode, struct symbol, node)->list;
372-
else
373-
entry = &sym->sec->symbol_list;
374-
list_add(&sym->list, entry);
375-
elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
376-
elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
377-
378-
/*
379-
* Don't store empty STT_NOTYPE symbols in the rbtree. They
380-
* can exist within a function, confusing the sorting.
381-
*/
382-
if (!sym->len)
383-
rb_erase(&sym->node, &sym->sec->symbol_tree);
389+
elf_add_symbol(elf, sym);
384390
}
385391

386392
if (stats)

0 commit comments

Comments
 (0)