490 changes: 490 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.h ------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef AARCH64_RELOCATION_HANDLER_H
#define AARCH64_RELOCATION_HANDLER_H

#include "AArch64TargetHandler.h"

namespace lld {
namespace elf {
typedef llvm::object::ELFType<llvm::support::little, 2, true> AArch64ELFType;

template <class ELFT> class AArch64TargetLayout;

class AArch64TargetRelocationHandler final
: public TargetRelocationHandler<AArch64ELFType> {
public:
AArch64TargetRelocationHandler(AArch64TargetLayout<AArch64ELFType> &layout)
: _tlsSize(0), _AArch64Layout(layout) {}

std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &,
const Reference &) const override;

virtual int64_t relocAddend(const Reference &) const;

static const Registry::KindStrings kindStrings[];

private:
// Cached size of the TLS segment.
mutable uint64_t _tlsSize;
AArch64TargetLayout<AArch64ELFType> &_AArch64Layout;
};

} // end namespace elf
} // end namespace lld

#endif // AArch64_RELOCATION_HANDLER_H
535 changes: 535 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.h ---------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Declares the relocation processing pass for x86-64. This includes
/// GOT and PLT entries, TLS, COPY, and ifunc.
///
//===----------------------------------------------------------------------===//

#ifndef LLD_READER_WRITER_ELF_AARCH64_AARCH64_RELOCATION_PASS_H
#define LLD_READER_WRITER_ELF_AARCH64_AARCH64_RELOCATION_PASS_H

#include <memory>

namespace lld {
class Pass;
namespace elf {
class AArch64LinkingContext;

/// \brief Create AArch64 relocation pass for the given linking context.
std::unique_ptr<Pass>
createAArch64RelocationPass(const AArch64LinkingContext &);
}
}

#endif
10 changes: 10 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64Target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64Target.h -----------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "AArch64LinkingContext.h"
129 changes: 129 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp --------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Atoms.h"
#include "AArch64ExecutableWriter.h"
#include "AArch64DynamicLibraryWriter.h"
#include "AArch64TargetHandler.h"
#include "AArch64LinkingContext.h"

using namespace lld;
using namespace elf;

AArch64TargetHandler::AArch64TargetHandler(AArch64LinkingContext &context)
: DefaultTargetHandler(context), _context(context),
_AArch64TargetLayout(new AArch64TargetLayout<AArch64ELFType>(context)),
_AArch64RelocationHandler(
new AArch64TargetRelocationHandler(*_AArch64TargetLayout.get())) {}

void AArch64TargetHandler::registerRelocationNames(Registry &registry) {
registry.addKindTable(Reference::KindNamespace::ELF,
Reference::KindArch::AArch64, kindStrings);
}

std::unique_ptr<Writer> AArch64TargetHandler::getWriter() {
switch (this->_context.getOutputELFType()) {
case llvm::ELF::ET_EXEC:
return std::unique_ptr<Writer>(new AArch64ExecutableWriter<AArch64ELFType>(
_context, *_AArch64TargetLayout.get()));
case llvm::ELF::ET_DYN:
return std::unique_ptr<Writer>(
new AArch64DynamicLibraryWriter<AArch64ELFType>(
_context, *_AArch64TargetLayout.get()));
case llvm::ELF::ET_REL:
llvm_unreachable("TODO: support -r mode");
default:
llvm_unreachable("unsupported output type");
}
}

