This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho][NFC] Minor refactor of Writer::run()
ClosedPublic

Authored by gkm on Mar 17 2021, 10:45 AM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rG74b888baaddc: [lld-macho][NFC] Minor refactor of Writer::run()
Summary

Move some functions closer to their uses. Move detailed address-assignment logic out of the otherwise abstract Writer::run(). This prepares the ground for a diff to implement branch range extension thunks.

  • SyntheticSections.cpp
    • move needsBinding() and prepareBranchTarget() into Writer.cpp
    • move addNonLazyBindingEntries() adjacent to its use.
  • Writer.cpp
    • move address-assignment logic from Writer::run() into new function Writer::assignAddresses()
    • move needsBinding() and prepareBranchTarget() from SyntheticSections.cpp
  • Target.h
    • remove orphaned decls of prepareSymbolRelocation() and validateRelocationInfo() which were moved to other files in earlier diffs.

Diff Detail

Event Timeline

gkm created this revision.Mar 17 2021, 10:45 AM
Herald added a project: Restricted Project. · View Herald Transcript
gkm requested review of this revision.Mar 17 2021, 10:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2021, 10:45 AM
gkm updated this revision to Diff 331321.Mar 17 2021, 10:57 AM
  • Now that addNonLazyBindingEntries() resides in Writer.cpp, also move its decl to Writer.h
int3 added inline comments.Mar 17 2021, 1:19 PM
lld/MachO/Writer.cpp
450

nit: extra line

475

ditto

858–859

This comment seems worth keeping

866

This function feels misleadingly named. Also I'm not sure why we need to put all the finalizeContents() calls together with the address assignment loop. Can we make linkEditSegment a member of Writer and then split all the finalizeContents() calls into a separate finalizeLinkEdit()?

gkm marked 4 inline comments as done.Mar 17 2021, 2:34 PM
gkm added inline comments.
lld/MachO/Writer.cpp
858–859

OK for now ... until BRET (branch-range-extension thunks) creates more sections after this point during address assignment. ;)

gkm updated this revision to Diff 331379.Mar 17 2021, 2:37 PM
gkm marked an inline comment as done.
  • revise according to review feedback
int3 accepted this revision.Mar 17 2021, 2:45 PM
int3 added inline comments.
lld/MachO/Writer.cpp
858–859

hmm... "No more segments or sections (aside from branch range extension thunks) may be created after this point"?

867–868

move this back to where it originally was (at the start of Writer::run()) so the "No more sections nor segments may be created after these methods run" comment holds true?

This revision is now accepted and ready to land.Mar 17 2021, 2:45 PM
gkm updated this revision to Diff 331383.Mar 17 2021, 2:53 PM
  • resolve clang-tidy complaints
gkm updated this revision to Diff 331390.Mar 17 2021, 3:07 PM
gkm marked 2 inline comments as done.
  • revise according to review feedback
This revision was landed with ongoing or failed builds.Mar 17 2021, 3:16 PM
This revision was automatically updated to reflect the committed changes.