This is an archive of the discontinued LLVM Phabricator instance.

[AsmPrinter] Use linker-private symbols in xray_instr_map
AbandonedPublic

Authored by MaskRay on Mar 11 2023, 8:03 AM.

Details

Summary

When compiling with -fxray-instrument for Apple platforms, XRay pass
generates relocation entries that offend Mach-O linker on x86_64.

All emitted entries in xray_instr_map use local labels, so the entire
section ends up filled with local (r_extern=0) relocations, which is
not allowed on x86_64 in Mach-O.

The linker is able to figure it out as long as there is at least one
external relocation in the section, making all local relocations
piggyback on the external one before them. Indulge the linker with
some "private" symbols, which are considered external for relocation
purposes, but are otherwise local to object files (i.e., "static",
do not get globally exported and are generally removed after linking).

Depends on D145291

Diff Detail

Event Timeline

ilammy created this revision.Mar 11 2023, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2023, 8:03 AM
ilammy requested review of this revision.Mar 11 2023, 8:03 AM
ilammy updated this revision to Diff 530286.Jun 11 2023, 12:33 AM
  • Rebased on top of updated dependent revisions
MaskRay added a comment.EditedJun 11 2023, 3:47 PM

xray_fn_idx entries should use PC-relative relocations as well, but I never get around to fix it. I wonder whether the change may make this patch unneeded or we are going to find other Mach-O relocation related issues.


All emitted entries in xray_instr_map use local labels, so the entire section ends up filled with local (r_extern=0) relocations, which is not allowed on x86_64 in Mach-O.

I wondered why clang --target=arm64-apple-darwin -fxray-instrument -fxray-instruction-threshold=1 a.c works while -S then -c a.o reported an assembler report.
The issue seems to be related to an ancient ld64 workaround done in 2015: d6223a24718df3c30b67422c2eb6d0e93af9c4e8

xray_fn_idx entries should use PC-relative relocations as well, but I never get around to fix it. I wonder whether the change may make this patch unneeded or we are going to find other Mach-O relocation related issues.

Created D152661. I wonder whether it bypasses some ld64 limitations.

MaskRay commandeered this revision.Aug 30 2023, 11:10 PM
MaskRay edited reviewers, added: ilammy; removed: MaskRay.

I think codegen works not but cmake still needs work:)

MaskRay abandoned this revision.Aug 30 2023, 11:11 PM