const Registry::KindStrings AArch64TargetHandler::kindStrings[] = {
LLD_KIND_STRING_ENTRY(R_AARCH64_NONE),
LLD_KIND_STRING_ENTRY(R_AARCH64_ABS64),
LLD_KIND_STRING_ENTRY(R_AARCH64_ABS32),
LLD_KIND_STRING_ENTRY(R_AARCH64_ABS16),
LLD_KIND_STRING_ENTRY(R_AARCH64_PREL64),
LLD_KIND_STRING_ENTRY(R_AARCH64_PREL32),
LLD_KIND_STRING_ENTRY(R_AARCH64_PREL16),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G0),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G0_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G1),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G1_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G2),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G2_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_UABS_G3),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_SABS_G0),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_SABS_G1),
LLD_KIND_STRING_ENTRY(R_AARCH64_MOVW_SABS_G2),
LLD_KIND_STRING_ENTRY(R_AARCH64_LD_PREL_LO19),
LLD_KIND_STRING_ENTRY(R_AARCH64_ADR_PREL_LO21),
LLD_KIND_STRING_ENTRY(R_AARCH64_ADR_PREL_PG_HI21),
LLD_KIND_STRING_ENTRY(R_AARCH64_ADD_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_LDST8_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TSTBR14),
LLD_KIND_STRING_ENTRY(R_AARCH64_CONDBR19),
LLD_KIND_STRING_ENTRY(R_AARCH64_JUMP26),
LLD_KIND_STRING_ENTRY(R_AARCH64_CALL26),
LLD_KIND_STRING_ENTRY(R_AARCH64_LDST16_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_LDST32_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_LDST64_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_LDST128_ABS_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_ADR_GOT_PAGE),
LLD_KIND_STRING_ENTRY(R_AARCH64_LD64_GOT_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_MOVW_DTPREL_G2),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_MOVW_DTPREL_G1),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_MOVW_DTPREL_G0),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_ADD_DTPREL_HI12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_ADD_DTPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST8_DTPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST16_DTPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST32_DTPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST64_DTPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_MOVW_TPREL_G2),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_MOVW_TPREL_G1),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_MOVW_TPREL_G0),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_ADD_TPREL_HI12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_ADD_TPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST8_TPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST16_TPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST32_TPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST64_TPREL_LO12),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSDESC_ADR_PAGE),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSDESC_LD64_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSDESC_ADD_LO12_NC),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSDESC_CALL),
LLD_KIND_STRING_ENTRY(R_AARCH64_COPY),
LLD_KIND_STRING_ENTRY(R_AARCH64_GLOB_DAT),
LLD_KIND_STRING_ENTRY(R_AARCH64_JUMP_SLOT),
LLD_KIND_STRING_ENTRY(R_AARCH64_RELATIVE),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLS_DTPREL64),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLS_DTPMOD64),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLS_TPREL64),
LLD_KIND_STRING_ENTRY(R_AARCH64_TLSDESC),
LLD_KIND_STRING_ENTRY(R_AARCH64_IRELATIVE),
LLD_KIND_STRING_END};
57 changes: 57 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//===- lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h ----------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_READER_WRITER_ELF_AARCH64_AARCH64_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_AARCH64_AARCH64_TARGET_HANDLER_H

#include "DefaultTargetHandler.h"
#include "ELFFile.h"
#include "AArch64RelocationHandler.h"
#include "TargetLayout.h"

#include "lld/Core/Simple.h"

namespace lld {
namespace elf {
typedef llvm::object::ELFType<llvm::support::little, 2, true> AArch64ELFType;
class AArch64LinkingContext;

template <class ELFT> class AArch64TargetLayout : public TargetLayout<ELFT> {
public:
AArch64TargetLayout(AArch64LinkingContext &context)
: TargetLayout<ELFT>(context) {}
};

class AArch64TargetHandler final : public DefaultTargetHandler<AArch64ELFType> {
public:
AArch64TargetHandler(AArch64LinkingContext &context);

AArch64TargetLayout<AArch64ELFType> &getTargetLayout() override {
return *(_AArch64TargetLayout.get());
}

void registerRelocationNames(Registry &registry) override;

const AArch64TargetRelocationHandler &getRelocationHandler() const override {
return *(_AArch64RelocationHandler.get());
}

std::unique_ptr<Writer> getWriter() override;

private:
static const Registry::KindStrings kindStrings[];
AArch64LinkingContext &_context;
std::unique_ptr<AArch64TargetLayout<AArch64ELFType>> _AArch64TargetLayout;
std::unique_ptr<AArch64TargetRelocationHandler> _AArch64RelocationHandler;
};

} // end namespace elf
} // end namespace lld

#endif
10 changes: 10 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_lld_library(lldAArch64ELFTarget
AArch64LinkingContext.cpp
AArch64TargetHandler.cpp
AArch64RelocationHandler.cpp
AArch64RelocationPass.cpp
)

target_link_libraries(lldAArch64ELFTarget
lldCore
)
15 changes: 15 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##===- lld/lib/ReaderWriter/ELF/AArch64/Makefile ----------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##

LLD_LEVEL := ../../../..
LIBRARYNAME := lldAArch64ELFTarget
USEDLIBS = lldCore.a
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF/AArch64 -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF

include $(LLD_LEVEL)/Makefile
15 changes: 15 additions & 0 deletions lld/lib/ReaderWriter/ELF/AArch64/TODO.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ELF AArch64
~~~~~~~~~~

Unimplemented Features
######################

* Just about everything!

Unimplemented Relocations
#########################

All of these relocations are defined in:
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf


5 changes: 5 additions & 0 deletions lld/lib/ReaderWriter/ELF/Atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ class SimpleELFDefinedAtom : public SimpleDefinedAtom {
Reference::Addend a) {
this->addReferenceELF(Reference::KindArch::Mips, relocType, off, t, a);
}

