This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Emit REBASE_OPCODE_ADD_ADDR_IMM_SCALED if possible
ClosedPublic

Authored by BertalanD on Jun 29 2022, 2:56 AM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rG8d29f0fdb9c6: [lld-macho] Emit REBASE_OPCODE_ADD_ADDR_IMM_SCALED if possible
Summary

An ADD_ADDR rebase opcode's argument can be encoded as an immediate if
the offset is less than 15 * word size. This change reduces the size of
chromium_framework by 100+ KiB.

Diff Detail

Event Timeline

BertalanD created this revision.Jun 29 2022, 2:56 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 29 2022, 2:56 AM
BertalanD requested review of this revision.Jun 29 2022, 2:56 AM
int3 added a subscriber: int3.Jun 29 2022, 10:30 AM

can we have a test for this? obj2yaml dumps out the exact opcodes used, so we can check using that. See e.g. bind-opcodes.s

BertalanD edited the summary of this revision. (Show Details)Jun 29 2022, 10:38 AM

Added a test.

int3 accepted this revision.Jun 29 2022, 11:33 AM

Thanks!

lld/MachO/SyntheticSections.cpp
209–210

micro-opt suggestion: div/mod instructions are relatively expensive, so writing this in terms of target->p2WordSize would probably be more efficient. just a suggestion for a future diff, I think we have a bunch of other places in the code that could be similarly changed

lld/test/MachO/rebase-opcodes.s
4 ↗(On Diff #441098)

just wondering, any reason you pick arm64? nothing wrong with that of course, but %lld defaults to -arch x86_64, so this is an extra flag that you're having to pass

This revision is now accepted and ready to land.Jun 29 2022, 11:33 AM
BertalanD added inline comments.Jun 29 2022, 12:43 PM
lld/test/MachO/rebase-opcodes.s
4 ↗(On Diff #441098)

There wasn't any particular reason other than the fact I'm developing on an ARM Mac. I'll push the commit with the arch changed to x86.

Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 1:29 PM