This is an archive of the discontinued LLVM Phabricator instance.

[InstrProfiling] Use llvm.compiler.used if applicable for Mach-O
ClosedPublic

Authored by MaskRay on Jul 5 2021, 12:59 PM.

Details

Summary

Similar to D97585.

D25456 used S_ATTR_LIVE_SUPPORT to ensure the data variable will be retained
or discarded as a unit with the counter variable, so llvm.compiler.used is
sufficient. It allows ld to dead strip unneeded profc and profd variables.

Diff Detail

Event Timeline

MaskRay created this revision.Jul 5 2021, 12:59 PM
MaskRay requested review of this revision.Jul 5 2021, 12:59 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 5 2021, 12:59 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
MaskRay updated this revision to Diff 356598.EditedJul 5 2021, 9:28 PM

-Wl,-dead_strip

Tested on aarch64 macOS.

MaskRay edited the summary of this revision. (Show Details)Aug 25 2021, 11:31 PM
MaskRay added reviewers: davidxl, vsk.
vsk added a comment.Aug 30 2021, 10:10 AM

Thanks for tackling this.

compiler-rt/test/profile/Darwin/coverage-linkage.cpp
10

The behavior of linker optimizations with LTO enabled may be a bit different. Could you check this case (test/profile/instrprof-darwin-dead-strip.c has an example)?

I don't have access to an x86_64 macOS.

If I remove REQUIRES: lto from test/profile/instrprof-darwin-dead-strip.c, it fails on aarch64 macOS before this patch.

But this patch doesn't change the section contents:

Contents of (__DATA,__llvm_prf_names) section
0000000100018030 6f660008 616d016f 69 6e

Contents of (__DATA,__llvm_prf_cnts) section
0000000100014000        00000000 00000000
vsk added a comment.Aug 30 2021, 11:27 AM

x86 access shouldn't be necessary. Here's a patch for the otool formatting issue: https://reviews.llvm.org/D108929 (feel free to fold this in to your own change, if you'd like to).

Does it look good? :)

vsk accepted this revision.Sep 1 2021, 11:48 AM

Yes, thanks! The test from D108929 should cover the lto case.

This revision is now accepted and ready to land.Sep 1 2021, 11:48 AM