Commit 28fe1d7b authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Peter Zijlstra

objtool: use gelf_getsymshndx to handle >64k sections

Currently, objtool fails to load the correct section for symbols when
the index is greater than SHN_LORESERVE. Use gelf_getsymshndx instead
of gelf_getsym to handle >64k sections.
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20200421220843.188260-2-samitolvanen@google.com
parent ab3852ab
...@@ -343,12 +343,14 @@ static int read_sections(struct elf *elf) ...@@ -343,12 +343,14 @@ static int read_sections(struct elf *elf)
static int read_symbols(struct elf *elf) static int read_symbols(struct elf *elf)
{ {
struct section *symtab, *sec; struct section *symtab, *symtab_shndx, *sec;
struct symbol *sym, *pfunc; struct symbol *sym, *pfunc;
struct list_head *entry; struct list_head *entry;
struct rb_node *pnode; struct rb_node *pnode;
int symbols_nr, i; int symbols_nr, i;
char *coldstr; char *coldstr;
Elf_Data *shndx_data = NULL;
Elf32_Word shndx;
symtab = find_section_by_name(elf, ".symtab"); symtab = find_section_by_name(elf, ".symtab");
if (!symtab) { if (!symtab) {
...@@ -356,6 +358,10 @@ static int read_symbols(struct elf *elf) ...@@ -356,6 +358,10 @@ static int read_symbols(struct elf *elf)
return -1; return -1;
} }
symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
if (symtab_shndx)
shndx_data = symtab_shndx->data;
symbols_nr = symtab->sh.sh_size / symtab->sh.sh_entsize; symbols_nr = symtab->sh.sh_size / symtab->sh.sh_entsize;
for (i = 0; i < symbols_nr; i++) { for (i = 0; i < symbols_nr; i++) {
...@@ -369,8 +375,9 @@ static int read_symbols(struct elf *elf) ...@@ -369,8 +375,9 @@ static int read_symbols(struct elf *elf)
sym->idx = i; sym->idx = i;
if (!gelf_getsym(symtab->data, i, &sym->sym)) { if (!gelf_getsymshndx(symtab->data, shndx_data, i, &sym->sym,
WARN_ELF("gelf_getsym"); &shndx)) {
WARN_ELF("gelf_getsymshndx");
goto err; goto err;
} }
...@@ -384,10 +391,13 @@ static int read_symbols(struct elf *elf) ...@@ -384,10 +391,13 @@ static int read_symbols(struct elf *elf)
sym->type = GELF_ST_TYPE(sym->sym.st_info); sym->type = GELF_ST_TYPE(sym->sym.st_info);
sym->bind = GELF_ST_BIND(sym->sym.st_info); sym->bind = GELF_ST_BIND(sym->sym.st_info);
if (sym->sym.st_shndx > SHN_UNDEF && if ((sym->sym.st_shndx > SHN_UNDEF &&
sym->sym.st_shndx < SHN_LORESERVE) { sym->sym.st_shndx < SHN_LORESERVE) ||
sym->sec = find_section_by_index(elf, (shndx_data && sym->sym.st_shndx == SHN_XINDEX)) {
sym->sym.st_shndx); if (sym->sym.st_shndx != SHN_XINDEX)
shndx = sym->sym.st_shndx;
sym->sec = find_section_by_index(elf, shndx);
if (!sym->sec) { if (!sym->sec) {
WARN("couldn't find section for symbol %s", WARN("couldn't find section for symbol %s",
sym->name); sym->name);
......
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