[llvm-dev] [RFC] Changing .llvm.call-graph-profile to use relocations

maskray@google.com via llvm-dev llvm-dev at lists.llvm.org
Wed May 26 17:03:53 PDT 2021


On 2021-05-26, Alexander Yermolovich wrote:
>Currently when .llvm.call-graph-profile is created by llvm it explicitly encodes the symbol indices. This section is basically a black box for post processing tools. For example, if we run strip -s on the object files the symbol table changes, but indices in that section do not.
>
>We propose to change this section to use relocations. The Frequency will still be in the .llvm.call-graph-profile, but symbol information will be in relocation section. In LLD information from both sections is used to reconstruct call graph profile. Relocations themselves will never be applied.

Yes, a relocation based approach will be more robust and can fix the
.llvm_addrsig issue https://sourceware.org/bugzilla/show_bug.cgi?id=23817

The relocation type doesn't matter. Your implementation uses R_X86_64_32 and from/to/value/from/to/value/from/to/value
An alternative design is R_X86_64_NONE + value/value/value, i.e. from/to do not occupy space in the content.
We will get a 3x space saving.

We need to change the section type since changing representation is incompatible
and the sections from old object files should be ignored.
The new section type will be ignored by old LLVM tools as well.

>With this approach post processing tools that handle relocations correctly work for this section also.
>
>One thing is section is marked with SHF_EXCLUDE.
>From spec
>"This section is excluded from input to the link-edit of an executable or shared object. This flag is ignored if the SHF_ALLOC flag is also set, or if relocations exist against the section."
>
>So technically speaking it needs to be kept, and presumably relocations applied, but LLD follows gold and ld and discards sections marked as SHF_EXCLUDE even with relocations. So, I think this approach should be fine. https://reviews.llvm.org/D24966

This is Solaris's spec (since 1996), not standard ELF's.  It can be advisory but
our behavior (mostly GNU ABI+Linux ABI+LLVM extensions) does not necessarily
follow it.  I cannot find a definition in the x86-64 psABI or a GNU ABI
document.

I think the behavior as implemented in gold and LLD is more useful.

>Finally, this bug seems similar to https://sourceware.org/bugzilla/show_bug.cgi?id=23817. Proposed solution for that was also to use relocations.
>
>Implementation: https://reviews.llvm.org/D103212


More information about the llvm-dev mailing list