This is an archive of the discontinued LLVM Phabricator instance.

[XRay] Make xray_instr_map compatible with Mach-O
ClosedPublic

Authored by MaskRay on Jun 18 2023, 9:18 PM.

Details

Summary

The __DATA,xray_instr_map section has label differences like
.quad Lxray_sled_0-Ltmp0 that is represented as a pair of UNSIGNED and SUBTRACTOR relocations.

LLVM integrated assembler attempts to rewrite A-B into A-B'+offset where B' can
be included in the symbol table. B' is called an atom and should be a
non-temporary symbol in the same section. However, since xray_instr_map does
not define a non-temporary symbol, the SUBTRACTO relocation will have no
associated symbol, and its r_extern value will be 0. Therefore, we will see
linker errors like:

error: SUBTRACTOR relocation must be extern at offset 0 of __DATA,xray_instr_map in a.o

To fix this issue, we need to define a non-temporary symbol in the section. We
can accomplish this by renaming Lxray_sleds_start0 to lxray_sleds_start0
("L" to "l").

lxray_sleds_start0 serves as the atom for this dead-strippable subsection.
With the S_ATTR_LIVE_SUPPORT attribute, ld -dead_strip will retain
subsections that reference live functions.

Special thanks to Oleksii Lozovskyi for reporting the issue and providing
initial analysis.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 18 2023, 9:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 9:18 PM
MaskRay requested review of this revision.Jun 18 2023, 9:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 9:18 PM
MaskRay updated this revision to Diff 533133.Jun 20 2023, 10:45 PM
MaskRay edited the summary of this revision. (Show Details)

rebase
thanks to Oleksii Lozovskyi

MaskRay accepted this revision.Jun 22 2023, 12:19 AM

I'll wait a bit and land this. I have pushed some test cleanup few days ago to make test updates less painful.

This revision is now accepted and ready to land.Jun 22 2023, 12:19 AM
This revision was landed with ongoing or failed builds.Jun 22 2023, 10:03 AM
This revision was automatically updated to reflect the committed changes.