This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Postprocess LC Linker Option
ClosedPublic

Authored by kyulee on Aug 11 2023, 7:20 AM.

Details

Reviewers
int3
ellis
Group Reviewers
Restricted Project
Commits
rG484c961ccdfa: [lld-macho] Postprocess LC Linker Option
Summary

LLD resolves symbols regardless of LTO modes early when reading and parsing input files in order. The object files built from LTO passes are appended later.
Because LLD eagerly resolves the LC linker options while parsing a new object file (and its chain of dependent libraries), the prior decision on pending prevailing symbols (belonging to some bitcode files) can change to ones in those native libraries that are just loaded.

This patch delays processing LC linker options until all the native object files are added after LTO is done, similar to LD64. This way we preserve the decision on prevailing symbols LLD made, regardless of LTO modes.

  • When parsing a new object file in parseLinkerOptions(), it just parses LC linker options in the header, and saves those contents to unprocessedLCLinkerOptions.
  • After LTO is finished, resolveLCLinkerOptions() is called to recursively load dependent libraries, starting with initial linker options collected in unprocessedLCLinkerOptions (which also updates during recursions)

Diff Detail

Event Timeline

kyulee created this revision.Aug 11 2023, 7:20 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 11 2023, 7:20 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
kyulee requested review of this revision.Aug 11 2023, 7:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 7:20 AM
kyulee retitled this revision from [LLD][MachO] Postprocess LC Linker Option to [lld-macho] Postprocess LC Linker Option.Aug 11 2023, 7:25 AM
kyulee updated this revision to Diff 549460.Aug 11 2023, 10:54 AM

Update tests

kyulee updated this revision to Diff 549462.Aug 11 2023, 10:57 AM

Update tests

int3 added a comment.Aug 12 2023, 9:09 PM

Another way to simplify/shorten the tests is to use %lld instead of %no-arg-lld. This defaults us to linking against x86_64 + macos, but for most tests the arch doesn't actually matter

lld/test/MachO/lc-linker-option-lto.ll
18–19

I think this should work given the changes suggested below on line 54

FileCheck does substring matching by default, so the leading address and other info can be ignored

19

there is also the option of putting weak1/weak2 into different sections per input file. Then you could just run FileCheck on the output of llvm-objdump --syms. This would be my preferred approach

55–58
kyulee updated this revision to Diff 549714.Aug 13 2023, 10:14 AM

Update (simplify) tests per comments.

kyulee updated this revision to Diff 549716.Aug 13 2023, 10:21 AM

Update (simplify) tests per comments.

kyulee marked 3 inline comments as done.Aug 13 2023, 10:27 AM
int3 accepted this revision.Aug 13 2023, 12:44 PM

Thank you!

This revision is now accepted and ready to land.Aug 13 2023, 12:44 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 26 2023, 7:26 AM
thakis added inline comments.
lld/MachO/Driver.cpp
524

We have this contains check both here and in parseLCLinkerOption(). Do we need it in both places? Shouldn't just parseLCLinkerOption() be enough?

kyulee added inline comments.Sep 26 2023, 9:13 AM
lld/MachO/Driver.cpp
524

Thanks for catching this. I think it's left out while I'm refactoring the code.
I make a pull request -- https://github.com/llvm/llvm-project/pull/67450