[PATCH] D118490: [lld][ELF] add .note sections from linker scripts as SHT_NOTE

Luca Boccassi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 28 10:50:49 PST 2022


bluca added a comment.

In D118490#3280116 <https://reviews.llvm.org/D118490#3280116>, @bluca wrote:

> In D118490#3280046 <https://reviews.llvm.org/D118490#3280046>, @MaskRay wrote:
>
>> Not very comfortable with this. I think GNU ld has other rules in this area and I am not sure we want to follow them all.
>> Can you file a feature request on https://sourceware.org/bugzilla/ to add a way to specify the output section type? https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type
>
> Hi,
>
> The problem is that breaks backward compatibility with bfd, because there's no such specifier there, so we can't change how it behaves with existing scripts. For the linked feature ( https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects ), we have a distro-wide linker script that we need to use for all builds. It's not really doable to do per-build-dependency generation, it's hard enough as it is. We need full compatibility.
>
> Also, isn't compatibility with input supported by bfd a project goal? If you take the linker script I added as a test and run it through bfd and lld, they'll generate different and incompatible outputs that breaks tools like systemd-coredump.
>
> Finally it's not just the section type, it also needs to be allocatable.

Let me add some more context on this feature work, given that wiki page is quite long. Fedora 36 is being rebuilt with every ELF binary including a small note following this specification:

https://systemd.io/COREDUMP_PACKAGE_METADATA/

the purpose of this in short is to give reliable and accurate metadata when things crash, regardless of the state of the system, configuration, network, etc, for the benefit of support engineers, maintainers and developers.

So we need this note to appear in SHT_NOTE format, and allocatable (SHF_ALLOC) so that it's loaded in memory and automatically included in the core file generated by the kernel.
systemd-coredump can then find it in the core file and add structured metadata to the journal and various log messages, and tooling handling cores like coredumpctl shows it by default, and so on.

Given lld is not compatible with the linker script we generated, which is accepted by bfd, we have to disable this feature for packages using lld. This is of course not ideal, and it's lld that gets blamed due to the lack of compatibility with bfd, so I'm attempting to fix it.

Which these two patches, the existing linker scripts we are using work out of the box and the binaries behave in the expected way, just like if they were built with gcc and bfd.

Hope this helps. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118490/new/

https://reviews.llvm.org/D118490



More information about the llvm-commits mailing list