This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Add support for arm64_32
ClosedPublic

Authored by int3 on Apr 2 2021, 4:54 PM.

Details

Summary

From what I can tell, it's pretty similar to arm64. The two main differences
are:

  1. No 64-bit relocations
  2. Stub code writes to 32-bit registers instead of 64-bit

Plus of course the various on-disk structures like segment_command are using
the 32-bit instead of the 64-bit variants.

Diff Detail

Event Timeline

int3 created this revision.Apr 2 2021, 4:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2021, 4:54 PM
int3 requested review of this revision.Apr 2 2021, 4:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2021, 4:54 PM

Does ARMCommon need to inherit from TargetInfo? Can ARM64 inherit from ARMCommon and TargetInfo? Multiple inheritance is a bit hacky.

int3 added a comment.Apr 3 2021, 2:14 PM

Can ARM64 inherit from ARMCommon and TargetInfo? Multiple inheritance is a bit hacky.

You mean multiple *levels* of inheritance is hacky, right? Multiple inheritance seems to be what you are describing -- having ARM64 inherit from two direct parent classes. But I think having ARM64Common inherit directly from TargetInfo makes sense since it's implementing some of TargetInfo's virtual methods...

No. Inheriting from multiple Classes.

struct ARM64: TargetInfo, ARMCommon {
...
}

But if ARMCommon already implements parts of TargetInfo, then it is fine.

int3 updated this revision to Diff 335657.Apr 6 2021, 2:03 PM

fix UBSAN alignment issues

gkm added a subscriber: gkm.Apr 12 2021, 7:49 PM
gkm added inline comments.
lld/MachO/Arch/ARM64.cpp
79
lld/MachO/Arch/ARM64_32.cpp
33
48
78
lld/MachO/MachOStructs.h
40

Will we be making endian-aware structs here also? E.g., all of the code signing headers are little-endian.

lld/test/MachO/arm64-32-stubs.s
4–6

Unifying this one seems within reach:

  • omit the "literal pool symbol address" comments
  • either ...
    • match {{[wx]}}16 or
    • define a FileCheck macro with the proper register name
lld/test/MachO/lit.local.cfg
19

Perhaps rename this as %lld-macos in a separate diff?

lld/test/MachO/segments.s
58–59

Why add {{.*}} here and elsewhere? To emphasize that there is more on the line?

int3 added inline comments.Apr 12 2021, 8:04 PM
lld/MachO/MachOStructs.h
40

The endianness is secondary; the main motivation here is to avoid misaligned read/write warnings from UBSAN. These wrapper structs should compile down to memcpy calls that get elided on architectures supporting unaligned reads (like x86_64).

lld/test/MachO/arm64-32-stubs.s
4–6

I think the 'literal pool symbol address' comments are useful though -- they verify that the instructions are actually referring to the right pointers. That (unfortunately) isn't being checked in the arm64-32 test.

lld/test/MachO/lit.local.cfg
19

eh, I think the RUN: lines are too long already as-is...

lld/test/MachO/segments.s
58–59

I added --match-full-lines to the FileCheck invocation in order to properly distinguish between LC_SEGMENT and LC_SEGMENT_64. But that also required adding {{.*}} here so this line would continue to match. Maybe it'll be cleaner to just add {{$}} to the LC_SEGMENT lines...

int3 updated this revision to Diff 337031.Apr 12 2021, 8:09 PM
int3 marked 5 inline comments as done.

update

int3 updated this revision to Diff 337034.Apr 12 2021, 8:15 PM

more {{$}}

gkm accepted this revision.Apr 12 2021, 8:21 PM

LGTM

lld/test/MachO/arm64-32-stubs.s
4–6

File a bug for llvm-objdump then.

This revision is now accepted and ready to land.Apr 12 2021, 8:21 PM
int3 marked an inline comment as done.Apr 12 2021, 8:51 PM
int3 added inline comments.
lld/test/MachO/arm64-32-stubs.s
4–6
int3 updated this revision to Diff 337036.Apr 12 2021, 9:03 PM
int3 marked an inline comment as done.

reference task number

This revision was landed with ongoing or failed builds.Apr 13 2021, 7:44 AM
This revision was automatically updated to reflect the committed changes.

It looks like this broke the Windows LLDB bot (which also builds lld):

https://lab.llvm.org/buildbot/#/builders/83/builds/5593

As far as I can tell, there's no currently running Windows LLD bot, so the LLDB bot is the only one to build this on Windows.

int3 added a comment.Apr 13 2021, 9:40 AM

Internal compiler error... that's fun :/ Reverting now, one sec

thakis added a subscriber: thakis.Apr 13 2021, 11:03 AM

The _revert_ of this seems to break tests: http://45.33.8.238/linux/44021/step_11.txt