Reduce the exposure of Triple::OSType in the ELF object writer. This will

avoid including ADT/Triple.h in many places when the target specific bits are
moved.

llvm-svn: 147059
This commit is contained in:
Rafael Espindola 2011-12-21 17:00:36 +00:00
parent c09b854f6b
commit 1ad4095d6b
8 changed files with 72 additions and 56 deletions

View File

@ -12,23 +12,37 @@
#include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCObjectWriter.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/ELF.h"
namespace llvm { namespace llvm {
class MCELFObjectTargetWriter { class MCELFObjectTargetWriter {
const Triple::OSType OSType; const uint8_t OSABI;
const uint16_t EMachine; const uint16_t EMachine;
const unsigned HasRelocationAddend : 1; const unsigned HasRelocationAddend : 1;
const unsigned Is64Bit : 1; const unsigned Is64Bit : 1;
protected: protected:
MCELFObjectTargetWriter(bool Is64Bit_, Triple::OSType OSType_,
MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
uint16_t EMachine_, bool HasRelocationAddend_); uint16_t EMachine_, bool HasRelocationAddend_);
public: public:
static uint8_t getOSABI(Triple::OSType OSType) {
switch (OSType) {
case Triple::FreeBSD:
return ELF::ELFOSABI_FREEBSD;
case Triple::Linux:
return ELF::ELFOSABI_LINUX;
default:
return ELF::ELFOSABI_NONE;
}
}
virtual ~MCELFObjectTargetWriter(); virtual ~MCELFObjectTargetWriter();
/// @name Accessors /// @name Accessors
/// @{ /// @{
Triple::OSType getOSType() { return OSType; } uint8_t getOSABI() { return OSABI; }
uint16_t getEMachine() { return EMachine; } uint16_t getEMachine() { return EMachine; }
bool hasRelocationAddend() { return HasRelocationAddend; } bool hasRelocationAddend() { return HasRelocationAddend; }
bool is64Bit() const { return Is64Bit; } bool is64Bit() const { return Is64Bit; }

View File

@ -93,11 +93,7 @@ void ELFObjectWriter::WriteHeader(uint64_t SectionDataSize,
Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION] Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
// e_ident[EI_OSABI] // e_ident[EI_OSABI]
switch (TargetObjectWriter->getOSType()) { Write8(TargetObjectWriter->getOSABI());
case Triple::FreeBSD: Write8(ELF::ELFOSABI_FREEBSD); break;
case Triple::Linux: Write8(ELF::ELFOSABI_LINUX); break;
default: Write8(ELF::ELFOSABI_NONE); break;
}
Write8(0); // e_ident[EI_ABIVERSION] Write8(0); // e_ident[EI_ABIVERSION]
WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD); WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);

View File

@ -12,10 +12,10 @@
using namespace llvm; using namespace llvm;
MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_, MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_,
Triple::OSType OSType_, uint8_t OSABI_,
uint16_t EMachine_, uint16_t EMachine_,
bool HasRelocationAddend_) bool HasRelocationAddend_)
: OSType(OSType_), EMachine(EMachine_), : OSABI(OSABI_), EMachine(EMachine_),
HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) { HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) {
} }

View File

@ -31,8 +31,8 @@ using namespace llvm;
namespace { namespace {
class ARMELFObjectWriter : public MCELFObjectTargetWriter { class ARMELFObjectWriter : public MCELFObjectTargetWriter {
public: public:
ARMELFObjectWriter(Triple::OSType OSType) ARMELFObjectWriter(uint8_t OSABI)
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSType, ELF::EM_ARM, : MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_ARM,
/*HasRelocationAddend*/ false) {} /*HasRelocationAddend*/ false) {}
}; };
@ -447,16 +447,16 @@ namespace {
// ELF is an ELF of course... // ELF is an ELF of course...
class ELFARMAsmBackend : public ARMAsmBackend { class ELFARMAsmBackend : public ARMAsmBackend {
public: public:
Triple::OSType OSType; uint8_t OSABI;
ELFARMAsmBackend(const Target &T, const StringRef TT, ELFARMAsmBackend(const Target &T, const StringRef TT,
Triple::OSType _OSType) uint8_t _OSABI)
: ARMAsmBackend(T, TT), OSType(_OSType) { } : ARMAsmBackend(T, TT), OSABI(_OSABI) { }
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
uint64_t Value) const; uint64_t Value) const;
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(new ARMELFObjectWriter(OSType), OS, return createELFObjectWriter(new ARMELFObjectWriter(OSABI), OS,
/*IsLittleEndian*/ true); /*IsLittleEndian*/ true);
} }
}; };
@ -580,5 +580,6 @@ MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT) {
if (TheTriple.isOSWindows()) if (TheTriple.isOSWindows())
assert(0 && "Windows not supported on ARM"); assert(0 && "Windows not supported on ARM");
return new ELFARMAsmBackend(T, TT, Triple(TT).getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
return new ELFARMAsmBackend(T, TT, OSABI);
} }

