diff --git a/.github/workflows/ci-win.yml b/.github/workflows/ci-win.yml index 143dc4295..9f6669227 100644 --- a/.github/workflows/ci-win.yml +++ b/.github/workflows/ci-win.yml @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bbf5a71d..1a84b0d73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" \ diff --git a/lib/Target/Template/CMakeLists.txt b/lib/Target/Template/CMakeLists.txt index 51d8bab1d..68efdc0ab 100644 --- a/lib/Target/Template/CMakeLists.txt +++ b/lib/Target/Template/CMakeLists.txt @@ -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 diff --git a/lib/Target/Template/TemplateGOT.cpp b/lib/Target/Template/TemplateGOT.cpp new file mode 100644 index 000000000..ac561585f --- /dev/null +++ b/lib/Target/Template/TemplateGOT.cpp @@ -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(O, R); + + return G; +} + +TemplateGOTPLTN *TemplateGOTPLTN::Create(ELFSection *O, ResolveInfo *R, + Fragment *PLT) { + TemplateGOTPLTN *G = make(O, R); + + return G; +} diff --git a/lib/Target/Template/TemplateGOT.h b/lib/Target/Template/TemplateGOT.h new file mode 100644 index 000000000..5adb711a4 --- /dev/null +++ b/lib/Target/Template/TemplateGOT.h @@ -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 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(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 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(GOT::TLS_GD, O, R)) {} + + TemplateGOT *getFirst() override { return this; } + + TemplateGOT *getNext() override { return Other; } + + static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) { + return make(O, R); + } + +private: + TemplateGOT *Other; +}; + +class TemplateLDGOT : public TemplateGOT { +public: + TemplateLDGOT(ELFSection *O, ResolveInfo *R) + : TemplateGOT(GOT::TLS_LD, O, R), + Other(make(GOT::TLS_LD, O, R)) {} + + TemplateGOT *getFirst() override { return this; } + + TemplateGOT *getNext() override { return Other; } + + static TemplateGOT *Create(ELFSection *O, ResolveInfo *R) { + return make(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(O, R); + } +}; +} // namespace eld + +#endif diff --git a/lib/Target/Template/TemplateInfo.cpp b/lib/Target/Template/TemplateInfo.cpp index 5970d4350..7d3ae23fd 100644 --- a/lib/Target/Template/TemplateInfo.cpp +++ b/lib/Target/Template/TemplateInfo.cpp @@ -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) diff --git a/lib/Target/Template/TemplateInfo.h b/lib/Target/Template/TemplateInfo.h index b72ef8cdd..9692f8851 100644 --- a/lib/Target/Template/TemplateInfo.h +++ b/lib/Target/Template/TemplateInfo.h @@ -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 { @@ -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; }; diff --git a/lib/Target/Template/TemplateLDBackend.cpp b/lib/Target/Template/TemplateLDBackend.cpp index cd5ed710e..ce1fed053 100644 --- a/lib/Target/Template/TemplateLDBackend.cpp +++ b/lib/Target/Template/TemplateLDBackend.cpp @@ -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" @@ -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(*this, config(), m_Module); } return true; } @@ -113,7 +112,14 @@ 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 { @@ -121,9 +127,9 @@ 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( + pModule, make(pModule.getConfig())); } } // namespace eld diff --git a/lib/Target/Template/TemplateLDBackend.h b/lib/Target/Template/TemplateLDBackend.h index 112d908d5..e2e6a5564 100644 --- a/lib/Target/Template/TemplateLDBackend.h +++ b/lib/Target/Template/TemplateLDBackend.h @@ -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" @@ -26,8 +28,6 @@ class TemplateLDBackend : public GNULDBackend { public: TemplateLDBackend(Module &pModule, TemplateInfo *pInfo); - ~TemplateLDBackend(); - void initializeAttributes() override; /// initRelocator - create and initialize Relocator. @@ -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 m_GOTMap; + llvm::DenseMap m_PLTMap; }; } // namespace eld diff --git a/lib/Target/Template/TemplatePLT.cpp b/lib/Target/Template/TemplatePLT.cpp new file mode 100644 index 000000000..0fa1f661b --- /dev/null +++ b/lib/Target/Template/TemplatePLT.cpp @@ -0,0 +1,28 @@ +//===- TemplatePLT.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 "TemplatePLT.h" +#include "eld/Readers/ELFSection.h" +#include "eld/Readers/Relocation.h" +#include "eld/Support/Memory.h" + +using namespace eld; + +// PLT0 +TemplatePLT0 *TemplatePLT0::Create(eld::IRBuilder &I, TemplateGOT *G, + ELFSection *O, ResolveInfo *R) { + TemplatePLT0 *P = make(G, I, O, R, 4, sizeof(hexagon_plt0)); + + return P; +} + +// PLTN +TemplatePLTN *TemplatePLTN::Create(eld::IRBuilder &I, TemplateGOT *G, + ELFSection *O, ResolveInfo *R) { + TemplatePLTN *P = make(G, I, O, R, 4, sizeof(hexagon_plt1)); + + return P; +} diff --git a/lib/Target/Template/TemplatePLT.h b/lib/Target/Template/TemplatePLT.h new file mode 100644 index 000000000..414370010 --- /dev/null +++ b/lib/Target/Template/TemplatePLT.h @@ -0,0 +1,76 @@ +//===- TemplatePLT.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_PLT_H +#define ELD_TARGET_TEMPLATE_PLT_H + +#include "TemplateGOT.h" +#include "eld/Fragment/PLT.h" +#include "eld/SymbolResolver/IRBuilder.h" + +namespace { + +const uint8_t hexagon_plt0[] = { + 0x00, +}; + +const uint8_t hexagon_plt1[] = { + 0x00, +}; + +} // anonymous namespace + +namespace eld { + +class TemplateGOT; +class IRBuilder; + +class TemplatePLT : public PLT { +public: + TemplatePLT(PLT::PLTType T, eld::IRBuilder &I, TemplateGOT *G, ELFSection *P, + ResolveInfo *R, uint32_t Align, uint32_t Size) + : PLT(T, G, P, R, Align, Size) {} + + virtual ~TemplatePLT() {} + + virtual llvm::ArrayRef getContent() const override = 0; +}; + +class TemplatePLT0 : public TemplatePLT { +public: + TemplatePLT0(TemplateGOT *G, eld::IRBuilder &I, ELFSection *P, ResolveInfo *R, + uint32_t Align, uint32_t Size) + : TemplatePLT(PLT::PLT0, I, G, P, R, Align, Size) {} + + virtual ~TemplatePLT0() {} + + virtual llvm::ArrayRef getContent() const override { + return hexagon_plt0; + } + + static TemplatePLT0 *Create(eld::IRBuilder &I, TemplateGOT *G, ELFSection *O, + ResolveInfo *R); +}; + +class TemplatePLTN : public TemplatePLT { +public: + TemplatePLTN(TemplateGOT *G, eld::IRBuilder &I, ELFSection *P, ResolveInfo *R, + uint32_t Align, uint32_t Size) + : TemplatePLT(PLT::PLTN, I, G, P, R, Align, Size) {} + + virtual ~TemplatePLTN() {} + + virtual llvm::ArrayRef getContent() const override { + return hexagon_plt1; + } + + static TemplatePLTN *Create(eld::IRBuilder &I, TemplateGOT *G, ELFSection *O, + ResolveInfo *R); +}; + +} // namespace eld + +#endif diff --git a/lib/Target/Template/TemplateRelocationFunctions.h b/lib/Target/Template/TemplateRelocationFunctions.h index ebf811cd6..529880467 100644 --- a/lib/Target/Template/TemplateRelocationFunctions.h +++ b/lib/Target/Template/TemplateRelocationFunctions.h @@ -62,13 +62,16 @@ struct RelocationDescription { bool forceVerify; }; -struct RelocationDescription RelocDesc[] = { +struct RelocationDescription RelocDesc[1] = { + {} /* { func = &applyNone , type = llvm::ELF:: , forceVerify = false } */ }; +#define TEMPLATE_MAXRELOCS (/*llvm::ELF::R_LAST_RELOC + 1*/ 0) + } // namespace eld #endif // TEMPLATE_RELOCATION_FUNCTIONS_H diff --git a/lib/Target/Template/TemplateRelocationInfo.h b/lib/Target/Template/TemplateRelocationInfo.h index 9e3810db5..f4c99d855 100644 --- a/lib/Target/Template/TemplateRelocationInfo.h +++ b/lib/Target/Template/TemplateRelocationInfo.h @@ -19,7 +19,7 @@ namespace llvm { namespace Template { extern "C" { -const RelocationInfo Relocs[] = {}; +const RelocationInfo Relocs[1] = {{}}; } // extern "C" } // namespace Template } // namespace llvm diff --git a/lib/Target/Template/TemplateRelocator.cpp b/lib/Target/Template/TemplateRelocator.cpp index 1a7cff2e4..3d1f5daa4 100644 --- a/lib/Target/Template/TemplateRelocator.cpp +++ b/lib/Target/Template/TemplateRelocator.cpp @@ -24,7 +24,7 @@ TemplateRelocator::TemplateRelocator(TemplateLDBackend &pParent, LinkerConfig &pConfig, Module &pModule) : Relocator(pConfig, pModule), m_Target(pParent) { // Mark force verify bit for specified relcoations - if (DiagnosticPrinter::verifyReloc() && + if (m_Module.getPrinter()->verifyReloc() && config().options().verifyRelocList().size()) { auto &list = config().options().verifyRelocList(); for (auto &i : RelocDesc) { @@ -44,10 +44,10 @@ Relocator::Result TemplateRelocator::applyRelocation(Relocation &pRelocation) { LDSymbol *outSymbol = symInfo->outSymbol(); if (outSymbol && outSymbol->hasFragRef()) { ELFSection *S = outSymbol->fragRef()->frag()->getOwningSection(); - if (S->kind() == LDFileFormat::Discard || + if (S->isDiscard() || (S->getOutputSection() && S->getOutputSection()->isDiscard())) { std::lock_guard relocGuard(m_RelocMutex); - issueUndefRef(pRelocation, *S->input(), S); + issueUndefRef(pRelocation, *S->getInputFile(), S); return Relocator::OK; } } @@ -63,7 +63,8 @@ const char *TemplateRelocator::getName(Relocation::Type pType) const { void TemplateRelocator::scanRelocation(Relocation &pReloc, eld::IRBuilder &pLinker, - ELFSection &pSection, Input &pInput, + ELFSection &pSection, + InputFile &pInputFile, CopyRelocs &CopyRelocs) { if (LinkerConfig::Object == config().codeGenType()) return; @@ -74,23 +75,24 @@ void TemplateRelocator::scanRelocation(Relocation &pReloc, "ResolveInfo of relocation not set while scanRelocation"); // Check if we are tracing relocations. - if (DiagnosticPrinter::traceReloc()) { + if (m_Module.getPrinter()->traceReloc()) { std::lock_guard relocGuard(m_RelocMutex); std::string relocName = getName(pReloc.type()); if (config().options().traceReloc(relocName)) - config().place(config().getDiagEngine())(Diag::reloc_trace) - << relocName << pInput.decoratedPath(); + config().raise(Diag::reloc_trace) + << relocName << pReloc.symInfo()->name() + << pInputFile.getInput()->decoratedPath(); } // check if we should issue undefined reference for the relocation target // symbol - if (rsym->isUndef() || rsym->isBitCode()) { - std::lock_guard relocGuard(m_RelocMutex); - if (!m_Target.canProvideSymbol(rsym)) { + { + if (rsym->isUndef() || rsym->isBitCode()) { + std::lock_guard relocGuard(m_RelocMutex); if (m_Target.canIssueUndef(rsym)) { if (rsym->visibility() != ResolveInfo::Default) - issueInvisibleRef(pReloc, pInput); - issueUndefRef(pReloc, pInput, &pSection); + issueInvisibleRef(pReloc, pInputFile); + issueUndefRef(pReloc, pInputFile, &pSection); } } } @@ -99,30 +101,30 @@ void TemplateRelocator::scanRelocation(Relocation &pReloc, ? pSection.getLink() : pReloc.targetRef()->frag()->getOwningSection(); - if (0 == (section->flag() & llvm::ELF::SHF_ALLOC)) + if (!section->isAlloc()) return; if (rsym->isLocal()) // rsym is local - scanLocalReloc(pInput, pReloc, pLinker, *section); + scanLocalReloc(pInputFile, pReloc, pLinker, *section); else // rsym is external - scanGlobalReloc(pInput, pReloc, pLinker, *section); + scanGlobalReloc(pInputFile, pReloc, pLinker, *section); } Relocation::Size TemplateRelocator::getSize(Relocation::Type pType) const { return 0; } -void TemplateRelocator::scanLocalReloc(Input &pInput, Relocation &pReloc, +void TemplateRelocator::scanLocalReloc(InputFile &pInput, Relocation &pReloc, eld::IRBuilder &pBuilder, ELFSection &pSection) {} -void TemplateRelocator::scanGlobalReloc(Input &pInput, Relocation &pReloc, +void TemplateRelocator::scanGlobalReloc(InputFile &pInput, Relocation &pReloc, eld::IRBuilder &pBuilder, ELFSection &pSection) {} void TemplateRelocator::partialScanRelocation(Relocation &pReloc, const ELFSection &pSection) { - pReloc.updateAddend(config().getDiagEngine()); + pReloc.updateAddend(m_Module); // if we meet a section symbol if (pReloc.symInfo()->type() == ResolveInfo::Section) { @@ -131,7 +133,7 @@ void TemplateRelocator::partialScanRelocation(Relocation &pReloc, // 1. update the relocation target offset assert(input_sym->hasFragRef()); // 2. get the output ELFSection which the symbol defined in - ELFSection *out_sect = input_sym->fragRef()->frag()->getOutputSection(); + ELFSection *out_sect = input_sym->fragRef()->getOutputELFSection(); ResolveInfo *sym_info = m_Module.getSectionSymbol(out_sect); // set relocation target symbol to the output section symbol's resolveInfo @@ -139,6 +141,8 @@ void TemplateRelocator::partialScanRelocation(Relocation &pReloc, } } +uint32_t TemplateRelocator::getNumRelocs() const { return TEMPLATE_MAXRELOCS; } + //=========================================// // Relocation Verifier //=========================================// @@ -162,86 +166,82 @@ Relocator::Result ApplyReloc(Relocation &pReloc, uint32_t Result, // Each relocation function implementation // //=========================================// -TemplateRelocator::Result eld::applyNone(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +TemplateRelocator::Result applyNone(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { return TemplateRelocator::OK; } -TemplateVRelocator::Result eld::applyAbs(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { - if (pReloc.type() >= TEMPLATE_MAXRELOCS) - return TemplateRelocator::Unsupport; - - int64_t S = pReloc.symValue(); +TemplateRelocator::Result applyAbs(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); return ApplyReloc(pReloc, S + A, pRelocDesc); } -TemplateRelocator::Result eld::applyRel(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +TemplateRelocator::Result applyRel(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); - int64_t P = pReloc.place(config().getDiagEngine()); + int64_t P = pReloc.place(pParent.module()); return ApplyReloc(pReloc, S + A - P, pRelocDesc); } -TemplateRelocator::Result eld::applyHILO(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); +TemplateRelocator::Result applyHILO(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); return ApplyReloc(pReloc, S + A, pRelocDesc); } -TemplateRelocator::Result eld::applyRelax(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +TemplateRelocator::Result applyRelax(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); return ApplyReloc(pReloc, S + A, pRelocDesc); } -TemplateRelocator::Result -eld::applyJumpOrCall(Relocation &pReloc, TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +TemplateRelocator::Result applyJumpOrCall(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); return ApplyReloc(pReloc, S + A, pRelocDesc); } -TemplateRelocator::Result eld::applyAlign(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +TemplateRelocator::Result applyAlign(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); + int64_t S = pReloc.symValue(pParent.module()); int64_t A = pReloc.addend(); return ApplyReloc(pReloc, S + A, pRelocDesc); } -TemplateRelocator::Result eld::applyGPRel(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) +TemplateRelocator::Result applyGPRel(Relocation &pReloc, + TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { - int64_t S = pReloc.symValue(); -int64_t A = pReloc.addend(); + int64_t S = pReloc.symValue(pParent.module()); + int64_t A = pReloc.addend(); -return ApplyReloc(pReloc, S + A, pRelocDesc); + return ApplyReloc(pReloc, S + A, pRelocDesc); } -Relocator::Result eld::unsupported(Relocation &pReloc, - TemplateRelocator &pParent, - RelocationDescription &pRelocDesc) { +Relocator::Result unsupported(Relocation &pReloc, TemplateRelocator &pParent, + RelocationDescription &pRelocDesc) { return TemplateRelocator::Unsupport; } diff --git a/lib/Target/Template/TemplateRelocator.h b/lib/Target/Template/TemplateRelocator.h index 30b471985..899440018 100644 --- a/lib/Target/Template/TemplateRelocator.h +++ b/lib/Target/Template/TemplateRelocator.h @@ -26,27 +26,31 @@ class TemplateRelocator : public Relocator { TemplateRelocator(TemplateLDBackend &pParent, LinkerConfig &pConfig, Module &pModule); - Result applyRelocation(Relocation &pRelocation); + Result applyRelocation(Relocation &pRelocation) override; void scanRelocation(Relocation &pReloc, eld::IRBuilder &pBuilder, - ELFSection &pSection, Input &pInput, CopyRelocs &); + ELFSection &pSection, InputFile &pInput, + CopyRelocs &) override; // Handle partial linking - void partialScanRelocation(Relocation &pReloc, const ELFSection &pSection); + void partialScanRelocation(Relocation &pReloc, + const ELFSection &pSection) override; - TemplateLDBackend &getTarget() { return m_Target; } + TemplateLDBackend &getTarget() override { return m_Target; } - const TemplateLDBackend &getTarget() const { return m_Target; } + const TemplateLDBackend &getTarget() const override { return m_Target; } - const char *getName(Relocation::Type pType) const; + const char *getName(Relocation::Type pType) const override; - Size getSize(Relocation::Type pType) const; + Size getSize(Relocation::Type pType) const override; + + uint32_t getNumRelocs() const override; private: - virtual void scanLocalReloc(Input &pInput, Relocation &pReloc, + virtual void scanLocalReloc(InputFile &pInput, Relocation &pReloc, eld::IRBuilder &pBuilder, ELFSection &pSection); - virtual void scanGlobalReloc(Input &pInput, Relocation &pReloc, + virtual void scanGlobalReloc(InputFile &pInput, Relocation &pReloc, eld::IRBuilder &pBuilder, ELFSection &pSection); private: diff --git a/lib/Target/Template/TemplateStandaloneInfo.h b/lib/Target/Template/TemplateStandaloneInfo.h index fe51a5b90..9206d1339 100644 --- a/lib/Target/Template/TemplateStandaloneInfo.h +++ b/lib/Target/Template/TemplateStandaloneInfo.h @@ -18,13 +18,13 @@ class TemplateStandaloneInfo : public TemplateInfo { public: TemplateStandaloneInfo(LinkerConfig &pConfig) : TemplateInfo(pConfig) {} - virtual uint64_t startAddr(bool linkerScriptHasSectionsCmd, bool isDynExec, - bool loadPhdr) const override { + uint64_t startAddr(bool linkerScriptHasSectionsCommand, bool isDynExec, + bool loadPhdr) const override { return 0; } - void initializeAttributes(eld::IRBuilder &pBuilder) override { - pBuilder.AgainstStatic(); + void initializeAttributes(InputBuilder &pBuilder) override { + pBuilder.makeBStatic(); } }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d1799b1ed..68e9c84b9 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,6 +24,9 @@ if(test_riscv GREATER -1) set(TEST_TARGETS "${TEST_TARGETS};RISCV64") endif() +#Remove the Template backend from the testing infrastructure. +list(REMOVE_ITEM TEST_TARGETS "Template") + add_custom_target(PluginUnitTests) set_target_properties(PluginUnitTests PROPERTIES FOLDER "plugin unit tests")