lkml.org 
[lkml]   [2021]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 01/13] objtool: Rewrite hashtable sizing
On Thu, May 06, 2021 at 09:33:53PM +0200, Peter Zijlstra wrote:
> @@ -343,6 +360,10 @@ static int read_symbols(struct elf *elf)
>
> symbols_nr = symtab->sh.sh_size / symtab->sh.sh_entsize;
>
> + if (!elf_alloc_hash(symbol, symbols_nr) ||
> + !elf_alloc_hash(symbol_name, symbols_nr))
> + return -1;
> +
> for (i = 0; i < symbols_nr; i++) {
> sym = malloc(sizeof(*sym));
> if (!sym) {

Ingo ran into the empty file without .symtab case with as-2.36.1, which
then means we don't even allocate the symbol hashes which then explodes
later.

The below seems to fix things.

---
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6942357cd4a2..60bef847ee85 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -340,25 +340,19 @@ static int read_symbols(struct elf *elf)
{
struct section *symtab, *symtab_shndx, *sec;
struct symbol *sym, *pfunc;
- int symbols_nr, i;
+ int i, symbols_nr = 0;
char *coldstr;
Elf_Data *shndx_data = NULL;
Elf32_Word shndx;

symtab = find_section_by_name(elf, ".symtab");
- if (!symtab) {
- /*
- * A missing symbol table is actually possible if it's an empty
- * .o file. This can happen for thunk_64.o.
- */
- return 0;
- }
-
- symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
- if (symtab_shndx)
- shndx_data = symtab_shndx->data;
+ if (symtab) {
+ 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;
+ }

if (!elf_alloc_hash(symbol, symbols_nr) ||
!elf_alloc_hash(symbol_name, symbols_nr))
\
 
 \ /
  Last update: 2021-05-12 12:44    [W:0.276 / U:0.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site