Skip to content

Commit 1bebb28

Browse files
author
Nick Kledzik
committedSep 9, 2014
[mach-o] Add support for arm64 (AAarch64)
Most of the changes are in the new file ArchHandler_arm64.cpp. But a few things had to be fixed to support 16KB pages (instead of 4KB) which iOS arm64 requires. In addition the StubInfo struct had to be expanded because arm64 uses two instruction (ADRP/LDR) to load a global which requires two relocations. The other mach-o arches just needed one relocation. llvm-svn: 217469
1 parent d0f1037 commit 1bebb28

18 files changed

+1391
-26
lines changed
 

Diff for: ‎lld/include/lld/ReaderWriter/MachOLinkingContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MachOLinkingContext : public LinkingContext {
4343
arch_armv6,
4444
arch_armv7,
4545
arch_armv7s,
46+
arch_arm64,
4647
};
4748

4849
enum class OS {

Diff for: ‎lld/lib/ReaderWriter/MachO/ArchHandler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ std::unique_ptr<mach_o::ArchHandler> ArchHandler::create(
4242
case MachOLinkingContext::arch_armv7:
4343
case MachOLinkingContext::arch_armv7s:
4444
return create_arm();
45+
case MachOLinkingContext::arch_arm64:
46+
return create_arm64();
4547
default:
4648
llvm_unreachable("Unknown arch");
4749
}

Diff for: ‎lld/lib/ReaderWriter/MachO/ArchHandler.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ class ArchHandler {
174174
int32_t addend;
175175
};
176176

177+
struct OptionalRefInfo {
178+
bool used;
179+
uint16_t kind;
180+
uint32_t offset;
181+
int32_t addend;
182+
};
183+
177184
/// Table of architecture specific information for creating stubs.
178185
struct StubInfo {
179186
const char* binderSymbolName;
@@ -185,16 +192,19 @@ class ArchHandler {
185192
uint32_t stubSize;
186193
uint8_t stubBytes[16];
187194
ReferenceInfo stubReferenceToLP;
188-
195+
OptionalRefInfo optStubReferenceToLP;
196+
189197
uint32_t stubHelperSize;
190198
uint8_t stubHelperBytes[16];
191199
ReferenceInfo stubHelperReferenceToImm;
192200
ReferenceInfo stubHelperReferenceToHelperCommon;
193-
201+
194202
uint32_t stubHelperCommonSize;
195203
uint8_t stubHelperCommonBytes[36];
196204
ReferenceInfo stubHelperCommonReferenceToCache;
205+
OptionalRefInfo optStubHelperCommonReferenceToCache;
197206
ReferenceInfo stubHelperCommonReferenceToBinder;
207+
OptionalRefInfo optStubHelperCommonReferenceToBinder;
198208
};
199209

200210
virtual const StubInfo &stubInfo() = 0;
@@ -205,6 +215,7 @@ class ArchHandler {
205215
static std::unique_ptr<mach_o::ArchHandler> create_x86_64();
206216
static std::unique_ptr<mach_o::ArchHandler> create_x86();
207217
static std::unique_ptr<mach_o::ArchHandler> create_arm();
218+
static std::unique_ptr<mach_o::ArchHandler> create_arm64();
208219

209220
// Handy way to pack mach-o r_type and other bit fields into one 16-bit value.
210221
typedef uint16_t RelocPattern;

Diff for: ‎lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const ArchHandler::StubInfo ArchHandler_arm::_sStubInfoArmPIC = {
208208
0x00, 0xF0, 0x9C, 0xE5, // ldr pc, [ip]
209209
0x00, 0x00, 0x00, 0x00 }, // .long L_foo$lazy_ptr - (L1$scv + 8)
210210
{ Reference::KindArch::ARM, delta32, 12, 0 },
211+
{ false, 0, 0, 0 },
211212

212213
// Stub Helper size and code
213214
12,
@@ -232,7 +233,9 @@ const ArchHandler::StubInfo ArchHandler_arm::_sStubInfoArmPIC = {
232233
0x00, 0x00, 0x00, 0x00, // L1: .long fFastStubGOTAtom - (helper+16)
233234
0x00, 0x00, 0x00, 0x00 }, // L2: .long dyld_stub_binder - (helper+28)
234235
{ Reference::KindArch::ARM, delta32, 28, 0xC },
235-
{ Reference::KindArch::ARM, delta32, 32, 0x04 }
236+
{ false, 0, 0, 0 },
237+
{ Reference::KindArch::ARM, delta32, 32, 0x04 },
238+
{ false, 0, 0, 0 }
236239
};
237240

238241
const ArchHandler::StubInfo &ArchHandler_arm::stubInfo() {

0 commit comments

Comments
 (0)
Please sign in to comment.