Re: build failure after commit eb0481bbc4ce ("objtool: Fix reloc_hash size")

From: Peter Zijlstra
Date: Wed Jun 28 2023 - 15:32:50 EST


On Wed, Jun 28, 2023 at 11:10:19AM -0700, Josh Poimboeuf wrote:
> On Wed, Jun 28, 2023 at 07:26:59PM +0200, Michal Kubecek wrote:
> > I digged some more and my guess is that the problem is that
> > elf_open_read() does
> >
> > memset(elf, 0, offsetof(struct elf, sections));
> >
> > but commit eb0481bbc4ce ("objtool: Fix reloc_hash size") added
> > num_relocs after sections so that it is not zeroed (0xbabababababababa
> > is probably some kind of poison).
>
> Argh, that memset() is subtle as heck. Peter, why?!?

Well, at the time struct elf had a bunch of fairly large hash tables
embedded inside it. memset() on those was a significant performance fail
-- esp. since we called objtool on every .o file.

struct elf {
Elf *elf;
GElf_Ehdr ehdr;
int fd;
char *name;
struct list_head sections;
DECLARE_HASHTABLE(symbol_hash, 20);
DECLARE_HASHTABLE(symbol_name_hash, 20);
DECLARE_HASHTABLE(section_hash, 16);
DECLARE_HASHTABLE(section_name_hash, 16);
DECLARE_HASHTABLE(rela_hash, 20);
};

Those embedded hash-tables have gone away, but apparently someone forgot
about this thing :/

Yes, this can go, struct elf is no longer like that.