View File

@ -41,8 +41,8 @@ static unsigned getFixupKindSize(unsigned Kind) {
namespace { namespace {
class MBlazeELFObjectWriter : public MCELFObjectTargetWriter { class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
public: public:
MBlazeELFObjectWriter(Triple::OSType OSType) MBlazeELFObjectWriter(uint8_t OSABI)
: MCELFObjectTargetWriter(/*is64Bit*/ false, OSType, ELF::EM_MBLAZE, : MCELFObjectTargetWriter(/*is64Bit*/ false, OSABI, ELF::EM_MBLAZE,
/*HasRelocationAddend*/ true) {} /*HasRelocationAddend*/ true) {}
}; };
@ -123,15 +123,15 @@ bool MBlazeAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
namespace { namespace {
class ELFMBlazeAsmBackend : public MBlazeAsmBackend { class ELFMBlazeAsmBackend : public MBlazeAsmBackend {
public: public:
Triple::OSType OSType; uint8_t OSABI;
ELFMBlazeAsmBackend(const Target &T, Triple::OSType _OSType) ELFMBlazeAsmBackend(const Target &T, uint8_t _OSABI)
: MBlazeAsmBackend(T), OSType(_OSType) { } : MBlazeAsmBackend(T), OSABI(_OSABI) { }
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
uint64_t Value) const; uint64_t Value) const;
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(new MBlazeELFObjectWriter(OSType), OS, return createELFObjectWriter(new MBlazeELFObjectWriter(OSABI), OS,
/*IsLittleEndian*/ false); /*IsLittleEndian*/ false);
} }
}; };
@ -172,5 +172,6 @@ MCAsmBackend *llvm::createMBlazeAsmBackend(const Target &T, StringRef TT) {
if (TheTriple.isOSWindows()) if (TheTriple.isOSWindows())
assert(0 && "Windows not supported on MBlaze"); assert(0 && "Windows not supported on MBlaze");
return new ELFMBlazeAsmBackend(T, TheTriple.getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
return new ELFMBlazeAsmBackend(T, OSABI);
} }

View File

