This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Mark aliased symbols as noDeadStrip
ClosedPublic

Authored by keith on Oct 3 2022, 9:13 AM.

Details

Reviewers
thakis
int3
Group Reviewers
Restricted Project
Commits
rG1d1aa2d0130c: [lld-macho] Mark aliased symbols as noDeadStrip
Summary

This matches ld64 behavior

Diff Detail

Event Timeline

keith created this revision.Oct 3 2022, 9:13 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 3 2022, 9:13 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
keith requested review of this revision.Oct 3 2022, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 9:13 AM

I didn't investigate the ld64 behavior besides checking that this same test case passes with it

lld/MachO/MarkLive.cpp
232

Left this here since we don't support this one yet

thakis accepted this revision.Oct 3 2022, 3:49 PM
thakis added a subscriber: int3.

Thanks!

I wonder if N_INDR symbols need this too? Probably not. (@int3)

This revision is now accepted and ready to land.Oct 3 2022, 3:49 PM
int3 added a comment.Oct 3 2022, 4:17 PM

I played around with the test a bit and I realized that ld64 doesn't actually dead-strip _foo if .subsections_via_symbols isn't there (even though _foo and _main are in separate files and therefore separate sections...)

With .subsections_via_symbols added, I noticed that ld64 does actually dead-strip _bar (but not _foo!). I am not really sure that behavior makes sense, presumably an alias exists so that some other library can look up the aliasing symbol name, not the aliased symbol name...

So I think we should add .subsections_via_symbols + add a comment to the test describing this deviation from ld64

I will look into N_INDR shortly...

int3 added a comment.Oct 3 2022, 4:48 PM

Oh yeah our alias-symbols.s test case already covers the -dead_strip + N_INDR case so we're good

int3 accepted this revision.Oct 3 2022, 4:49 PM

lgtm modulo the changes to the test suggested above

int3 added a comment.Oct 3 2022, 7:22 PM

So I think we should add .subsections_via_symbols + add a comment to the test describing this deviation from ld64

Just for completeness: imitating this behavior isn't the most trivial since we track liveness at the InputSection level rather than at the symbol level. But I don't think it's important to imitate this, so it's all good

keith added a comment.Oct 4 2022, 2:39 PM

Thanks for investigating some more, IIUC you're saying merge as is correct?

int3 added a comment.Oct 4 2022, 2:39 PM

yeah add .subsections_via_symbols and a comment about ld64's behavior to the test, then merge :)

keith updated this revision to Diff 465170.Oct 4 2022, 2:53 PM

Update test with ld64 context

This revision was landed with ongoing or failed builds.Oct 4 2022, 2:54 PM
This revision was automatically updated to reflect the committed changes.