summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter')
-rw-r--r--lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/ARM/ARMELFFile.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/CMakeLists.txt1
-rw-r--r--lld/lib/ReaderWriter/ELF/DynamicFile.cpp7
-rw-r--r--lld/lib/ReaderWriter/ELF/DynamicFile.h3
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFFile.cpp7
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFFile.h6
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFReader.h47
-rw-r--r--lld/lib/ReaderWriter/ELF/FileCommon.cpp63
-rw-r--r--lld/lib/ReaderWriter/ELF/FileCommon.h48
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp5
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h2
-rw-r--r--lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h5
24 files changed, 162 insertions, 68 deletions
diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
index 81ae48eb58c..64b9cba7d60 100644
--- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
@@ -24,7 +24,7 @@ enum {
class AArch64LinkingContext final : public ELFLinkingContext {
public:
- static const int machine = llvm::ELF::EM_AARCH64;
+ int getMachineType() const override { return llvm::ELF::EM_AARCH64; }
AArch64LinkingContext(llvm::Triple);
void addPasses(PassManager &) override;
diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
index e2696bbd3d3..e917d952ece 100644
--- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
@@ -20,8 +20,8 @@ namespace elf {
class AArch64LinkingContext;
class AArch64TargetHandler final : public TargetHandler {
- typedef ELFReader<ELF64LE, AArch64LinkingContext, ELFFile> ObjReader;
- typedef ELFReader<ELF64LE, AArch64LinkingContext, DynamicFile> DSOReader;
+ typedef ELFReader<ELFFile<ELF64LE>> ObjReader;
+ typedef ELFReader<DynamicFile<ELF64LE>> DSOReader;
public:
AArch64TargetHandler(AArch64LinkingContext &ctx);
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMELFFile.h b/lld/lib/ReaderWriter/ELF/ARM/ARMELFFile.h
index 8ebd3b1f1cf..72368bd20d0 100644
--- a/lld/lib/ReaderWriter/ELF/ARM/ARMELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/ARM/ARMELFFile.h
@@ -55,7 +55,7 @@ template <class ELFT> class ARMELFFile : public ELFFile<ELFT> {
typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
public:
- ARMELFFile(std::unique_ptr<MemoryBuffer> mb, ARMLinkingContext &ctx)
+ ARMELFFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx)
: ELFFile<ELFT>(std::move(mb), ctx) {}
protected:
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h b/lld/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h
index 5540b730add..a354c2fc415 100644
--- a/lld/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h
@@ -19,7 +19,7 @@ namespace elf {
class ARMLinkingContext final : public ELFLinkingContext {
public:
- static const int machine = llvm::ELF::EM_ARM;
+ int getMachineType() const override { return llvm::ELF::EM_ARM; }
ARMLinkingContext(llvm::Triple);
void addPasses(PassManager &) override;
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
index 63a9aeaf70f..74f218fb8f5 100644
--- a/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
@@ -59,8 +59,8 @@ private:
};
class ARMTargetHandler final : public TargetHandler {
- typedef ELFReader<ELF32LE, ARMLinkingContext, ARMELFFile> ObjReader;
- typedef ELFReader<ELF32LE, ARMLinkingContext, DynamicFile> DSOReader;
+ typedef ELFReader<ARMELFFile<ELF32LE>> ObjReader;
+ typedef ELFReader<DynamicFile<ELF32LE>> DSOReader;
public:
ARMTargetHandler(ARMLinkingContext &ctx);
diff --git a/lld/lib/ReaderWriter/ELF/CMakeLists.txt b/lld/lib/ReaderWriter/ELF/CMakeLists.txt
index 9b9a62779cd..d94d9b61f90 100644
--- a/lld/lib/ReaderWriter/ELF/CMakeLists.txt
+++ b/lld/lib/ReaderWriter/ELF/CMakeLists.txt
@@ -2,6 +2,7 @@ add_llvm_library(lldELF
DynamicFile.cpp
ELFFile.cpp
ELFLinkingContext.cpp
+ FileCommon.cpp
Reader.cpp
Writer.cpp
LINK_LIBS
diff --git a/lld/lib/ReaderWriter/ELF/DynamicFile.cpp b/lld/lib/ReaderWriter/ELF/DynamicFile.cpp
index 3f0d2fdee54..4ca4a3e1565 100644
--- a/lld/lib/ReaderWriter/ELF/DynamicFile.cpp
+++ b/lld/lib/ReaderWriter/ELF/DynamicFile.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "DynamicFile.h"
+#include "FileCommon.h"
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Object/ELF.h"
@@ -29,6 +30,12 @@ DynamicFile<ELFT>::DynamicFile(std::unique_ptr<MemoryBuffer> mb,
: SharedLibraryFile(mb->getBufferIdentifier()), _mb(std::move(mb)),
_ctx(ctx), _useShlibUndefines(ctx.useShlibUndefines()) {}
+template <typename ELFT>
+std::error_code DynamicFile<ELFT>::isCompatible(const MemoryBuffer &mb,
+ ELFLinkingContext &ctx) {
+ return lld::elf::isCompatible<ELFT>(mb, ctx);
+}
+
template <class ELFT>
const SharedLibraryAtom *DynamicFile<ELFT>::exports(StringRef name,
bool dataSymbolOnly) const {
diff --git a/lld/lib/ReaderWriter/ELF/DynamicFile.h b/lld/lib/ReaderWriter/ELF/DynamicFile.h
index 9a642f51fce..b319fad93ee 100644
--- a/lld/lib/ReaderWriter/ELF/DynamicFile.h
+++ b/lld/lib/ReaderWriter/ELF/DynamicFile.h
@@ -26,6 +26,9 @@ public:
DynamicFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx);
+ static std::error_code isCompatible(const MemoryBuffer &mb,
+ ELFLinkingContext &ctx);
+
const SharedLibraryAtom *exports(StringRef name,
bool dataSymbolOnly) const override;
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.cpp b/lld/lib/ReaderWriter/ELF/ELFFile.cpp
index 6a1979325f5..e25662feefd 100644
--- a/lld/lib/ReaderWriter/ELF/ELFFile.cpp
+++ b/lld/lib/ReaderWriter/ELF/ELFFile.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "ELFFile.h"
+#include "FileCommon.h"
#include "llvm/ADT/STLExtras.h"
namespace lld {
@@ -27,6 +28,12 @@ ELFFile<ELFT>::ELFFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx)
_useWrap(ctx.wrapCalls().size()), _ctx(ctx) {}
template <typename ELFT>
+std::error_code ELFFile<ELFT>::isCompatible(const MemoryBuffer &mb,
+ ELFLinkingContext &ctx) {
+ return lld::elf::isCompatible<ELFT>(mb, ctx);
+}
+
+template <typename ELFT>
Atom *ELFFile<ELFT>::findAtom(const Elf_Sym *sourceSym,
const Elf_Sym *targetSym) {
// Return the atom for targetSym if we can do so.
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h
index ccf94e9b49d..90623dfa914 100644
--- a/lld/lib/ReaderWriter/ELF/ELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/ELFFile.h
@@ -11,6 +11,7 @@
#define LLD_READER_WRITER_ELF_FILE_H
#include "Atoms.h"
+#include "FileCommon.h"
#include "llvm/ADT/MapVector.h"
#include <map>
#include <unordered_map>
@@ -89,6 +90,9 @@ public:
ELFFile(StringRef name, ELFLinkingContext &ctx);
ELFFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx);
+ static std::error_code isCompatible(const MemoryBuffer &mb,
+ ELFLinkingContext &ctx);
+
static bool canParse(file_magic magic) {
return magic == file_magic::elf_relocatable;
}
@@ -334,6 +338,8 @@ protected:
return nullptr;
}
+ static bool isCompatible(unsigned char size, unsigned char endian);
+
llvm::BumpPtrAllocator _readerStorage;
std::unique_ptr<llvm::object::ELFFile<ELFT> > _objFile;
diff --git a/lld/lib/ReaderWriter/ELF/ELFReader.h b/lld/lib/ReaderWriter/ELF/ELFReader.h
index 09e90797481..723109f1dc6 100644
--- a/lld/lib/ReaderWriter/ELF/ELFReader.h
+++ b/lld/lib/ReaderWriter/ELF/ELFReader.h
@@ -20,60 +20,25 @@
namespace lld {
namespace elf {
-template <typename ELFT, typename ContextT, template <typename> class FileT>
-class ELFReader : public Reader {
+template <typename FileT> class ELFReader : public Reader {
public:
- typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
-
- ELFReader(ContextT &ctx) : _ctx(ctx) {}
+ ELFReader(ELFLinkingContext &ctx) : _ctx(ctx) {}
bool canParse(file_magic magic, const MemoryBuffer &mb) const override {
- return (FileT<ELFT>::canParse(magic) &&
- elfHeader(mb)->e_machine == ContextT::machine);
+ return FileT::canParse(magic);
}
std::error_code
loadFile(std::unique_ptr<MemoryBuffer> mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
- const Elf_Ehdr *hdr = elfHeader(*mb);
- if (auto ec = _ctx.mergeHeaderFlags(hdr->getFileClass(), hdr->e_flags))
+ if (std::error_code ec = FileT::isCompatible(*mb, _ctx))
return ec;
- result.push_back(createELF(std::move(mb)));
+ result.push_back(llvm::make_unique<FileT>(std::move(mb), _ctx));
return std::error_code();
}
private:
- /// Create an object depending on the runtime attributes and alignment
- /// of an ELF file.
- std::unique_ptr<File> createELF(std::unique_ptr<MemoryBuffer> mb) const {
- using namespace llvm::ELF;
- using namespace llvm::support;
-
- if (uintptr_t(mb->getBufferStart()) & 1)
- llvm_unreachable("Invalid alignment for ELF file!");
- unsigned char size;
- unsigned char endian;
- std::tie(size, endian) = llvm::object::getElfArchType(mb->getBuffer());
- File *file = nullptr;
- if (size == ELFCLASS32 && endian == ELFDATA2LSB) {
- file = new FileT<ELF32LE>(std::move(mb), _ctx);
- } else if (size == ELFCLASS32 && endian == ELFDATA2MSB) {
- file = new FileT<ELF32BE>(std::move(mb), _ctx);
- } else if (size == ELFCLASS64 && endian == ELFDATA2LSB) {
- file = new FileT<ELF64LE>(std::move(mb), _ctx);
- } else if (size == ELFCLASS64 && endian == ELFDATA2MSB) {
- file = new FileT<ELF64BE>(std::move(mb), _ctx);
- }
- if (!file)
- llvm_unreachable("Invalid ELF type!");
- return std::unique_ptr<File>(file);
- }
-
- static const Elf_Ehdr *elfHeader(const MemoryBuffer &buf) {
- return reinterpret_cast<const Elf_Ehdr *>(buf.getBuffer().data());
- }
-
- ContextT &_ctx;
+ ELFLinkingContext &_ctx;
};
} // namespace elf
diff --git a/lld/lib/ReaderWriter/ELF/FileCommon.cpp b/lld/lib/ReaderWriter/ELF/FileCommon.cpp
new file mode 100644
index 00000000000..e4a3e40282d
--- /dev/null
+++ b/lld/lib/ReaderWriter/ELF/FileCommon.cpp
@@ -0,0 +1,63 @@
+//===- lib/ReaderWriter/ELF/FileCommon.cpp --------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ELFFile.h"
+#include "FileCommon.h"
+
+using namespace llvm::ELF;
+
+namespace lld {
+namespace elf {
+
+template <>
+std::error_code checkCompatibility<ELF32LE>(unsigned char size,
+ unsigned char endian) {
+ if (size == ELFCLASS64)
+ return make_dynamic_error_code("ELF32 expected, but got ELF64");
+ if (endian == ELFDATA2MSB)
+ return make_dynamic_error_code(
+ "Little endian files are expected, but got a big endian file.");
+ return std::error_code();
+}
+
+template <>
+std::error_code checkCompatibility<ELF32BE>(unsigned char size,
+ unsigned char endian) {
+ if (size == ELFCLASS64)
+ return make_dynamic_error_code("ELF32 expected, but got ELF64");
+ if (endian == ELFDATA2LSB)
+ return make_dynamic_error_code(
+ "Big endian files are expected, but got a little endian file.");
+ return std::error_code();
+}
+
+template <>
+std::error_code checkCompatibility<ELF64LE>(unsigned char size,
+ unsigned char endian) {
+ if (size == ELFCLASS32)
+ return make_dynamic_error_code("ELF64 expected, but got ELF32");
+ if (endian == ELFDATA2MSB)
+ return make_dynamic_error_code(
+ "Little endian files are expected, but got a big endian file.");
+ return std::error_code();
+}
+
+template <>
+std::error_code checkCompatibility<ELF64BE>(unsigned char size,
+ unsigned char endian) {
+ if (size == ELFCLASS32)
+ return make_dynamic_error_code("ELF64 expected, but got ELF32");
+ if (endian == ELFDATA2LSB)
+ return make_dynamic_error_code(
+ "Big endian files are expected, but got a little endian file.");
+ return std::error_code();
+}
+
+} // end namespace elf
+} // end namespace lld
diff --git a/lld/lib/ReaderWriter/ELF/FileCommon.h b/lld/lib/ReaderWriter/ELF/FileCommon.h
new file mode 100644
index 00000000000..16d783670e0
--- /dev/null
+++ b/lld/lib/ReaderWriter/ELF/FileCommon.h
@@ -0,0 +1,48 @@
+//===- lib/ReaderWriter/ELF/FileCommon.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_FILE_COMMON_H
+#define LLD_READER_WRITER_ELF_FILE_COMMON_H
+
+#include "lld/ReaderWriter/ELFLinkingContext.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ELF.h"
+
+namespace lld {
+namespace elf {
+
+template <class ELFT>
+std::error_code checkCompatibility(unsigned char size, unsigned char endian);
+
+template <typename ELFT>
+std::error_code isCompatible(const MemoryBuffer &mb, ELFLinkingContext &ctx) {
+ typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
+
+ if (uintptr_t(mb.getBufferStart()) & 1)
+ return make_dynamic_error_code("invalid alignment");
+
+ auto *hdr = reinterpret_cast<const Elf_Ehdr *>(mb.getBuffer().data());
+ if (hdr->e_machine != ctx.getMachineType())
+ return make_dynamic_error_code("incompatible machine type");
+
+ unsigned char size;
+ unsigned char endian;
+ std::tie(size, endian) = llvm::object::getElfArchType(mb.getBuffer());
+ if (std::error_code ec = checkCompatibility<ELFT>(size, endian))
+ return ec;
+
+ if (auto ec = ctx.mergeHeaderFlags(hdr->getFileClass(), hdr->e_flags))
+ return ec;
+ return std::error_code();
+}
+
+} // end namespace elf
+} // end namespace lld
+
+#endif
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
index 0e049d97de3..dc6fa4e3212 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
@@ -108,7 +108,7 @@ template <class ELFT> class HexagonELFFile : public ELFFile<ELFT> {
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
public:
- HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, HexagonLinkingContext &ctx)
+ HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx)
: ELFFile<ELFT>(std::move(mb), ctx) {}
bool isCommonSymbol(const Elf_Sym *symbol) const override {
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
index ae66556024e..02ce5c5612a 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
@@ -20,7 +20,7 @@ namespace elf {
class HexagonLinkingContext final : public ELFLinkingContext {
public:
- static const int machine = llvm::ELF::EM_HEXAGON;
+ int getMachineType() const override { return llvm::ELF::EM_HEXAGON; }
HexagonLinkingContext(llvm::Triple triple);
void addPasses(PassManager &) override;
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
index e68243cda2f..3b92c343240 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
@@ -109,8 +109,8 @@ private:
/// \brief TargetHandler for Hexagon
class HexagonTargetHandler final : public TargetHandler {
- typedef ELFReader<ELF32LE, HexagonLinkingContext, HexagonELFFile> ObjReader;
- typedef ELFReader<ELF32LE, HexagonLinkingContext, DynamicFile> ELFDSOReader;
+ typedef ELFReader<HexagonELFFile<ELF32LE>> ObjReader;
+ typedef ELFReader<DynamicFile<ELF32LE>> ELFDSOReader;
public:
HexagonTargetHandler(HexagonLinkingContext &targetInfo);
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
index f0e988d0517..0780b65e8c4 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
@@ -88,7 +88,7 @@ private:
template <class ELFT> class MipsELFFile : public ELFFile<ELFT> {
public:
- MipsELFFile(std::unique_ptr<MemoryBuffer> mb, MipsLinkingContext &ctx)
+ MipsELFFile(std::unique_ptr<MemoryBuffer> mb, ELFLinkingContext &ctx)
: ELFFile<ELFT>(std::move(mb), ctx) {}
bool isPIC() const {
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp
index 2cae3477786..d9e01d3483b 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp
@@ -66,11 +66,6 @@ uint32_t MipsELFFlagsMerger::getMergedELFFlags() const { return _flags; }
std::error_code MipsELFFlagsMerger::mergeHeaderFlags(uint8_t newClass,
uint32_t newFlags) {
- // Check bitness.
- if (_is64Bit != (newClass == ELFCLASS64))
- return make_dynamic_error_code(
- "Bitness is incompatible with that of the selected target");
-
// We support two ABI: O32 and N64. The last one does not have
// the corresponding ELF flag.
uint32_t inAbi = newFlags & EF_MIPS_ABI;
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
index 7f56b115b5a..3c45015f420 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
@@ -39,7 +39,7 @@ enum {
class MipsLinkingContext final : public ELFLinkingContext {
public:
- static const int machine = llvm::ELF::EM_MIPS;
+ int getMachineType() const override { return llvm::ELF::EM_MIPS; }
MipsLinkingContext(llvm::Triple triple);
std::error_code mergeHeaderFlags(uint8_t fileClass, uint64_t flags) override;
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
index 271dad442ce..6459eb4defe 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
@@ -22,8 +22,8 @@ namespace elf {
/// \brief TargetHandler for Mips
template <class ELFT> class MipsTargetHandler final : public TargetHandler {
- typedef ELFReader<ELFT, MipsLinkingContext, MipsELFFile> ObjReader;
- typedef ELFReader<ELFT, MipsLinkingContext, DynamicFile> DSOReader;
+ typedef ELFReader<MipsELFFile<ELFT>> ObjReader;
+ typedef ELFReader<DynamicFile<ELFT>> DSOReader;
public:
MipsTargetHandler(MipsLinkingContext &ctx)
diff --git a/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h b/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
index 5833056e2a6..f6ab3e980d7 100644
--- a/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
@@ -19,7 +19,7 @@ namespace elf {
class X86LinkingContext final : public ELFLinkingContext {
public:
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
- static const int machine = llvm::ELF::EM_386;
+ int getMachineType() const override { return llvm::ELF::EM_386; }
X86LinkingContext(llvm::Triple);
void registerRelocationNames(Registry &r) override;
diff --git a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h
index 41cdee4ad4b..b8fb66445e1 100644
--- a/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetHandler.h
@@ -20,8 +20,8 @@ namespace elf {
class X86LinkingContext;
class X86TargetHandler final : public TargetHandler {
- typedef ELFReader<ELF32LE, X86LinkingContext, ELFFile> ObjReader;
- typedef ELFReader<ELF32LE, X86LinkingContext, DynamicFile> DSOReader;
+ typedef ELFReader<ELFFile<ELF32LE>> ObjReader;
+ typedef ELFReader<DynamicFile<ELF32LE>> DSOReader;
public:
X86TargetHandler(X86LinkingContext &ctx);
diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
index d1a129a9bbb..a5a7b3d21f4 100644
--- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
+++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
@@ -30,7 +30,7 @@ protected:
public:
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
- static const int machine = llvm::ELF::EM_X86_64;
+ int getMachineType() const override { return llvm::ELF::EM_X86_64; }
X86_64LinkingContext(llvm::Triple);
void addPasses(PassManager &) override;
diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
index 6553898e8fe..12724f1a8a4 100644
--- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
@@ -58,9 +58,8 @@ private:
};
class X86_64TargetHandler : public TargetHandler {
- typedef llvm::object::ELFType<llvm::support::little, 2, true> ELFT;
- typedef ELFReader<ELFT, X86_64LinkingContext, ELFFile> ObjReader;
- typedef ELFReader<ELFT, X86_64LinkingContext, DynamicFile> DSOReader;
+ typedef ELFReader<ELFFile<ELF64LE>> ObjReader;
+ typedef ELFReader<DynamicFile<ELF64LE>> DSOReader;
public:
X86_64TargetHandler(X86_64LinkingContext &ctx);
OpenPOWER on IntegriCloud