This is an archive of the discontinued LLVM Phabricator instance.

[MC][MachO] Change addrsig format + ensure its size is properly set
ClosedPublic

Authored by int3 on Jun 13 2022, 6:21 AM.

Details

Summary

There were two problems with the previous setup:

  1. We weren't setting its size, which caused problems when __llvm_addrsig wasn't the last section. In particular, __debug_line (if created) is generated and placed after __llvm_addrsig, and would result in an invalid object file w/ overlapping sections being emitted.
  1. The symbol indices could be invalidated if e.g. llvm-strip ran on the object file. See discussion [here][1].

To fix both these issues, we use symbol relocations instead of encoding
symbol indices directly in the section contents. The section itself
doesn't contain any data. That sidesteps the layout problem in addition
to solving the second issue.

The corresponding LLD change to read in this new format: D128938: [lld-macho] Read in new addrsig format.
It will fix the icf-safe.ll test failure on this diff.

[1]: https://discourse.llvm.org/t/problems-with-mach-o-address-significance-table-generation/63392/

Diff Detail

Event Timeline

int3 created this revision.Jun 13 2022, 6:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 6:21 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
int3 requested review of this revision.Jun 13 2022, 6:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 6:21 AM
int3 edited the summary of this revision. (Show Details)Jun 13 2022, 6:24 AM
int3 added inline comments.Jun 13 2022, 6:24 AM
llvm/test/CodeGen/AArch64/addrsig-macho.ll
91–93

@alx32: What's the purpose of these calls to dbg.value? What does it help us test?

int3 planned changes to this revision.Jun 13 2022, 6:28 AM
int3 updated this revision to Diff 441479.Jun 30 2022, 12:12 PM
int3 retitled this revision from [MC] Ensure addrsig's section size is properly set to [MC][MachO] Change addrsig format + ensure its size is properly set.
int3 edited the summary of this revision. (Show Details)

new approach

int3 updated this revision to Diff 441493.Jun 30 2022, 12:49 PM

use pointer sized relocs

int3 edited the summary of this revision. (Show Details)Jun 30 2022, 12:49 PM
int3 edited the summary of this revision. (Show Details)Jun 30 2022, 1:41 PM
int3 added inline comments.Jul 5 2022, 2:17 PM
llvm/lib/MC/MCMachOStreamer.cpp
608

could use the actual machine pointer size here, but I'm not sure how to check for 64/32 bit elegantly here. MCMachObjectTargetWriter::is64Bit() exists, but that would require downcasting writer here which seems kinda ugly

LGTM in general. Some comments inline.

llvm/lib/MC/MCMachOStreamer.cpp
34

This is no longer needed.

608

You can just add is64Bit() to MachObjectWriter which just return TargetObjectWriter->is64Bit().

int3 added inline comments.Jul 12 2022, 12:31 AM
llvm/lib/MC/MCMachOStreamer.cpp
608

Not sure I understand this. MachObjectWriter::is64Bit() already exists; the problem is that I don't seem to have access to MachObjectWriter here without doing a static_cast on writer.

(I know I said MCMachObjectTargetWriter instead of MachObjectWriter in my earlier comment, but I mixed the two up. Regardless they both have an is64Bit method.

int3 updated this revision to Diff 443844.Jul 12 2022, 12:32 AM

remove unnecessary include

int3 added a comment.Jul 15 2022, 12:27 PM

bump. I don't know if there's a simple solution to the is64Bit question, but I don't think it's super important either? At most we're just allocating an additional 4 bytes

alx32 accepted this revision.Jul 19 2022, 10:25 AM

LGTM, thanks for doing this !

This revision is now accepted and ready to land.Jul 19 2022, 10:25 AM
This revision was landed with ongoing or failed builds.Jul 19 2022, 6:22 PM
This revision was automatically updated to reflect the committed changes.