[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y2N/0YarDv6yeuuw@hirez.programming.kicks-ass.net>
Date: Thu, 3 Nov 2022 09:46:09 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Josh Poimboeuf <jpoimboe@...nel.org>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org, djwong@...nel.org,
yujie.liu@...el.com, tglx@...utronix.de, joao.moreira@...el.com,
samitolvanen@...gle.com
Subject: Re: [PATCH 3/5] objtool: Avoid O(bloody terrible) behaviour -- an
ode to libelf
On Wed, Nov 02, 2022 at 03:22:22PM -0700, Josh Poimboeuf wrote:
> On Fri, Oct 28, 2022 at 09:40:25PM +0200, Peter Zijlstra wrote:
> > Due to how gelf_update_sym*() requires an Elf_Data pointer, and how
> > libelf keeps Elf_Data in a linked list per section,
> > elf_update_symbol() ends up having to iterate this list on each
> > update to find the correct Elf_Data for the index'ed symbol.
> >
> > By allocating one Elf_Data per new symbol, the list grows per new
> > symbol, giving an effective O(n^2) insertion time. This is obviously
> > bloody terrible.
> >
> > Therefore over-allocate the Elf_Data when an extention is needed.
> > Except it turns out libelf disregards Elf_Scn::sh_size in favour of
> > the sum of Elf_Data::d_size. IOW it will happily write out all the
> > unused space and fill it with:
> >
> > 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
> >
> > entries (aka zeros). Which obviously violates the STB_LOCAL placement
> > rule, and is a general pain in the backside for not being the desired
> > behaviour.
> >
> > Manually fix-up the Elf_Data size to avoid this problem before calling
> > elf_update().
> >
> > This significantly improves performance when adding a significant
> > number of symbols.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
>
> Instead of going through libelf to add each symbol, and
> adjusting/shifting/reallocating the d_buf one symbol at a time, it would
> probably be a lot easier (and faster) to just manually do all that at
> the end, just before writing the file.
Yeah, I've been >< close to doing that at least twice now. The only
consideration is that we then also must rewrite all relocs but I think
we end up doing that anyway.
I'll go do the patch to see what it looks like.
Powered by blists - more mailing lists