@ -72,9 +72,9 @@ namespace {
class MipsELFObjectWriter : public MCELFObjectTargetWriter { class MipsELFObjectWriter : public MCELFObjectTargetWriter {
public: public:
MipsELFObjectWriter(bool is64Bit, Triple::OSType OSType, uint16_t EMachine, MipsELFObjectWriter(bool is64Bit, uint8_t OSABI, uint16_t EMachine,
bool HasRelocationAddend) bool HasRelocationAddend)
: MCELFObjectTargetWriter(is64Bit, OSType, EMachine, : MCELFObjectTargetWriter(is64Bit, OSABI, EMachine,
HasRelocationAddend) {} HasRelocationAddend) {}
}; };
@ -197,10 +197,10 @@ public:
class MipsEB_AsmBackend : public MipsAsmBackend { class MipsEB_AsmBackend : public MipsAsmBackend {
public: public:
Triple::OSType OSType; uint8_t OSABI;
MipsEB_AsmBackend(const Target &T, Triple::OSType _OSType) MipsEB_AsmBackend(const Target &T, uint8_t _OSABI)
: MipsAsmBackend(T), OSType(_OSType) {} : MipsAsmBackend(T), OSABI(_OSABI) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(createELFObjectTargetWriter(), return createELFObjectWriter(createELFObjectTargetWriter(),
@ -208,16 +208,16 @@ public:
} }
MCELFObjectTargetWriter *createELFObjectTargetWriter() const { MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
return new MipsELFObjectWriter(false, OSType, ELF::EM_MIPS, false); return new MipsELFObjectWriter(false, OSABI, ELF::EM_MIPS, false);
} }
}; };
class MipsEL_AsmBackend : public MipsAsmBackend { class MipsEL_AsmBackend : public MipsAsmBackend {
public: public:
Triple::OSType OSType; uint8_t OSABI;
MipsEL_AsmBackend(const Target &T, Triple::OSType _OSType) MipsEL_AsmBackend(const Target &T, uint8_t _OSABI)
: MipsAsmBackend(T), OSType(_OSType) {} : MipsAsmBackend(T), OSABI(_OSABI) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(createELFObjectTargetWriter(), return createELFObjectWriter(createELFObjectTargetWriter(),
@ -225,7 +225,7 @@ public:
} }
MCELFObjectTargetWriter *createELFObjectTargetWriter() const { MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
return new MipsELFObjectWriter(false, OSType, ELF::EM_MIPS, false); return new MipsELFObjectWriter(false, OSABI, ELF::EM_MIPS, false);
} }
}; };
} // namespace } // namespace
@ -235,5 +235,6 @@ MCAsmBackend *llvm::createMipsAsmBackend(const Target &T, StringRef TT) {
// just return little endian for now // just return little endian for now
// //
return new MipsEL_AsmBackend(T, Triple(TT).getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
return new MipsEL_AsmBackend(T, OSABI);
} }

View File

