ELF: Remove a template parameter from ELF{Object,DOS}Reader constructors.
There is one-to-one correspondence between ELF machine type and a LinkingContext. We passed them as separate arguments to the constructor. This patch is to teach the LinkingContexts about their machine types, so that we don't need to pass that data as separate arguments. llvm-svn: 233894
This commit is contained in:
parent
dfb02a9e0d
commit
b965ac5dc9
|
|
@ -34,15 +34,14 @@ class AArch64ELFObjectReader
|
|||
public:
|
||||
AArch64ELFObjectReader(AArch64LinkingContext &ctx)
|
||||
: ELFObjectReader<AArch64ELFType, AArch64ELFFileCreateELFTraits,
|
||||
AArch64LinkingContext>(ctx, llvm::ELF::EM_AARCH64) {}
|
||||
AArch64LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
class AArch64ELFDSOReader
|
||||
: public ELFDSOReader<AArch64ELFType, AArch64LinkingContext> {
|
||||
public:
|
||||
AArch64ELFDSOReader(AArch64LinkingContext &ctx)
|
||||
: ELFDSOReader<AArch64ELFType,
|
||||
AArch64LinkingContext>(ctx, llvm::ELF::EM_AARCH64) {}
|
||||
: ELFDSOReader<AArch64ELFType, AArch64LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ enum {
|
|||
class AArch64LinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
|
||||
static const int machine = llvm::ELF::EM_AARCH64;
|
||||
AArch64LinkingContext(llvm::Triple);
|
||||
|
||||
void addPasses(PassManager &) override;
|
||||
|
|
|
|||
|
|
@ -34,14 +34,14 @@ class ARMELFObjectReader
|
|||
public:
|
||||
ARMELFObjectReader(ARMLinkingContext &ctx)
|
||||
: ELFObjectReader<ARMELFType, ARMELFFileCreateELFTraits,
|
||||
ARMLinkingContext>(ctx, llvm::ELF::EM_ARM) {}
|
||||
ARMLinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
class ARMELFDSOReader
|
||||
: public ELFDSOReader<ARMELFType, ARMLinkingContext> {
|
||||
public:
|
||||
ARMELFDSOReader(ARMLinkingContext &ctx)
|
||||
: ELFDSOReader<ARMELFType, ARMLinkingContext>(ctx, llvm::ELF::EM_ARM) {}
|
||||
: ELFDSOReader<ARMELFType, ARMLinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace elf {
|
|||
class ARMLinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
|
||||
static const int machine = llvm::ELF::EM_ARM;
|
||||
ARMLinkingContext(llvm::Triple);
|
||||
|
||||
void addPasses(PassManager &) override;
|
||||
|
|
|
|||
|
|
@ -23,13 +23,12 @@ class ELFObjectReader : public Reader {
|
|||
public:
|
||||
typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
|
||||
|
||||
ELFObjectReader(ContextT &ctx, uint64_t machine)
|
||||
: _ctx(ctx), _machine(machine) {}
|
||||
ELFObjectReader(ContextT &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &buf) const override {
|
||||
return (magic == llvm::sys::fs::file_magic::elf_relocatable &&
|
||||
elfHeader(buf)->e_machine == _machine);
|
||||
elfHeader(buf)->e_machine == ContextT::machine);
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
|
@ -54,7 +53,6 @@ public:
|
|||
|
||||
protected:
|
||||
ContextT &_ctx;
|
||||
uint64_t _machine;
|
||||
};
|
||||
|
||||
struct DynamicFileCreateELFTraits {
|
||||
|
|
@ -72,13 +70,12 @@ class ELFDSOReader : public Reader {
|
|||
public:
|
||||
typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
|
||||
|
||||
ELFDSOReader(ContextT &ctx, uint64_t machine)
|
||||
: _ctx(ctx), _machine(machine) {}
|
||||
ELFDSOReader(ContextT &ctx) : _ctx(ctx) {}
|
||||
|
||||
bool canParse(file_magic magic, StringRef,
|
||||
const MemoryBuffer &buf) const override {
|
||||
return (magic == llvm::sys::fs::file_magic::elf_shared_object &&
|
||||
elfHeader(buf)->e_machine == _machine);
|
||||
elfHeader(buf)->e_machine == ContextT::machine);
|
||||
}
|
||||
|
||||
std::error_code
|
||||
|
|
@ -103,7 +100,6 @@ public:
|
|||
|
||||
protected:
|
||||
ContextT &_ctx;
|
||||
uint64_t _machine;
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -34,15 +34,14 @@ class HexagonELFObjectReader
|
|||
public:
|
||||
HexagonELFObjectReader(HexagonLinkingContext &ctx)
|
||||
: ELFObjectReader<HexagonELFType, HexagonELFFileCreateELFTraits,
|
||||
HexagonLinkingContext>(ctx, llvm::ELF::EM_HEXAGON) {}
|
||||
HexagonLinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
class HexagonELFDSOReader
|
||||
: public ELFDSOReader<HexagonELFType, HexagonLinkingContext> {
|
||||
public:
|
||||
HexagonELFDSOReader(HexagonLinkingContext &ctx)
|
||||
: ELFDSOReader<HexagonELFType,
|
||||
HexagonLinkingContext>(ctx, llvm::ELF::EM_HEXAGON) {}
|
||||
: ELFDSOReader<HexagonELFType, HexagonLinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ typedef llvm::object::ELFType<llvm::support::little, 2, false> HexagonELFType;
|
|||
class HexagonLinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
|
||||
static const int machine = llvm::ELF::EM_HEXAGON;
|
||||
HexagonLinkingContext(llvm::Triple triple);
|
||||
|
||||
void addPasses(PassManager &) override;
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ class MipsELFObjectReader
|
|||
|
||||
public:
|
||||
MipsELFObjectReader(MipsLinkingContext &ctx)
|
||||
: BaseReaderType(ctx, llvm::ELF::EM_MIPS),
|
||||
_flagMerger(ctx.getELFFlagsMerger()) {}
|
||||
: BaseReaderType(ctx), _flagMerger(ctx.getELFFlagsMerger()) {}
|
||||
|
||||
std::error_code
|
||||
loadFile(std::unique_ptr<MemoryBuffer> mb, const Registry ®istry,
|
||||
|
|
@ -58,8 +57,7 @@ class MipsELFDSOReader : public ELFDSOReader<ELFT, MipsLinkingContext> {
|
|||
|
||||
public:
|
||||
MipsELFDSOReader(MipsLinkingContext &ctx)
|
||||
: BaseReaderType(ctx, llvm::ELF::EM_MIPS),
|
||||
_flagMerger(ctx.getELFFlagsMerger()) {}
|
||||
: BaseReaderType(ctx), _flagMerger(ctx.getELFFlagsMerger()) {}
|
||||
|
||||
std::error_code
|
||||
loadFile(std::unique_ptr<MemoryBuffer> mb, const Registry ®istry,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ typedef llvm::object::ELFType<llvm::support::big, 2, true> Mips64BEType;
|
|||
class MipsLinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
|
||||
static const int machine = llvm::ELF::EM_MIPS;
|
||||
MipsLinkingContext(llvm::Triple triple);
|
||||
|
||||
uint32_t getMergedELFFlags() const;
|
||||
|
|
|
|||
|
|
@ -34,15 +34,14 @@ class X86ELFObjectReader
|
|||
public:
|
||||
X86ELFObjectReader(X86LinkingContext &ctx)
|
||||
: ELFObjectReader<X86ELFType, X86ELFFileCreateELFTraits,
|
||||
X86LinkingContext>(ctx, llvm::ELF::EM_386) {}
|
||||
X86LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
class X86ELFDSOReader
|
||||
: public ELFDSOReader<X86ELFType, X86LinkingContext> {
|
||||
public:
|
||||
X86ELFDSOReader(X86LinkingContext &ctx)
|
||||
: ELFDSOReader<X86ELFType,
|
||||
X86LinkingContext>(ctx, llvm::ELF::EM_386) {}
|
||||
: ELFDSOReader<X86ELFType, X86LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -19,6 +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;
|
||||
X86LinkingContext(llvm::Triple);
|
||||
void registerRelocationNames(Registry &r) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,15 +34,14 @@ class X86_64ELFObjectReader
|
|||
public:
|
||||
X86_64ELFObjectReader(X86_64LinkingContext &ctx)
|
||||
: ELFObjectReader<X86_64ELFType, X86_64ELFFileCreateELFTraits,
|
||||
X86_64LinkingContext>(ctx, llvm::ELF::EM_X86_64) {}
|
||||
X86_64LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
class X86_64ELFDSOReader
|
||||
: public ELFDSOReader<X86_64ELFType, X86_64LinkingContext> {
|
||||
public:
|
||||
X86_64ELFDSOReader(X86_64LinkingContext &ctx)
|
||||
: ELFDSOReader<X86_64ELFType,
|
||||
X86_64LinkingContext>(ctx, llvm::ELF::EM_X86_64) {}
|
||||
: ELFDSOReader<X86_64ELFType, X86_64LinkingContext>(ctx) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ protected:
|
|||
|
||||
public:
|
||||
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
|
||||
static const int machine = llvm::ELF::EM_X86_64;
|
||||
X86_64LinkingContext(llvm::Triple);
|
||||
|
||||
void addPasses(PassManager &) override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue