Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
-DLLVM_ENABLE_PROJECTS="llvm;clang;clang-tools-extra" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_TARGETS_TO_BUILD="ARM;AArch64;RISCV;Hexagon;X86" \
-DELD_TARGETS_TO_BUILD='ARM;AArch64;RISCV;Hexagon;X86;Template' \
../llvm-project/llvm

- name: Build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DLLVM_TARGETS_TO_BUILD="ARM;AArch64;RISCV;Hexagon;X86" \
-DELD_TARGETS_TO_BUILD='ARM;AArch64;RISCV;Hexagon;X86;Template' \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DLLVM_CCACHE_BUILD:BOOL=ON \
-DLLVM_CCACHE_DIR:STRING="$CCACHE_DIR" \
Expand Down
10 changes: 7 additions & 3 deletions lib/Target/Template/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
llvm_add_library(
STATIC
ELDTemplateLDBackend
STATIC
TemplateEmulation.cpp
TemplateGOT.cpp
TemplateInfo.cpp
TemplateLDBackend.cpp
TemplateVRelocator.cpp
TemplatePLT.cpp
TemplateRelocator.cpp
TemplateRelocationCompute.cpp)

add_subdirectory(TargetInfo)

target_link_libraries(
ELDTemplateLDBackend PRIVATE ELDTemplateTargetInfo ELDCore ELDFragment
ELDObject ELDTarget LLVMTemplateCodeGen)
ELDObject ELDTarget )

# Add this to the end of target_link_libraries: LLVMTemplateCodeGen
25 changes: 25 additions & 0 deletions lib/Target/Template/TemplateGOT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===- TemplateGOT.cpp-----------------------------------------------------===//
// Part of the eld Project, under the BSD License
// See https://github.com/qualcomm/eld/LICENSE.txt for license information.
// SPDX-License-Identifier: BSD-3-Clause
//===----------------------------------------------------------------------===//

#include "TemplateGOT.h"
#include "eld/Readers/ELFSection.h"
#include "eld/Readers/Relocation.h"

using namespace eld;

// GOTPLT0
TemplateGOTPLT0 *TemplateGOTPLT0::Create(ELFSection *O, ResolveInfo *R) {
TemplateGOTPLT0 *G = make<TemplateGOTPLT0>(O, R);

return G;
}

TemplateGOTPLTN *TemplateGOTPLTN::Create(ELFSection *O, ResolveInfo *R,
Fragment *PLT) {
TemplateGOTPLTN *G = make<TemplateGOTPLTN>(O, R);

return G;
}
151 changes: 151 additions & 0 deletions lib/Target/Template/TemplateGOT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//===- TemplateGOT.h-------------------------------------------------------===//
// Part of the eld Project, under the BSD License
// See https://github.com/qualcomm/eld/LICENSE.txt for license information.
// SPDX-License-Identifier: BSD-3-Clause
//===----------------------------------------------------------------------===//

#ifndef ELD_TARGET_TEMPLATE_GOT_H
#define ELD_TARGET_TEMPLATE_GOT_H

#include "eld/Fragment/GOT.h"
#include "eld/Support/Memory.h"
#include "eld/Target/GNULDBackend.h"

namespace eld {

/** \class TemplateGOT
* \brief Template Global Offset Table.
*/

class TemplateGOT : public GOT {
public:
// Going to be used by GOTPLT0
TemplateGOT(GOTType T, ELFSection *O, ResolveInfo *R, uint32_t Align,
uint32_t Size)
: GOT(T, O, R, Align, Size) {
if (O)
O->addFragmentAndUpdateSize(this);
}

// Helper constructor for GOT.
TemplateGOT(GOTType T, ELFSection *O, ResolveInfo *R) : GOT(T, O, R, 4, 4) {
if (O)
O->addFragmentAndUpdateSize(this);
}

virtual ~TemplateGOT() {}

virtual TemplateGOT *getFirst() { return this; }

virtual TemplateGOT *getNext() { return nullptr; }

virtual llvm::ArrayRef<uint8_t> getContent() const override {
// Convert uint32_t to ArrayRef.
typedef union {
uint32_t a;
uint8_t b[4];
} C;
C Content;
Content.a = 0;
// If the GOT contents needs to reflect a symbol value, then we use the
// symbol value.
if (getValueType() == GOT::SymbolValue)
Content.a = symInfo()->outSymbol()->value();
if (getValueType() == GOT::TLSStaticSymbolValue)
Content.a =
symInfo()->outSymbol()->value() - GNULDBackend::getTLSTemplateSize();
std::memcpy((void *)Value, (void *)&Content.a, sizeof(Value));
return llvm::ArrayRef(Value);
}

static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) {
return make<TemplateGOT>(GOT::Regular, O, R);
}

private:
uint8_t Value[4] = {0};
};

