[Patch] ld plugin: Fix known_used with CLAIM_FILE_HOOK_V2 for elf_link_add_archive_symbols [GCC PR122432]
H.J. Lu
hjl.tools@gmail.com
Mon Oct 27 21:23:38 GMT 2025
On Tue, Oct 28, 2025 at 2:14 AM Tobias Burnus <tburnus@baylibre.com> wrote:
>
> 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.
I can't reproduce the issue. If the common symbol comes first is an issue,
you can create a testcase with 2 separate sources:
1. a.c only with a common symbol.
2. b.c uses the common symbol.
Without a testcase and others can't reproduce the issue, it is
very hard to tell if your patch is correct or not.
Please first create a binutils bug report.
> 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.
--
H.J.
More information about the Binutils
mailing list