Skip to content

Commit

Permalink
[mach-o] Add support for arm64 (AAarch64)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Nick Kledzik committed Sep 9, 2014
1 parent d0f1037 commit 1bebb28
Show file tree
Hide file tree
Showing 18 changed files with 1,391 additions and 26 deletions.
1 change: 1 addition & 0 deletions lld/include/lld/ReaderWriter/MachOLinkingContext.h
Expand Up @@ -43,6 +43,7 @@ class MachOLinkingContext : public LinkingContext {
arch_armv6,
arch_armv7,
arch_armv7s,
arch_arm64,
};

enum class OS {
Expand Down
2 changes: 2 additions & 0 deletions lld/lib/ReaderWriter/MachO/ArchHandler.cpp
Expand Up @@ -42,6 +42,8 @@ std::unique_ptr<mach_o::ArchHandler> ArchHandler::create(
case MachOLinkingContext::arch_armv7:
case MachOLinkingContext::arch_armv7s:
return create_arm();
case MachOLinkingContext::arch_arm64:
return create_arm64();
default:
llvm_unreachable("Unknown arch");
}
Expand Down
15 changes: 13 additions & 2 deletions lld/lib/ReaderWriter/MachO/ArchHandler.h
Expand Up @@ -174,6 +174,13 @@ class ArchHandler {
int32_t addend;
};

struct OptionalRefInfo {
bool used;
uint16_t kind;
uint32_t offset;
int32_t addend;
};

/// Table of architecture specific information for creating stubs.
struct StubInfo {
const char* binderSymbolName;
Expand All @@ -185,16 +192,19 @@ class ArchHandler {
uint32_t stubSize;
uint8_t stubBytes[16];
ReferenceInfo stubReferenceToLP;

OptionalRefInfo optStubReferenceToLP;

uint32_t stubHelperSize;
uint8_t stubHelperBytes[16];
ReferenceInfo stubHelperReferenceToImm;
ReferenceInfo stubHelperReferenceToHelperCommon;

uint32_t stubHelperCommonSize;
uint8_t stubHelperCommonBytes[36];
ReferenceInfo stubHelperCommonReferenceToCache;
OptionalRefInfo optStubHelperCommonReferenceToCache;
ReferenceInfo stubHelperCommonReferenceToBinder;
OptionalRefInfo optStubHelperCommonReferenceToBinder;
};

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

// Handy way to pack mach-o r_type and other bit fields into one 16-bit value.
typedef uint16_t RelocPattern;
Expand Down
5 changes: 4 additions & 1 deletion lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
Expand Up @@ -208,6 +208,7 @@ const ArchHandler::StubInfo ArchHandler_arm::_sStubInfoArmPIC = {
0x00, 0xF0, 0x9C, 0xE5, // ldr pc, [ip]
0x00, 0x00, 0x00, 0x00 }, // .long L_foo$lazy_ptr - (L1$scv + 8)
{ Reference::KindArch::ARM, delta32, 12, 0 },
{ false, 0, 0, 0 },

// Stub Helper size and code
12,
Expand All @@ -232,7 +233,9 @@ const ArchHandler::StubInfo ArchHandler_arm::_sStubInfoArmPIC = {
0x00, 0x00, 0x00, 0x00, // L1: .long fFastStubGOTAtom - (helper+16)
0x00, 0x00, 0x00, 0x00 }, // L2: .long dyld_stub_binder - (helper+28)
{ Reference::KindArch::ARM, delta32, 28, 0xC },
{ Reference::KindArch::ARM, delta32, 32, 0x04 }
{ false, 0, 0, 0 },
{ Reference::KindArch::ARM, delta32, 32, 0x04 },
{ false, 0, 0, 0 }
};

const ArchHandler::StubInfo &ArchHandler_arm::stubInfo() {
Expand Down

0 comments on commit 1bebb28

Please sign in to comment.