void addReferenceELF_AArch64(uint16_t relocType, uint64_t off, const Atom *t,
Reference::Addend a) {
this->addReferenceELF(Reference::KindArch::AArch64, relocType, off, t, a);
}
};

/// \brief Atom which represents an object for which a COPY relocation will be
Expand Down
1 change: 1 addition & 0 deletions lld/lib/ReaderWriter/ELF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(lldELF
lldReaderWriter
lldX86ELFTarget
lldX86_64ELFTarget
lldAArch64ELFTarget
)

include_directories(.)
Expand Down
2 changes: 2 additions & 0 deletions lld/lib/ReaderWriter/ELF/ELFFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ template <class ELFT> Reference::KindArch ELFFile<ELFT>::kindArch() {
return Reference::KindArch::Hexagon;
case llvm::ELF::EM_MIPS:
return Reference::KindArch::Mips;
case llvm::ELF::EM_AARCH64:
return Reference::KindArch::AArch64;
}
llvm_unreachable("unsupported e_machine value");
}
Expand Down
5 changes: 5 additions & 0 deletions lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ uint16_t ELFLinkingContext::getOutputMachine() const {
return llvm::ELF::EM_MIPS;
case llvm::Triple::ppc:
return llvm::ELF::EM_PPC;
case llvm::Triple::aarch64:
return llvm::ELF::EM_AARCH64;
default:
llvm_unreachable("Unhandled arch");
}
Expand Down Expand Up @@ -147,6 +149,9 @@ ELFLinkingContext::create(llvm::Triple triple) {
case llvm::Triple::ppc:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::PPCLinkingContext(triple));
case llvm::Triple::aarch64:
return std::unique_ptr<ELFLinkingContext>(
new lld::elf::AArch64LinkingContext(triple));
default:
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions lld/lib/ReaderWriter/ELF/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
LLD_LEVEL := ../../..
LIBRARYNAME := lldELF
USEDLIBS = lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
lldX86ELFTarget.a lldX86_64ELFTarget.a \
lldX86ELFTarget.a lldX86_64ELFTarget.a lldAArch64ELFTarget.a \
lldReaderWriter.a lldPasses.a

CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLD_LEVEL)/lib/ReaderWriter/ELF

# these link against this lib
PARALLEL_DIRS := Hexagon PPC X86 X86_64 Mips
PARALLEL_DIRS := Hexagon PPC X86 X86_64 Mips AArch64

include $(LLD_LEVEL)/Makefile
1 change: 1 addition & 0 deletions lld/lib/ReaderWriter/ELF/Targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#include "PPC/PPCTarget.h"
#include "X86/X86Target.h"
#include "X86_64/X86_64Target.h"
#include "AArch64/AArch64Target.h"

#endif
4 changes: 4 additions & 0 deletions lld/test/elf/AArch64/Inputs/fn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int fn()
{
return 0;
}
Binary file added lld/test/elf/AArch64/Inputs/fn.o
Binary file not shown.
12 changes: 12 additions & 0 deletions lld/test/elf/AArch64/Inputs/initfini-option.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

void init() {
printf("%s\n", __FUNCTION__);
}

void fini() {
printf("%s\n", __FUNCTION__);
}

int main() {
}
Binary file added lld/test/elf/AArch64/Inputs/initfini-option.o
Binary file not shown.
13 changes: 13 additions & 0 deletions lld/test/elf/AArch64/Inputs/initfini.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>

void __attribute__ ((constructor)) constructor() {
printf("%s\n", __FUNCTION__);
}

void __attribute__ ((destructor)) destructor() {
printf("%s\n", __FUNCTION__);
}

int main() {
return 0;
}
Binary file added lld/test/elf/AArch64/Inputs/initfini.o
Binary file not shown.
4 changes: 4 additions & 0 deletions lld/test/elf/AArch64/Inputs/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main() {
fn();
return 0;
}
Binary file added lld/test/elf/AArch64/Inputs/main.o
Binary file not shown.
1 change: 1 addition & 0 deletions lld/test/elf/AArch64/Inputs/no-interp-section.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int c = 10;
Binary file added lld/test/elf/AArch64/Inputs/no-interp-section.o
Binary file not shown.
Binary file added lld/test/elf/AArch64/Inputs/zerosizedsection.o
Binary file not shown.
3 changes: 3 additions & 0 deletions lld/test/elf/AArch64/Inputs/zerosizedsection.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text
.data
.word .text
22 changes: 22 additions & 0 deletions lld/test/elf/AArch64/defsym.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
RUN: lld -flavor gnu -target aarch64--linux-gnu --defsym=main=fn \
RUN: --noinhibit-exec %p/Inputs/fn.o -o %t
RUN: llvm-readobj -symbols %t | FileCheck %s

