OpenCloudOS-Kernel/tools/objtool
Peter Zijlstra 13f60e80e1 objtool: Avoid O(bloody terrible) behaviour -- an ode to libelf
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>
Tested-by: Yujie Liu <yujie.liu@intel.com>
Link: https://lkml.kernel.org/r/20221028194453.461658986@infradead.org
2022-11-01 13:44:08 +01:00
..
Documentation objtool: Update documentation 2022-04-22 12:32:05 +02:00
arch/x86 objtool: Allow !PC relative relocations 2022-10-17 16:41:06 +02:00
include/objtool objtool: Avoid O(bloody terrible) behaviour -- an ode to libelf 2022-11-01 13:44:08 +01:00
.gitignore objtool: Rework header include paths 2021-01-13 18:13:14 -06:00
Build objtool: Ditch subcommands 2022-04-22 12:32:01 +02:00
Makefile Kbuild updates for v5.19 2022-05-26 12:09:50 -07:00
builtin-check.c objtool: Add --hacks=skylake 2022-10-17 16:41:07 +02:00
check.c objtool: Allow STT_NOTYPE -> STT_FUNC+0 sibling-calls 2022-10-17 16:41:09 +02:00
elf.c objtool: Avoid O(bloody terrible) behaviour -- an ode to libelf 2022-11-01 13:44:08 +01:00
objtool.c objtool: Add .call_sites section 2022-10-17 16:41:07 +02:00
orc_dump.c x86/unwind/orc: Change REG_SP_INDIRECT 2021-02-10 20:53:51 +01:00
orc_gen.c Merge branch 'objtool/urgent' 2021-10-07 00:40:17 +02:00
special.c objtool,x86: Replace alternatives with .retpoline_sites 2021-10-28 23:25:25 +02:00
sync-check.sh Merge branch 'x86/cpu' into WIP.x86/core, to merge the NOP changes & resolve a semantic conflict 2021-04-02 12:36:30 +02:00
weak.c objtool: Ditch subcommands 2022-04-22 12:32:01 +02:00