class TemplateGOTPLT0 : public TemplateGOT {
public:
TemplateGOTPLT0(ELFSection *O, ResolveInfo *R)
: TemplateGOT(GOT::GOTPLT0, O, R, 4, 16) {}

TemplateGOT *getFirst() override { return this; }

TemplateGOT *getNext() override { return nullptr; }

static TemplateGOTPLT0 *Create(ELFSection *O, ResolveInfo *R);

llvm::ArrayRef<uint8_t> getContent() const override {
return llvm::ArrayRef(Value);
}

private:
uint8_t Value[16] = {0};
};

class TemplateGOTPLTN : public TemplateGOT {
public:
TemplateGOTPLTN(ELFSection *O, ResolveInfo *R)
: TemplateGOT(GOT::GOTPLTN, O, R, 4, 4) {}

TemplateGOT *getFirst() override { return this; }

TemplateGOT *getNext() override { return nullptr; }

static TemplateGOTPLTN *Create(ELFSection *O, ResolveInfo *R, Fragment *PLT);
};

class TemplateGDGOT : public TemplateGOT {
public:
TemplateGDGOT(ELFSection *O, ResolveInfo *R)
: TemplateGOT(GOT::TLS_GD, O, R),
Other(make<TemplateGOT>(GOT::TLS_GD, O, R)) {}

TemplateGOT *getFirst() override { return this; }

TemplateGOT *getNext() override { return Other; }

static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) {
return make<TemplateGDGOT>(O, R);
}

private:
TemplateGOT *Other;
};

class TemplateLDGOT : public TemplateGOT {
public:
TemplateLDGOT(ELFSection *O, ResolveInfo *R)
: TemplateGOT(GOT::TLS_LD, O, R),
Other(make<TemplateGOT>(GOT::TLS_LD, O, R)) {}

TemplateGOT *getFirst() override { return this; }

TemplateGOT *getNext() override { return Other; }

static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) {
return make<TemplateLDGOT>(O, R);
}

private:
TemplateGOT *Other;
};

class TemplateIEGOT : public TemplateGOT {
public:
TemplateIEGOT(ELFSection *O, ResolveInfo *R)
: TemplateGOT(GOT::TLS_LE, O, R) {}

TemplateGOT *getFirst() override { return this; }

TemplateGOT *getNext() override { return nullptr; }

static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) {
return make<TemplateIEGOT>(O, R);
}
};
} // namespace eld

#endif
13 changes: 9 additions & 4 deletions lib/Target/Template/TemplateInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@

using namespace eld;

const char *TemplateInfo::flagString(uint64_t flag) const { return ""; }
std::string TemplateInfo::flagString(uint64_t flag) const { return ""; }

llvm::StringRef TemplateInfo::getOutputMCPU() const { return "Template"; }

