RFR: 8336849: Remove .llvm_addrsig section from JDK/VM static libraries (.a files)
Jiangli Zhou
jiangli at openjdk.org
Tue Aug 6 17:10:31 UTC 2024
On Tue, 6 Aug 2024 13:26:00 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:
> But why and how do you specify `-Wl,--icf=safe` when building libjvm.a? That is not part of the linker flags in the JDK build mainline. I have not encountered these problems when trying to link with lld.
No, it's not when **building** `libjvm.a`. It's when linking the final elf executable **using** `libjvm.a` (or `libnet.a`, etc) that's created with `ld -r` or `objcopy`. During the final elf executable linking time, user could include additional desired linker flags, such as `-Wl,--icf=safe`. That's the case where things can run into trouble.
We don't have control of the linker flags that users might want to use.
>
> In any case, the links you provided explains why this approach is catastrophically wrong:
>
> > Other linkers, notably LLVM lld, supports --icf=safe. It uses .llvm_addrsig sections to identify functions that are safe to merge. Functions that are not mentioned in the section are not address-taken (no one takes its pointer), so they are safe to merge.
>
> If you were to remove these sections, then the linker will believe that all functions are safe to merge.
How did you arrive the conclusion?
According to https://maskray.me/blog/2020-11-15-explain-gnu-linker-options#icfall-and---icfsafe (already linked from the bug description),
"ld.lld --icf=safe uses a special section `.llvm_addrsig` (LLVM address significance table, type SHT_LLVM_ADDRSIG) produced by Clang -faddrsig....If the section is absent, ld.lld is conservative and assumes every section defining a symbol in the table is address significant."
When `.llvm_addrsig` section is removed (not present), my understanding is that the linker would only do conservative identical code folding safely.
See more in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105625.
>
> If you really want that, then you should pass `--icf=all` to the linker, and then it will stop caring about the `.llvm_addrsig` sections.
>
> But from reading the links you sent, the safe and sound approach seems to be to send `--icf=none` to lld when it should operate on a partially linked (ld -r) .o file.
`--icf=all` is more aggressive optimization and might not be safe? Also, we don't control how developers would be building the final elf image.
Removing `.llvm_addrsig` is safe. It has the benefit of not restricting specific final linking flags.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20265#issuecomment-2271754139
More information about the build-dev
mailing list