This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Move adding bindings for stub targets out of Writer (NFC)
ClosedPublic

Authored by BertalanD on Aug 23 2022, 8:25 AM.

Details

Summary

We now re-use the existing needsBinding() helper to determine if a
branch has to go through a stub. The logic for determining which type of
binding is needed can now be done inside StubsSection::addEntry().

This commit prepares us for adding chained fixups support, which will
complicate the logic for adding binding entries.

Diff Detail

Event Timeline

BertalanD created this revision.Aug 23 2022, 8:25 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 23 2022, 8:25 AM
BertalanD requested review of this revision.Aug 23 2022, 8:25 AM
int3 added a subscriber: int3.Aug 23 2022, 9:24 AM

Would be nice to review this together with the stacked chained fixups diff, for context :)

lld/MachO/SyntheticSections.cpp
680

I think we can add an else { llvm_unreachable(...) } here

thakis added a subscriber: thakis.Aug 23 2022, 11:41 AM

Would be nice to review this together with the stacked chained fixups diff, for context :)

See here: https://github.com/BertalanD/llvm-project/commits/chained-fixups

int3 accepted this revision.Aug 24 2022, 8:43 AM

Kinda wish we didn't have to repeat the checks for symbol type / symbol properties in prepareBranchTarget and the stubs addEntry method, but I can't see a way around it

lld/MachO/Writer.cpp
577–578

how do you feel about replacing this with a bool branchTargetNeedsStubs() method, then have its callers call stubs->addEntry themselves? IMO it makes it clearer that the logic in this function is now solely about deciding whether to do something, rather than how it should be done

This revision is now accepted and ready to land.Aug 24 2022, 8:43 AM
int3 added inline comments.Aug 24 2022, 8:55 AM
lld/MachO/Writer.cpp
1133–1135

if we go the branchTargetNeedsStubs() route, I would remove the llvm_unreachable() assert in it and then we wouldn't have to check for isa<Undefined> here

BertalanD added inline comments.Aug 24 2022, 11:11 AM
lld/MachO/Writer.cpp
577–578

That's a good idea, I agree that it would make the logic clearer.

Actually, it looks like the logic of branchTargetNeedsStubs() would be identical to needsBinding(), so we can do away with this function altogether.

BertalanD retitled this revision from [lld-macho] Split stub creation and adding binding entries (NFC) to [lld-macho] Move adding bindings for stub targets out of Writer (NFC).
BertalanD edited the summary of this revision. (Show Details)

Call in.stubs->addEntry() directly, and use needsBinding() to check if a stub is needed.

int3 added a comment.Aug 24 2022, 6:19 PM

Oh yeah I forgot about needsBinding(). Thanks!

BertalanD updated this revision to Diff 455513.Aug 25 2022, 2:29 AM

Updated StubsSection::addEntry() comment.

thakis accepted this revision.Aug 25 2022, 4:36 AM

Nice!

Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 8:37 AM