mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org, djwong@kernel.org,
	yujie.liu@intel.com, tglx@linutronix.de, joao.moreira@intel.com,
	samitolvanen@google.com
Subject: Re: [PATCH 3/5] objtool: Avoid O(bloody terrible) behaviour -- an ode to libelf
Date: Thu, 3 Nov 2022 09:46:09 +0100	[thread overview]
Message-ID: <Y2N/0YarDv6yeuuw@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20221102222222.r4xkj6uynlj6n2t6@treble>

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@infradead.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.

  reply	other threads:[~2022-11-03  8:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 19:40 [PATCH 0/5] x86/kallsyms: Fix the call-thunk kallsyms fail Peter Zijlstra
2022-10-28 19:40 ` [PATCH 1/5] kallsyms: Revert "Take callthunks into account" Peter Zijlstra
2022-10-28 19:40 ` [PATCH 2/5] objtool: Slice up elf_create_section_symbol() Peter Zijlstra
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-28 19:40 ` [PATCH 3/5] objtool: Avoid O(bloody terrible) behaviour -- an ode to libelf Peter Zijlstra
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-11-02 22:22   ` [PATCH 3/5] " Josh Poimboeuf
2022-11-03  8:46     ` Peter Zijlstra [this message]
2022-10-28 19:40 ` [PATCH 4/5] objtool: Add option to generate prefix symbols Peter Zijlstra
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-11-02 23:41   ` [PATCH 4/5] " Josh Poimboeuf
2022-10-28 19:40 ` [PATCH 5/5] x86: Add prefix symbols for function padding Peter Zijlstra
2022-11-02  9:20   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra
2022-10-30  9:15 ` [PATCH 0/5] x86/kallsyms: Fix the call-thunk kallsyms fail Peter Zijlstra
2022-10-31  6:18   ` Yujie Liu
2022-11-02 21:46 ` [PATCH 6/5] objtool: Optimize elf_dirty_reloc_sym() Peter Zijlstra
2022-11-05 10:36   ` [tip: x86/core] " tip-bot2 for Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2N/0YarDv6yeuuw@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=djwong@kernel.org \
    --cc=joao.moreira@intel.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yujie.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®