This is an archive of the discontinued LLVM Phabricator instance.

[profile] Add __attribute__((used)) to zero size dummy sections
ClosedPublic

Authored by MaskRay on Feb 17 2021, 2:25 PM.

Details

Summary

D14468 added these dummy sections. This patch adds __attribute__((used)) so
that when compiled by GCC>=11 or (expected, D96838) Clang>=13 on some ELF platforms,
these sections will get SHF_GNU_RETAIN to make sure they will not be discarded
by ld --gc-sections.

We are trying to get rid of LLD's "C identifier name sections are GC roots" semantics.
If LLD drops the rule in the future (we will retain compatibility for __llvm_prf_* for a while),
__llvm_prf_* will need to have the SHF_GNU_RETAIN flag, otherwise:

// __llvm_prf_cnts/__llvm_prf_data usually exist, but {names,vnds} may not exist.
// Such diagnostics will happen with {cnts,data} as well if no input object file is instrumented.
% clang++ -fprofile-generate a.cc -fuse-ld=lld -Wl,--gc-sections
ld.lld: error: undefined hidden symbol: __start___llvm_prf_names
>>> referenced by InstrProfilingPlatformLinux.c
>>>               InstrProfilingPlatformLinux.c.o:(__llvm_profile_begin_names) in archive /tmp/RelA/lib/clang/13.0.0/lib/linux/libclang_rt.profile-x86_64.a
...

Diff Detail

Event Timeline

MaskRay created this revision.Feb 17 2021, 2:25 PM
MaskRay requested review of this revision.Feb 17 2021, 2:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2021, 2:25 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
davidxl accepted this revision.Feb 17 2021, 2:38 PM

lgtm

This revision is now accepted and ready to land.Feb 17 2021, 2:38 PM

Apologies that I might have committed this too fast (I wanted to unblock others quickly) but I just noticed there has been a discussion on whether __attribute__((used)) should have SHF_GNU_RETAIN behavior in GCC community.
I'll watch it closely: https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565457.html
(I think even if they did not use used, they would pick a different attribute.)