This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] `-exported_symbols` should hide symbols before LTO runs
ClosedPublic

Authored by int3 on Jul 23 2022, 10:14 AM.

Details

Summary

We were previously doing it after LTO, which did have the desired effect
of having the un-exported symbols marked as private extern in the final
output binary, but doing it before LTO creates more optimization
opportunities.

One observable difference is that LTO can now elide un-exported symbols
entirely, so they may not even be present as private externs in the
output.

This is also what ld64 implements.

Diff Detail

Event Timeline

int3 created this revision.Jul 23 2022, 10:14 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 23 2022, 10:14 AM
int3 requested review of this revision.Jul 23 2022, 10:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2022, 10:14 AM
int3 added inline comments.Jul 23 2022, 10:17 AM
lld/MachO/Driver.cpp
1632–1635

had to move these up as well as they need to run before handleExplicitExports

int3 updated this revision to Diff 447405.Jul 25 2022, 10:40 AM

tweak comment

int3 planned changes to this revision.Jul 25 2022, 12:24 PM
thevinster accepted this revision.Jul 28 2022, 11:59 AM
thevinster added a subscriber: thevinster.
thevinster added inline comments.
lld/MachO/Driver.cpp
536

Instead of needing to set didCompile on every loop iteration, we could extract lto->compile into another variable and set didCompile based on the size of that variable? It's minor but feels cleaner this way.

This revision is now accepted and ready to land.Jul 28 2022, 11:59 AM
int3 marked an inline comment as done.Jul 28 2022, 2:52 PM
int3 added inline comments.
lld/MachO/Driver.cpp
536

good idea :)

This revision was automatically updated to reflect the committed changes.
int3 marked an inline comment as done.