This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][MachO] Support LC_LINKER_OPTIMIZATION_HINT load command
ClosedPublic

Authored by MaskRay on Jun 25 2021, 8:44 PM.

Details

Summary

The load command is currently specific to arm64 and holds information
for instruction rewriting, e.g. converting a GOT load to an ADR to
compute a local address.
(On ELF the information is usually conveyed by relocations, e.g.
R_X86_64_REX_GOTPCRELX, R_PPC64_TOC16_HA)

Diff Detail

Event Timeline

MaskRay created this revision.Jun 25 2021, 8:44 PM
MaskRay requested review of this revision.Jun 25 2021, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 25 2021, 8:44 PM

Regarding tests:

loh.s:

.text
.align 2
_test:
L1:   adrp  x0, _foo@PAGE
L2:   add   x0, x0, _foo@PAGEOFF
.loh AdrpAdd L1, L2

.data
_foo: .long 0

llvm-mc -filetype=obj -triple=arm64-apple-darwin loh.s -o loh.o

llvm-objdump --macho --link-opt-hints loh.o
will print them.

Unfortunately, at the moment ObjectYAML doesn't support linker optimization hints (see MachOYAML.h, struct LinkEditData),
so ideally it'd be good to extend ObjectYAML (it should be similar to other things living inside LinkEdit),
alternatively, one can create a test using assembly & llvm-mc.

MaskRay updated this revision to Diff 354759.Jun 27 2021, 10:44 AM

Thanks for the example!

Added a test

This revision is now accepted and ready to land.Jun 28 2021, 9:42 PM
llvm/tools/llvm-objcopy/MachO/MachOReader.cpp
335

nit: to hide these details one can introduce readLinkerOptimizationHints
(similarly to readDataInCode, readFunctionStartsData etc)
which would call this helper method (readLinkData) with the right arguments:

void MachOReader::readLinkerOptimizationHints(Object &Obj) {
    return readLinkData(*Obj, Obj->LinkerOptimizationHintCommandIndex, 
                                     Obj->LinkerOptimizationHint);
}
MaskRay updated this revision to Diff 355421.Jun 29 2021, 6:47 PM
MaskRay marked an inline comment as done.
MaskRay retitled this revision from [llvm-objcopy][MachO] Support LINKER_OPTIMIZATION_HINT to [llvm-objcopy][MachO] Support LC_LINKER_OPTIMIZATION_HINT load command.
MaskRay edited the summary of this revision. (Show Details)

comment

This revision was landed with ongoing or failed builds.Jun 29 2021, 6:48 PM
This revision was automatically updated to reflect the committed changes.