@ -59,9 +59,9 @@ public:
class PPCELFObjectWriter : public MCELFObjectTargetWriter { class PPCELFObjectWriter : public MCELFObjectTargetWriter {
public: public:
PPCELFObjectWriter(bool Is64Bit, Triple::OSType OSType, uint16_t EMachine, PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI, uint16_t EMachine,
bool HasRelocationAddend, bool isLittleEndian) bool HasRelocationAddend, bool isLittleEndian)
: MCELFObjectTargetWriter(Is64Bit, OSType, EMachine, HasRelocationAddend) {} : MCELFObjectTargetWriter(Is64Bit, OSABI, EMachine, HasRelocationAddend) {}
}; };
class PPCAsmBackend : public MCAsmBackend { class PPCAsmBackend : public MCAsmBackend {
@ -154,10 +154,10 @@ namespace {
}; };
class ELFPPCAsmBackend : public PPCAsmBackend { class ELFPPCAsmBackend : public PPCAsmBackend {
Triple::OSType OSType; uint8_t OSABI;
public: public:
ELFPPCAsmBackend(const Target &T, Triple::OSType OSType) : ELFPPCAsmBackend(const Target &T, uint8_t OSABI) :
PPCAsmBackend(T), OSType(OSType) { } PPCAsmBackend(T), OSABI(OSABI) { }
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
uint64_t Value) const { uint64_t Value) const {
@ -177,7 +177,7 @@ namespace {
bool is64 = getPointerSize() == 8; bool is64 = getPointerSize() == 8;
return createELFObjectWriter(new PPCELFObjectWriter( return createELFObjectWriter(new PPCELFObjectWriter(
/*Is64Bit=*/is64, /*Is64Bit=*/is64,
OSType, OSABI,
is64 ? ELF::EM_PPC64 : ELF::EM_PPC, is64 ? ELF::EM_PPC64 : ELF::EM_PPC,
/*addend*/ true, /*isLittleEndian*/ false), /*addend*/ true, /*isLittleEndian*/ false),
OS, /*IsLittleEndian=*/false); OS, /*IsLittleEndian=*/false);
@ -197,5 +197,6 @@ MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, StringRef TT) {
if (Triple(TT).isOSDarwin()) if (Triple(TT).isOSDarwin())
return new DarwinPPCAsmBackend(T); return new DarwinPPCAsmBackend(T);
return new ELFPPCAsmBackend(T, Triple(TT).getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
return new ELFPPCAsmBackend(T, OSABI);
} }

View File

@ -58,9 +58,9 @@ namespace {
class X86ELFObjectWriter : public MCELFObjectTargetWriter { class X86ELFObjectWriter : public MCELFObjectTargetWriter {
public: public:
X86ELFObjectWriter(bool is64Bit, Triple::OSType OSType, uint16_t EMachine, X86ELFObjectWriter(bool is64Bit, uint8_t OSABI, uint16_t EMachine,
bool HasRelocationAddend) bool HasRelocationAddend, bool foobar)
: MCELFObjectTargetWriter(is64Bit, OSType, EMachine, HasRelocationAddend) {} : MCELFObjectTargetWriter(is64Bit, OSABI, EMachine, HasRelocationAddend) {}
}; };
class X86AsmBackend : public MCAsmBackend { class X86AsmBackend : public MCAsmBackend {
@ -325,9 +325,9 @@ bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
namespace { namespace {
class ELFX86AsmBackend : public X86AsmBackend { class ELFX86AsmBackend : public X86AsmBackend {
public: public:
Triple::OSType OSType; uint8_t OSABI;
ELFX86AsmBackend(const Target &T, Triple::OSType _OSType) ELFX86AsmBackend(const Target &T, uint8_t _OSABI)
: X86AsmBackend(T), OSType(_OSType) { : X86AsmBackend(T), OSABI(_OSABI) {
HasReliableSymbolDifference = true; HasReliableSymbolDifference = true;
} }
@ -339,8 +339,8 @@ public:
class ELFX86_32AsmBackend : public ELFX86AsmBackend { class ELFX86_32AsmBackend : public ELFX86AsmBackend {
public: public:
ELFX86_32AsmBackend(const Target &T, Triple::OSType OSType) ELFX86_32AsmBackend(const Target &T, uint8_t OSABI)
: ELFX86AsmBackend(T, OSType) {} : ELFX86AsmBackend(T, OSABI) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(createELFObjectTargetWriter(), return createELFObjectWriter(createELFObjectTargetWriter(),
@ -348,14 +348,14 @@ public:
} }
MCELFObjectTargetWriter *createELFObjectTargetWriter() const { MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
return new X86ELFObjectWriter(false, OSType, ELF::EM_386, false); return new X86ELFObjectWriter(false, OSABI, ELF::EM_386, false, false);
} }
}; };
class ELFX86_64AsmBackend : public ELFX86AsmBackend { class ELFX86_64AsmBackend : public ELFX86AsmBackend {
public: public:
ELFX86_64AsmBackend(const Target &T, Triple::OSType OSType) ELFX86_64AsmBackend(const Target &T, uint8_t OSABI)
: ELFX86AsmBackend(T, OSType) {} : ELFX86AsmBackend(T, OSABI) {}
MCObjectWriter *createObjectWriter(raw_ostream &OS) const { MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createELFObjectWriter(createELFObjectTargetWriter(), return createELFObjectWriter(createELFObjectTargetWriter(),
@ -363,7 +363,7 @@ public:
} }
MCELFObjectTargetWriter *createELFObjectTargetWriter() const { MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
return new X86ELFObjectWriter(true, OSType, ELF::EM_X86_64, true); return new X86ELFObjectWriter(true, OSABI, ELF::EM_X86_64, true, false);
} }
}; };
@ -457,7 +457,8 @@ MCAsmBackend *llvm::createX86_32AsmBackend(const Target &T, StringRef TT) {
if (TheTriple.isOSWindows()) if (TheTriple.isOSWindows())
return new WindowsX86AsmBackend(T, false); return new WindowsX86AsmBackend(T, false);
return new ELFX86_32AsmBackend(T, TheTriple.getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
return new ELFX86_32AsmBackend(T, OSABI);
} }
MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT) { MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT) {
@ -469,5 +470,6 @@ MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT) {
if (TheTriple.isOSWindows()) if (TheTriple.isOSWindows())
return new WindowsX86AsmBackend(T, true); return new WindowsX86AsmBackend(T, true);
return new ELFX86_64AsmBackend(T, TheTriple.getOS()); uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
return new ELFX86_64AsmBackend(T, OSABI);
} }