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:
Rui Ueyama 2015-04-02 05:19:36 +00:00
parent dfb02a9e0d
commit b965ac5dc9
13 changed files with 22 additions and 26 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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 &registry,
@ -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 &registry,

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;