[Patch] ld plugin: Fix known_used with CLAIM_FILE_HOOK_V2 for elf_link_add_archive_symbols [GCC PR122432]
Tobias Burnus
tburnus@baylibre.com
Mon Oct 27 18:14:26 GMT 2025
This is about CLAIM_FILE_HOOK_V2's known_used flag, its effect
on GCC's offloading side and common symbols processing.
Originally, for any call to the hook, the compiler processed
the offloading code - even for unused common symbols. The fix
was to add a 'known_used' to the call (_v2) and only do so when
true.
The current scheme fails, however, if a common symbol comes
in a file before any actually used symbol - as the common
symbol already triggers a call to the plugin - with 'known_used'
set to false - and never calls it again afterward.
The solution proposed in this email/patch is to move the
common symbol handling until after all other symbols have
been handled - such that the hook will either be called
later with known_used = true and only, if none of those
are used, a call to the hook with false can happen.
* * *
The original change that introduce known_used is
commit b21318bd2c2 "Add LDPT_REGISTER_CLAIM_FILE_HOOK_V2
linker plugin hook [GCC PR109128]" with associated GCC
lto-plugin modifying commit r14-677-gc49d51fa8134f6.
* * *
Comments, concerns? If not, OK for mainline?
* * *
That there is some problem was known for longer, but it
was hard to debug - especially for users and code sharing
was not always possible. It also tended to disappear when
reducing it, which made it difficult debug or to create a
reproducer. Fortunately, this issue is now understood.
Tobias
PS: As I never had to push to Sourceware, I only have a
GCC account. Thus, I either need an account or someone to
push it for me :-)
PPS: I have tested this by building Binutils and using it
with the respective code. I have not extensively exercised
a lot of code and I fail to see how to add a testcase for this.
(Commit b21318bd2c2 did only do so for the new plugin interface.)
If you have suggestions what to tested in addition, please tell me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ld-plugin-Fix-known_used-with-CLAIM_FILE_HOOK_V2-for.patch
Type: text/x-patch
Size: 7063 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20251027/55476c4f/attachment-0001.bin>
More information about the Binutils
mailing list