CHECK: Symbol {
CHECK: Name: main (1)
CHECK: Value: 0x4001A4
CHECK: Size: 0
CHECK: Binding: Global (0x1)
CHECK: Type: Function (0x2)
CHECK: Other: 0
CHECK: Section: .text (0x5)
CHECK: }
CHECK: Symbol {
CHECK: Name: fn (6)
CHECK: Value: 0x4001A4
CHECK: Size: 8
CHECK: Binding: Global (0x1)
CHECK: Type: Function (0x2)
CHECK: Other: 0
CHECK: Section: .text (0x5)
CHECK: }
9 changes: 9 additions & 0 deletions lld/test/elf/AArch64/dontignorezerosize-sections.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This tests that lld is not ignoring zero sized sections
RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/zerosizedsection.o \
RUN: --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t

CHECK: references:
CHECK: - kind: layout-after
CHECK: offset: 0
CHECK: target: L000
5 changes: 5 additions & 0 deletions lld/test/elf/AArch64/dynlib-nointerp-section.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/no-interp-section.o \
RUN: -o %t -shared
RUN: llvm-objdump -section-headers %t | FileCheck %s

CHECK-NOT: .interp
12 changes: 12 additions & 0 deletions lld/test/elf/AArch64/initfini-alignment.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This tests the functionality that lld is able to create
# init_array/fini_array sections in the output ELF with the
# right alignment

RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/initfini-option.o \
RUN: -init init -fini fini --noinhibit-exec -o %t
RUN: llvm-readobj -s %t | FileCheck %s

CHECK: Name: .init_array
CHECK: AddressAlignment: 8
CHECK: Name: .fini_array
CHECK: AddressAlignment: 8
21 changes: 21 additions & 0 deletions lld/test/elf/AArch64/initfini-option.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This tests the functionality that lld is able to create
# init_array/fini_array sections in the output ELF. This
# corresponds to the the .init_array/.fini_array sections
# in the output ELF.

RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/initfini-option.o \
RUN: -init init -fini fini --noinhibit-exec --output-filetype=yaml -static -o %t
RUN: FileCheck %s < %t

CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-name: .init_array
CHECK: references:
CHECK: - kind: R_AARCH64_ABS64
CHECK: offset: 0
CHECK: target: init
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-name: .fini_array
CHECK: references:
CHECK: - kind: R_AARCH64_ABS64
CHECK: offset: 0
CHECK: target: fini
23 changes: 23 additions & 0 deletions lld/test/elf/AArch64/initfini.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This tests the functionality that lld is able to read
# init_array/fini_array sections in the input ELF. This
# corresponds to the the .init_array/.fini_array sections
# in the output ELF.

RUN: lld -flavor gnu -target aarch64--linux-gnu %p/Inputs/initfini.o \
RUN: --noinhibit-exec --output-filetype=yaml -o %t
RUN: FileCheck %s < %t

CHECK: type: data
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-name: .init_array
CHECK: references:
CHECK: - kind: R_AARCH64_ABS64
CHECK: offset: 0
CHECK: target: constructor
CHECK: type: data
CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
CHECK: section-name: .fini_array
CHECK: references:
CHECK: - kind: R_AARCH64_ABS64
CHECK: offset: 0
CHECK: target: destructor
3 changes: 2 additions & 1 deletion lld/tools/lld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ USEDLIBS = lldDriver.a \
lldELF.a lldMachO.a lldPasses.a lldPECOFF.a lldYAML.a \
lldReaderWriter.a lldCore.a lldNative.a \
lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
lldX86ELFTarget.a lldX86_64ELFTarget.a LLVMOption.a
lldX86ELFTarget.a lldX86_64ELFTarget.a lldAArch64ELFTarget.a \
LLVMOption.a

include $(LLD_LEVEL)/Makefile
2 changes: 1 addition & 1 deletion lld/unittests/DriverTests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ USEDLIBS = lldDriver.a \
lldHexagonELFTarget.a lldPPCELFTarget.a lldMipsELFTarget.a \
lldX86ELFTarget.a lldX86_64ELFTarget.a lldYAML.a \
LLVMObject.a LLVMMCParser.a LLVMMC.a LLVMBitReader.a \
LLVMCore.a LLVMOption.a LLVMSupport.a
LLVMCore.a LLVMOption.a LLVMSupport.a lldAArch64ELFTarget.a
include $(LLD_LEVEL)/unittests/Makefile