diff --git a/lld/MachO/Arch/ARM.cpp b/lld/MachO/Arch/ARM.cpp deleted file mode 100644 --- a/lld/MachO/Arch/ARM.cpp +++ /dev/null @@ -1,214 +0,0 @@ -//===- ARM.cpp ------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "InputFiles.h" -#include "Symbols.h" -#include "SyntheticSections.h" -#include "Target.h" - -#include "lld/Common/ErrorHandler.h" -#include "llvm/ADT/Bitfields.h" -#include "llvm/BinaryFormat/MachO.h" -#include "llvm/Support/Endian.h" - -using namespace llvm; -using namespace llvm::MachO; -using namespace llvm::support::endian; -using namespace lld; -using namespace lld::macho; - -namespace { - -struct ARM : TargetInfo { - ARM(uint32_t cpuSubtype); - - int64_t getEmbeddedAddend(MemoryBufferRef, uint64_t offset, - const relocation_info) const override; - void relocateOne(uint8_t *loc, const Reloc &, uint64_t va, - uint64_t pc) const override; - - void writeStub(uint8_t *buf, const Symbol &, uint64_t) const override; - void writeStubHelperHeader(uint8_t *buf) const override; - void writeStubHelperEntry(uint8_t *buf, const Symbol &, - uint64_t entryAddr) const override; - - void writeObjCMsgSendStub(uint8_t *buf, Symbol *sym, uint64_t stubsAddr, - uint64_t stubOffset, uint64_t selrefsVA, - uint64_t selectorIndex, uint64_t gotAddr, - uint64_t msgSendIndex) const override; - - void relaxGotLoad(uint8_t *loc, uint8_t type) const override; - uint64_t getPageSize() const override { return 4 * 1024; } - - void handleDtraceReloc(const Symbol *sym, const Reloc &r, - uint8_t *loc) const override; -}; -} // namespace - -static constexpr std::array relocAttrsArray{{ -#define B(x) RelocAttrBits::x - {"VANILLA", /* FIXME populate this */ B(_0)}, - {"PAIR", /* FIXME populate this */ B(_0)}, - {"SECTDIFF", /* FIXME populate this */ B(_0)}, - {"LOCAL_SECTDIFF", /* FIXME populate this */ B(_0)}, - {"PB_LA_PTR", /* FIXME populate this */ B(_0)}, - {"BR24", B(PCREL) | B(LOCAL) | B(EXTERN) | B(BRANCH) | B(BYTE4)}, - {"BR22", B(PCREL) | B(LOCAL) | B(EXTERN) | B(BRANCH) | B(BYTE4)}, - {"32BIT_BRANCH", /* FIXME populate this */ B(_0)}, - {"HALF", /* FIXME populate this */ B(_0)}, - {"HALF_SECTDIFF", /* FIXME populate this */ B(_0)}, -#undef B -}}; - -int64_t ARM::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset, - relocation_info rel) const { - // FIXME: implement this - return 0; -} - -template using BitfieldFlag = Bitfield::Element; - -// ARM BL encoding: -// -// 30 28 24 0 -// +---------+---------+----------------------------------------------+ -// | cond | 1 0 1 1 | imm24 | -// +---------+---------+----------------------------------------------+ -// -// `cond` here varies depending on whether we have bleq, blne, etc. -// `imm24` encodes a 26-bit pcrel offset -- last 2 bits are zero as ARM -// functions are 4-byte-aligned. -// -// ARM BLX encoding: -// -// 30 28 24 0 -// +---------+---------+----------------------------------------------+ -// | 1 1 1 1 | 1 0 1 H | imm24 | -// +---------+---------+----------------------------------------------+ -// -// Since Thumb functions are 2-byte-aligned, we need one extra bit to encode -// the offset -- that is the H bit. -// -// BLX is always unconditional, so while we can convert directly from BLX to BL, -// we need to insert a shim if a BL's target is a Thumb function. -// -// Helper aliases for decoding BL / BLX: -using Cond = Bitfield::Element; -using Imm24 = Bitfield::Element; - -void ARM::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value, - uint64_t pc) const { - switch (r.type) { - case ARM_RELOC_BR24: { - uint32_t base = read32le(loc); - bool isBlx = Bitfield::get(base) == 0xf; - const Symbol *sym = r.referent.get(); - int32_t offset = value - (pc + 8); - - if (auto *defined = dyn_cast(sym)) { - if (!isBlx && defined->thumb) { - error("TODO: implement interworking shim"); - return; - } else if (isBlx && !defined->thumb) { - Bitfield::set(base, 0xe); // unconditional BL - Bitfield::set>(base, true); - isBlx = false; - } - } else { - error("TODO: Implement ARM_RELOC_BR24 for dylib symbols"); - return; - } - - if (isBlx) { - assert((0x1 & value) == 0); - Bitfield::set(base, offset >> 2); - Bitfield::set>(base, (offset >> 1) & 1); // H bit - } else { - assert((0x3 & value) == 0); - Bitfield::set(base, offset >> 2); - } - write32le(loc, base); - break; - } - default: - fatal("unhandled relocation type"); - } -} - -void ARM::writeStub(uint8_t *buf, const Symbol &sym, uint64_t) const { - fatal("TODO: implement this"); -} - -void ARM::writeStubHelperHeader(uint8_t *buf) const { - fatal("TODO: implement this"); -} - -void ARM::writeStubHelperEntry(uint8_t *buf, const Symbol &sym, - uint64_t entryAddr) const { - fatal("TODO: implement this"); -} - -void ARM::writeObjCMsgSendStub(uint8_t *buf, Symbol *sym, uint64_t stubsAddr, - uint64_t stubOffset, uint64_t selrefsVA, - uint64_t selectorIndex, uint64_t gotAddr, - uint64_t msgSendIndex) const { - fatal("TODO: implement this"); -} - -void ARM::relaxGotLoad(uint8_t *loc, uint8_t type) const { - fatal("TODO: implement this"); -} - -ARM::ARM(uint32_t cpuSubtype) : TargetInfo(ILP32()) { - cpuType = CPU_TYPE_ARM; - this->cpuSubtype = cpuSubtype; - - stubSize = 0 /* FIXME */; - stubHelperHeaderSize = 0 /* FIXME */; - stubHelperEntrySize = 0 /* FIXME */; - - relocAttrs = {relocAttrsArray.data(), relocAttrsArray.size()}; -} - -TargetInfo *macho::createARMTargetInfo(uint32_t cpuSubtype) { - static ARM t(cpuSubtype); - return &t; -} - -void ARM::handleDtraceReloc(const Symbol *sym, const Reloc &r, - uint8_t *loc) const { - if (config->outputType == MH_OBJECT) - return; - - switch (r.type) { - case ARM_RELOC_BR24: - if (sym->getName().startswith("___dtrace_probe")) { - // change call site to a NOP - write32le(loc, 0xE1A00000); - } else if (sym->getName().startswith("___dtrace_isenabled")) { - // change call site to 'eor r0, r0, r0' - write32le(loc, 0xE0200000); - } else { - error("Unrecognized dtrace symbol prefix: " + toString(*sym)); - } - break; - case ARM_THUMB_RELOC_BR22: - if (sym->getName().startswith("___dtrace_probe")) { - // change 32-bit blx call site to two thumb NOPs - write32le(loc, 0x46C046C0); - } else if (sym->getName().startswith("___dtrace_isenabled")) { - // change 32-bit blx call site to 'nop', 'eor r0, r0' - write32le(loc, 0x46C04040); - } else { - error("Unrecognized dtrace symbol prefix: " + toString(*sym)); - } - break; - default: - llvm_unreachable("Unsupported dtrace relocation type for ARM"); - } -} diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -5,7 +5,6 @@ include_directories(${LLVM_MAIN_SRC_DIR}/../libunwind/include) add_lld_library(lldMachO - Arch/ARM.cpp Arch/ARM64.cpp Arch/ARM64Common.cpp Arch/ARM64_32.cpp diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -752,8 +752,6 @@ return createARM64TargetInfo(); case CPU_TYPE_ARM64_32: return createARM64_32TargetInfo(); - case CPU_TYPE_ARM: - return createARMTargetInfo(cpuSubtype); default: error("missing or unsupported -arch " + archName); return nullptr; diff --git a/lld/MachO/Target.h b/lld/MachO/Target.h --- a/lld/MachO/Target.h +++ b/lld/MachO/Target.h @@ -145,7 +145,6 @@ TargetInfo *createX86_64TargetInfo(); TargetInfo *createARM64TargetInfo(); TargetInfo *createARM64_32TargetInfo(); -TargetInfo *createARMTargetInfo(uint32_t cpuSubtype); struct LP64 { using mach_header = llvm::MachO::mach_header_64; diff --git a/lld/test/MachO/arm-branch-relocs.s b/lld/test/MachO/arm-branch-relocs.s deleted file mode 100644 --- a/lld/test/MachO/arm-branch-relocs.s +++ /dev/null @@ -1,33 +0,0 @@ -# REQUIRES: arm -# RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %s -o %t.o -# RUN: %lld-watchos -dylib -arch armv7 -lSystem -o %t %t.o -# RUN: llvm-objdump --macho -d %t | FileCheck %s - -# CHECK: _arm: -# CHECK-NEXT: blx _thumb_1 -# CHECK-NEXT: blx _thumb_2 -# CHECK-NEXT: bl _arm -# CHECK-NEXT: bl _arm - -.globl _arm, _thumb_1, _thumb_2 -.syntax unified -.thumb_func _thumb_1 -.thumb_func _thumb_2 - -.p2align 2 - -.code 16 -## These two thumb functions are exactly 2 bytes apart in order to test that we -## set the H bit correctly in the BLX instruction. -_thumb_1: - nop - -_thumb_2: - nop - -.code 32 -_arm: - blx _thumb_1 - blx _thumb_2 - bl _arm - blx _arm diff --git a/lld/test/MachO/arm-dtrace.s b/lld/test/MachO/arm-dtrace.s deleted file mode 100644 --- a/lld/test/MachO/arm-dtrace.s +++ /dev/null @@ -1,47 +0,0 @@ -# REQUIRES: arm -# RUN: rm -rf %t; split-file %s %t - -# TODO: Replace %no-lsystem-lld with %lld - -# RUN: llvm-mc -filetype=obj -triple=armv4t-apple-darwin %t/armv4t-dtrace.s -o %t/armv4t-dtrace.o -# RUN: %no-lsystem-lld -arch armv4t -o %t/armv4t-dtrace %t/armv4t-dtrace.o - -## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions -# RUN: llvm-objdump --macho -D %t/armv4t-dtrace | FileCheck %s --check-prefix=CHECK-armv4t - -# CHECK-armv4t: 00 00 20 e0 eor r0, r0, r0 - -# CHECK-armv4t: 00 00 a0 e1 mov r0, r0 - -# RUN: llvm-mc -filetype=obj -triple=thumbv7-apple-darwin %t/armv7-dtrace.s -o %t/armv7-dtrace.o -# RUN: %no-lsystem-lld -arch armv7 -o %t/armv7-dtrace %t/armv7-dtrace.o - -## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions -# RUN: llvm-objdump --macho -D %t/armv7-dtrace | FileCheck %s --check-prefix=CHECK-armv7 - -# CHECK-armv7: 40 40 eors r0, r0 -# CHECK-armv7-NEXT: c0 46 mov r8, r8 - -# CHECK-armv7: c0 46 mov r8, r8 -# CHECK-armv7-NEXT: c0 46 mov r8, r8 - -;--- armv4t-dtrace.s - .globl _main -_main: - bl ___dtrace_isenabled$Foo$added$v1 - .reference ___dtrace_typedefs$Foo$v2 - bl ___dtrace_probe$Foo$added$v1$696e74 - .reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 - -.subsections_via_symbols - -;--- armv7-dtrace.s - .globl _main - .thumb_func _main -_main: - bl ___dtrace_isenabled$Foo$added$v1 - .reference ___dtrace_typedefs$Foo$v2 - bl ___dtrace_probe$Foo$added$v1$696e74 - .reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 - -.subsections_via_symbols diff --git a/lld/test/MachO/header.s b/lld/test/MachO/header.s --- a/lld/test/MachO/header.s +++ b/lld/test/MachO/header.s @@ -1,15 +1,13 @@ -# REQUIRES: x86, aarch64, arm +# REQUIRES: x86, aarch64 # RUN: rm -rf %t && mkdir -p %t # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/x86-64-test.o # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t/arm64-test.o # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %s -o %t/arm64-32-test.o # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos %s -o %t/arm64-32-test.o -# RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %s -o %t/arm-test.o # RUN: %lld -lSystem -arch x86_64 -o %t/x86-64-executable %t/x86-64-test.o # RUN: %lld -lSystem -arch arm64 -o %t/arm64-executable %t/arm64-test.o # RUN: %lld-watchos -lSystem -o %t/arm64-32-executable %t/arm64-32-test.o -# RUN: %lld-watchos -lSystem -arch armv7 -o %t/arm-executable %t/arm-test.o # RUN: %lld -arch x86_64 -dylib -o %t/x86-64-dylib %t/x86-64-test.o @@ -17,7 +15,6 @@ # RUN: llvm-objdump --macho --private-header %t/x86-64-executable | FileCheck %s --check-prefix=EXEC -DCPU=X86_64 -DSUBTYPE=ALL -DCAPS=LIB64 # RUN: llvm-objdump --macho --private-header %t/arm64-executable | FileCheck %s --check-prefix=EXEC -DCPU=ARM64 -DSUBTYPE=ALL -DCAPS=0x00 # RUN: llvm-objdump --macho --private-header %t/arm64-32-executable | FileCheck %s --check-prefix=EXEC -DCPU=ARM64_32 -DSUBTYPE=V8 -DCAPS=0x00 -# RUN: llvm-objdump --macho --private-header %t/arm-executable | FileCheck %s --check-prefix=EXEC -DCPU=ARM -DSUBTYPE=V7 -DCAPS=0x00 # RUN: llvm-objdump --macho --private-header %t/x86-64-dylib | FileCheck %s --check-prefix=DYLIB -DCPU=X86_64 -DSUBTYPE=ALL -DCAPS=0x00 diff --git a/lld/test/MachO/weak-def-thumb-conflict.s b/lld/test/MachO/weak-def-thumb-conflict.s deleted file mode 100644 --- a/lld/test/MachO/weak-def-thumb-conflict.s +++ /dev/null @@ -1,28 +0,0 @@ -# REQUIRES: arm -# RUN: rm -rf %t; split-file %s %t -# RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %t/thumb-foo.s -o %t/thumb-foo.o -# RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %t/arm-foo.s -o %t/arm-foo.o -# RUN: %lld-watchos -arch armv7 -dylib %t/arm-foo.o %t/thumb-foo.o -o %t/arm-foo -# RUN: %lld-watchos -arch armv7 -dylib %t/thumb-foo.o %t/arm-foo.o -o %t/thumb-foo -# RUN: llvm-nm -m %t/arm-foo | FileCheck %s --check-prefix=ARM -# RUN: llvm-nm -m %t/thumb-foo | FileCheck %s --check-prefix=THUMB - -## Check that we preserve the .thumb_def flag if we pick the thumb definition of -## _foo. -# ARM: (__TEXT,arm) weak external _foo -# THUMB: (__TEXT,thumb) weak external [Thumb] _foo - -#--- thumb-foo.s -.section __TEXT,thumb -.globl _foo -.weak_definition _foo -.thumb_func _foo -.p2align 2 -_foo: - -#--- arm-foo.s -.section __TEXT,arm -.globl _foo -.weak_definition _foo -.p2align 2 -_foo: