This is an archive of the discontinued LLVM Phabricator instance.

[profile] Make {__start_,__stop_}__llvm_prf_* symbols undefined weak
ClosedPublic

Authored by MaskRay on Feb 17 2021, 10:59 PM.

Details

Summary

To make a kind of metadata section usage work, we may drop the
__start_/__stop_ references retain C identifier name sections rule from LLD (see D96914).

If an application has no __llvm_prf_data surviving --gc-sections,
LLD will error for {__start_,__stop_}__llvm_prf_* references from libclang_rt.profile-*.
Other __llvm_prf_* sections have similar issues.

Making the references weak can address the problem.
This probably enables the opportunity to drop zero size dummy sections in InstrProfilingPlatformLinux.c.

Diff Detail

Event Timeline

MaskRay requested review of this revision.Feb 17 2021, 10:59 PM
MaskRay created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2021, 10:59 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

@davidxl In D14468, you mentioned:

Making start_../stop_.. weak extern symbols solve the problem when building executable, but PC relative dynamic reloc is not allowed so shared library case will still fail.

do you remember in what cases that can fail? That could mean an old compiler bug. I think we may be able to delete the dummy sections if we use undefined weak symbols.

Does it work for other linkers with this change?

Does it work for other linkers with this change?

Yes. Checked with:

clang++ -fprofile-generate -fuse-ld={bfd,gold,lld} -Wl,--gc-sections a.cc
clang++ -fprofile-generate -fuse-ld={bfd,gold,lld} -Wl,--gc-sections a.cc -fpic -shared

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

Thanks! I'll do that separately after this change sticks.

MaskRay edited the summary of this revision. (Show Details)Feb 17 2021, 11:29 PM
MaskRay edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Feb 17 2021, 11:33 PM
This revision was automatically updated to reflect the committed changes.