//===----------------------------------------------------------------------===//
// TemplateInfo
//===----------------------------------------------------------------------===//
TemplateInfo::TemplateInfo(LinkerConfig &pConfig) : TargetInfo(pConfig) {
m_OutputFlag = 0;
TemplateInfo::TemplateInfo(LinkerConfig &pConfig)
: TargetInfo(pConfig), m_OutputFlag(-1) {}

bool TemplateInfo::initialize() {
m_CmdLineFlag = -1;
return true;
}

uint64_t TemplateInfo::translateFlag(uint64_t pFlag) const { return pFlag; }

bool TemplateInfo::checkFlags(uint64_t pFlag, const std::string &name, bool) {
bool TemplateInfo::checkFlags(uint64_t pFlag, const InputFile *pInputFile,
bool) {
// Choose the default architecture from the input files, only if mcpu option
// is not specified on the command line.
if (!m_OutputFlag)
Expand Down
13 changes: 7 additions & 6 deletions lib/Target/Template/TemplateInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ class TemplateInfo : public TargetInfo {
return 1;
}

std::string getMachineStr() const override { return ""; }

/// flags - the value of ElfXX_Ehdr::e_flags
uint64_t flags() const override;

uint8_t OSABI() const override;

bool checkFlags(uint64_t flag, const std::string &name, bool) override;

const char *flagString(uint64_t pFlag) const override;
bool checkFlags(uint64_t flag, const InputFile *pInputFile, bool) override;

int32_t cmdLineFlag() const override { return m_CmdLineFlag; }

int32_t outputFlag() const override { return m_OutputFlag; }
std::string flagString(uint64_t pFlag) const override;

bool needEhdr(Module &pModule, bool linkerScriptHasSectionsCmd,
bool isPhdr) override {
Expand All @@ -43,8 +41,11 @@ class TemplateInfo : public TargetInfo {

llvm::StringRef getOutputMCPU() const override;

bool initialize() override;

private:
uint64_t translateFlag(uint64_t pFlag) const;
int32_t m_CmdLineFlag;
int32_t m_OutputFlag;
};

Expand Down
20 changes: 13 additions & 7 deletions lib/Target/Template/TemplateLDBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Template.h"
#include "TemplateRelocator.h"
#include "TemplateStandaloneInfo.h"
#include "eld/BranchIsland/StubFactory.h"
#include "eld/Config/LinkerConfig.h"
#include "eld/Fragment/FillFragment.h"
#include "eld/Fragment/RegionFragment.h"
Expand Down Expand Up @@ -43,11 +44,9 @@ TemplateLDBackend::TemplateLDBackend(Module &pModule, TemplateInfo *pInfo)
: GNULDBackend(pModule, pInfo), m_pRelocator(nullptr),
m_pEndOfImage(nullptr) {}

TemplateLDBackend::~TemplateLDBackend() { delete m_pRelocator; }

bool TemplateLDBackend::initRelocator() {
if (nullptr == m_pRelocator) {
m_pRelocator = new TemplateRelocator(*this, config(), m_Module);
m_pRelocator = make<TemplateRelocator>(*this, config(), m_Module);
}
return true;
}
Expand Down Expand Up @@ -113,17 +112,24 @@ TemplateLDBackend::getValueForDiscardedRelocations(const Relocation *R) const {
}

void TemplateLDBackend::initializeAttributes() {
getInfo().initializeAttributes(*m_Module.getIRBuilder());
getInfo().initializeAttributes(m_Module.getIRBuilder()->getInputBuilder());
}

Stub *TemplateLDBackend::getBranchIslandStub(Relocation *pReloc,
int64_t targetValue) const {
(void)pReloc;
(void)targetValue;
return *(getStubFactory()->getAllStubs().cbegin());
}

namespace eld {

//===----------------------------------------------------------------------===//
/// createTemplateLDBackend - the help function to create corresponding
/// TemplateLDBackend
GNULDBackend *createTemplateLDBackend(Module &pModule) {
return new TemplateLDBackend(pModule,
new TemplateStandaloneInfo(pModule.getConfig()));
GNULDBackend *createTemplateLDBackend(eld::Module &pModule) {
return make<TemplateLDBackend>(
pModule, make<TemplateStandaloneInfo>(pModule.getConfig()));
}

} // namespace eld
Expand Down
17 changes: 14 additions & 3 deletions lib/Target/Template/TemplateLDBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#ifndef TEMPLATE_LDBACKEND_H
#define TEMPLATE_LDBACKEND_H

#include "TemplateGOT.h"
#include "TemplatePLT.h"
#include "eld/Config/LinkerConfig.h"
#include "eld/Input/ELFSection.h"
#include "eld/Object/ObjectBuilder.h"
#include "eld/Readers/ELFSection.h"
#include "eld/SymbolResolver/IRBuilder.h"
#include "eld/Target/GNULDBackend.h"

Expand All @@ -26,8 +28,6 @@ class TemplateLDBackend : public GNULDBackend {
public:
TemplateLDBackend(Module &pModule, TemplateInfo *pInfo);

~TemplateLDBackend();

void initializeAttributes() override;

/// initRelocator - create and initialize Relocator.
Expand Down Expand Up @@ -65,11 +65,22 @@ class TemplateLDBackend : public GNULDBackend {

uint64_t maxBranchOffset() override { return 0; }

public:
Stub *getBranchIslandStub(Relocation *pReloc,
int64_t pTargetValue) const override;

std::size_t PLTEntriesCount() const override { return m_PLTMap.size(); }

std::size_t GOTEntriesCount() const override { return m_GOTMap.size(); }

private:
Relocator *m_pRelocator;
llvm::BumpPtrAllocator _alloc;

LDSymbol *m_pEndOfImage;

llvm::DenseMap<ResolveInfo *, TemplateGOT *> m_GOTMap;
llvm::DenseMap<ResolveInfo *, TemplatePLT *> m_PLTMap;
};
} // namespace eld

Expand Down
Loading
Loading