]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld: BTF deduplication
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:33:53 +0000 (21:33 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 20:33:53 +0000 (21:33 +0100)
commit0d6c6345b74557482be29adeb3944cc5822526cd
tree10a2dc43a0ffbee511350459c1ddc9eacf69c651
parent1cea8a8ce757eb5e99f228abdf73cd62578b7745
ld: BTF deduplication

Figuring out what to do when a mix of BTF and CTF sections is supplied is a
little magical.  We hunt down all the .BTF and .ctf sections in the link,
but just because all the sections we found were .BTF doesn't mean that the
output isn't going to be CTF: if deduplication results in any conflicting
types, we'll need a CTF section to encode them (BTF cannot yet represent
such things).

So if we find that we've got nothing but .BTF sections, we do as we do for
.ctf and mark all but one of them as excluded from the link (with the intent
of creating the deduplicated output in the remaining one): but we also
create a provisional linker-created .ctf section, just in case we need it
later (we can't tell at this stage, before deduplication).

After deduplication, one of these sections is unneeded.  Sometimes, we can
do this removal via Depending on the emulation, lang_write_ctf may be called
either early (long before bfd_elf_final_link) or late (after final link and
indeed symtab and strtab writeout).  (ELF calls it late).  If called early,
we can figure out what format was emitted by ctf_link and freely remove the
unwanted section by flipping on its SEC_EXCLUDE flag.

But that leaves late calls.  We add a new ctf_remove_section hook to the
bfd_link_callbacks, which is invoked at the very start of
bfd_elf_final_link, when removal of sections is still permitted.  We invoke
section removal for the .ctf-or-.BTF section via this hook if lang_write_ctf
is called late: this then does the extra trickery with section count
adjustment etc needed to remove sections so late, and communicates the fact
that it's removed sections to bfd_elf_final_link, which can then decide to
call _bfd_fix_excluded_sec_syms (which is quite expensive, so we do it only
once for all sections removed at this stage, by whatever means).
bfd/elflink.c
include/bfdlink.h
ld/ldlang.c
ld/ldlang.h
ld/ldmain.c