This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Implement removal of unused dylibs
ClosedPublic

Authored by thakis on May 31 2021, 7:22 PM.

Details

Reviewers
int3
gkm
Group Reviewers
Restricted Project
Commits
rG2c1903412b0a: [lld/mac] Implement removal of unused dylibs
Summary

This omits load commands for unreferenced dylibs if:

  • the dylib was loaded implicitly,
  • it is marked MH_DEAD_STRIPPABLE_DYLIB
  • or -dead_strip_dylibs is passed

This matches ld64.

Currently, the "is dylib referenced" state is computed before dead code
stripping and is not updated after dead code stripping. This too matches ld64.
We should do better here.

With this, clang-format linked with lld (like with ld64) no longer has
libobjc.A.dylib in otool -L output. (It was implicitly loaded as a reexport
of CoreFoundation.framework, but it's not needed.)

Diff Detail

Event Timeline

thakis created this revision.May 31 2021, 7:22 PM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: dang. · View Herald Transcript
thakis requested review of this revision.May 31 2021, 7:22 PM
int3 added inline comments.Jun 1 2021, 12:06 PM
lld/MachO/InputFiles.h
166

why not just make it unsigned, and check that we don't call unreference() if it's already zero?

lld/MachO/Symbols.h
251

can we have a comment about why the && file check is necessary?

255

ultra nit: can we have a newline between multi-line functions?

lld/test/MachO/dead-strip-dylibs.s
49
lld/test/MachO/implicit-dylibs.s
78–79

this seems kind of sketch since this line could appear elsewhere in the output... --implicit-check-not LC_LOAD_DYLIB (like the other test is using) seems better

thakis updated this revision to Diff 349066.Jun 1 2021, 12:37 PM
thakis marked 4 inline comments as done.

comments

Thanks! All done.

int3 accepted this revision.Jun 1 2021, 1:00 PM

Thanks!

This revision is now accepted and ready to land.Jun 1 2021, 1:00 PM
This revision was landed with ongoing or failed builds.Jun 1 2021, 1:12 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2021, 1:12 PM