forked from OSchip/llvm-project
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:
parent
c09b854f6b
commit
1ad4095d6b
|
@ -12,23 +12,37 @@
|
|||
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
#include "llvm/Support/ELF.h"
|
||||
|
||||
namespace llvm {
|
||||
class MCELFObjectTargetWriter {
|
||||
const Triple::OSType OSType;
|
||||
const uint8_t OSABI;
|
||||
const uint16_t EMachine;
|
||||
const unsigned HasRelocationAddend : 1;
|
||||
const unsigned Is64Bit : 1;
|
||||
|
||||
protected:
|
||||
MCELFObjectTargetWriter(bool Is64Bit_, Triple::OSType OSType_,
|
||||
|
||||
MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
|
||||
uint16_t EMachine_, bool HasRelocationAddend_);
|
||||
|
||||
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();
|
||||
|
||||
/// @name Accessors
|
||||
/// @{
|
||||
Triple::OSType getOSType() { return OSType; }
|
||||
uint8_t getOSABI() { return OSABI; }
|
||||
uint16_t getEMachine() { return EMachine; }
|
||||
bool hasRelocationAddend() { return HasRelocationAddend; }
|
||||
bool is64Bit() const { return Is64Bit; }
|
||||
|
|
|
@ -93,11 +93,7 @@ void ELFObjectWriter::WriteHeader(uint64_t SectionDataSize,
|
|||
|
||||
Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
|
||||
// e_ident[EI_OSABI]
|
||||
switch (TargetObjectWriter->getOSType()) {
|
||||
case Triple::FreeBSD: Write8(ELF::ELFOSABI_FREEBSD); break;
|
||||
case Triple::Linux: Write8(ELF::ELFOSABI_LINUX); break;
|
||||
default: Write8(ELF::ELFOSABI_NONE); break;
|
||||
}
|
||||
Write8(TargetObjectWriter->getOSABI());
|
||||
Write8(0); // e_ident[EI_ABIVERSION]
|
||||
|
||||
WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
using namespace llvm;
|
||||
|
||||
MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_,
|
||||
Triple::OSType OSType_,
|
||||
uint8_t OSABI_,
|
||||
uint16_t EMachine_,
|
||||
bool HasRelocationAddend_)
|
||||
: OSType(OSType_), EMachine(EMachine_),
|
||||
: OSABI(OSABI_), EMachine(EMachine_),
|
||||
HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) {
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ using namespace llvm;
|
|||
namespace {
|
||||
class ARMELFObjectWriter : public MCELFObjectTargetWriter {
|
||||
public:
|
||||
ARMELFObjectWriter(Triple::OSType OSType)
|
||||
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSType, ELF::EM_ARM,
|
||||
ARMELFObjectWriter(uint8_t OSABI)
|
||||
: MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_ARM,
|
||||
/*HasRelocationAddend*/ false) {}
|
||||
};
|
||||
|
||||
|
@ -447,16 +447,16 @@ namespace {
|
|||
// ELF is an ELF of course...
|
||||
class ELFARMAsmBackend : public ARMAsmBackend {
|
||||
public:
|
||||
Triple::OSType OSType;
|
||||
uint8_t OSABI;
|
||||
ELFARMAsmBackend(const Target &T, const StringRef TT,
|
||||
Triple::OSType _OSType)
|
||||
: ARMAsmBackend(T, TT), OSType(_OSType) { }
|
||||
uint8_t _OSABI)
|
||||
: ARMAsmBackend(T, TT), OSABI(_OSABI) { }
|
||||
|
||||
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
||||
uint64_t Value) const;
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(new ARMELFObjectWriter(OSType), OS,
|
||||
return createELFObjectWriter(new ARMELFObjectWriter(OSABI), OS,
|
||||
/*IsLittleEndian*/ true);
|
||||
}
|
||||
};
|
||||
|
@ -580,5 +580,6 @@ MCAsmBackend *llvm::createARMAsmBackend(const Target &T, StringRef TT) {
|
|||
if (TheTriple.isOSWindows())
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ static unsigned getFixupKindSize(unsigned Kind) {
|
|||
namespace {
|
||||
class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
|
||||
public:
|
||||
MBlazeELFObjectWriter(Triple::OSType OSType)
|
||||
: MCELFObjectTargetWriter(/*is64Bit*/ false, OSType, ELF::EM_MBLAZE,
|
||||
MBlazeELFObjectWriter(uint8_t OSABI)
|
||||
: MCELFObjectTargetWriter(/*is64Bit*/ false, OSABI, ELF::EM_MBLAZE,
|
||||
/*HasRelocationAddend*/ true) {}
|
||||
};
|
||||
|
||||
|
@ -123,15 +123,15 @@ bool MBlazeAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
|
|||
namespace {
|
||||
class ELFMBlazeAsmBackend : public MBlazeAsmBackend {
|
||||
public:
|
||||
Triple::OSType OSType;
|
||||
ELFMBlazeAsmBackend(const Target &T, Triple::OSType _OSType)
|
||||
: MBlazeAsmBackend(T), OSType(_OSType) { }
|
||||
uint8_t OSABI;
|
||||
ELFMBlazeAsmBackend(const Target &T, uint8_t _OSABI)
|
||||
: MBlazeAsmBackend(T), OSABI(_OSABI) { }
|
||||
|
||||
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
||||
uint64_t Value) const;
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(new MBlazeELFObjectWriter(OSType), OS,
|
||||
return createELFObjectWriter(new MBlazeELFObjectWriter(OSABI), OS,
|
||||
/*IsLittleEndian*/ false);
|
||||
}
|
||||
};
|
||||
|
@ -172,5 +172,6 @@ MCAsmBackend *llvm::createMBlazeAsmBackend(const Target &T, StringRef TT) {
|
|||
if (TheTriple.isOSWindows())
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ namespace {
|
|||
|
||||
class MipsELFObjectWriter : public MCELFObjectTargetWriter {
|
||||
public:
|
||||
MipsELFObjectWriter(bool is64Bit, Triple::OSType OSType, uint16_t EMachine,
|
||||
MipsELFObjectWriter(bool is64Bit, uint8_t OSABI, uint16_t EMachine,
|
||||
bool HasRelocationAddend)
|
||||
: MCELFObjectTargetWriter(is64Bit, OSType, EMachine,
|
||||
: MCELFObjectTargetWriter(is64Bit, OSABI, EMachine,
|
||||
HasRelocationAddend) {}
|
||||
};
|
||||
|
||||
|
@ -197,10 +197,10 @@ public:
|
|||
|
||||
class MipsEB_AsmBackend : public MipsAsmBackend {
|
||||
public:
|
||||
Triple::OSType OSType;
|
||||
uint8_t OSABI;
|
||||
|
||||
MipsEB_AsmBackend(const Target &T, Triple::OSType _OSType)
|
||||
: MipsAsmBackend(T), OSType(_OSType) {}
|
||||
MipsEB_AsmBackend(const Target &T, uint8_t _OSABI)
|
||||
: MipsAsmBackend(T), OSABI(_OSABI) {}
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(createELFObjectTargetWriter(),
|
||||
|
@ -208,16 +208,16 @@ public:
|
|||
}
|
||||
|
||||
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 {
|
||||
public:
|
||||
Triple::OSType OSType;
|
||||
uint8_t OSABI;
|
||||
|
||||
MipsEL_AsmBackend(const Target &T, Triple::OSType _OSType)
|
||||
: MipsAsmBackend(T), OSType(_OSType) {}
|
||||
MipsEL_AsmBackend(const Target &T, uint8_t _OSABI)
|
||||
: MipsAsmBackend(T), OSABI(_OSABI) {}
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(createELFObjectTargetWriter(),
|
||||
|
@ -225,7 +225,7 @@ public:
|
|||
}
|
||||
|
||||
MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
|
||||
return new MipsELFObjectWriter(false, OSType, ELF::EM_MIPS, false);
|
||||
return new MipsELFObjectWriter(false, OSABI, ELF::EM_MIPS, false);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
@ -235,5 +235,6 @@ MCAsmBackend *llvm::createMipsAsmBackend(const Target &T, StringRef TT) {
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -59,9 +59,9 @@ public:
|
|||
|
||||
class PPCELFObjectWriter : public MCELFObjectTargetWriter {
|
||||
public:
|
||||
PPCELFObjectWriter(bool Is64Bit, Triple::OSType OSType, uint16_t EMachine,
|
||||
PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI, uint16_t EMachine,
|
||||
bool HasRelocationAddend, bool isLittleEndian)
|
||||
: MCELFObjectTargetWriter(Is64Bit, OSType, EMachine, HasRelocationAddend) {}
|
||||
: MCELFObjectTargetWriter(Is64Bit, OSABI, EMachine, HasRelocationAddend) {}
|
||||
};
|
||||
|
||||
class PPCAsmBackend : public MCAsmBackend {
|
||||
|
@ -154,10 +154,10 @@ namespace {
|
|||
};
|
||||
|
||||
class ELFPPCAsmBackend : public PPCAsmBackend {
|
||||
Triple::OSType OSType;
|
||||
uint8_t OSABI;
|
||||
public:
|
||||
ELFPPCAsmBackend(const Target &T, Triple::OSType OSType) :
|
||||
PPCAsmBackend(T), OSType(OSType) { }
|
||||
ELFPPCAsmBackend(const Target &T, uint8_t OSABI) :
|
||||
PPCAsmBackend(T), OSABI(OSABI) { }
|
||||
|
||||
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
||||
uint64_t Value) const {
|
||||
|
@ -177,7 +177,7 @@ namespace {
|
|||
bool is64 = getPointerSize() == 8;
|
||||
return createELFObjectWriter(new PPCELFObjectWriter(
|
||||
/*Is64Bit=*/is64,
|
||||
OSType,
|
||||
OSABI,
|
||||
is64 ? ELF::EM_PPC64 : ELF::EM_PPC,
|
||||
/*addend*/ true, /*isLittleEndian*/ false),
|
||||
OS, /*IsLittleEndian=*/false);
|
||||
|
@ -197,5 +197,6 @@ MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, StringRef TT) {
|
|||
if (Triple(TT).isOSDarwin())
|
||||
return new DarwinPPCAsmBackend(T);
|
||||
|
||||
return new ELFPPCAsmBackend(T, Triple(TT).getOS());
|
||||
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
|
||||
return new ELFPPCAsmBackend(T, OSABI);
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ namespace {
|
|||
|
||||
class X86ELFObjectWriter : public MCELFObjectTargetWriter {
|
||||
public:
|
||||
X86ELFObjectWriter(bool is64Bit, Triple::OSType OSType, uint16_t EMachine,
|
||||
bool HasRelocationAddend)
|
||||
: MCELFObjectTargetWriter(is64Bit, OSType, EMachine, HasRelocationAddend) {}
|
||||
X86ELFObjectWriter(bool is64Bit, uint8_t OSABI, uint16_t EMachine,
|
||||
bool HasRelocationAddend, bool foobar)
|
||||
: MCELFObjectTargetWriter(is64Bit, OSABI, EMachine, HasRelocationAddend) {}
|
||||
};
|
||||
|
||||
class X86AsmBackend : public MCAsmBackend {
|
||||
|
@ -325,9 +325,9 @@ bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
|
|||
namespace {
|
||||
class ELFX86AsmBackend : public X86AsmBackend {
|
||||
public:
|
||||
Triple::OSType OSType;
|
||||
ELFX86AsmBackend(const Target &T, Triple::OSType _OSType)
|
||||
: X86AsmBackend(T), OSType(_OSType) {
|
||||
uint8_t OSABI;
|
||||
ELFX86AsmBackend(const Target &T, uint8_t _OSABI)
|
||||
: X86AsmBackend(T), OSABI(_OSABI) {
|
||||
HasReliableSymbolDifference = true;
|
||||
}
|
||||
|
||||
|
@ -339,8 +339,8 @@ public:
|
|||
|
||||
class ELFX86_32AsmBackend : public ELFX86AsmBackend {
|
||||
public:
|
||||
ELFX86_32AsmBackend(const Target &T, Triple::OSType OSType)
|
||||
: ELFX86AsmBackend(T, OSType) {}
|
||||
ELFX86_32AsmBackend(const Target &T, uint8_t OSABI)
|
||||
: ELFX86AsmBackend(T, OSABI) {}
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(createELFObjectTargetWriter(),
|
||||
|
@ -348,14 +348,14 @@ public:
|
|||
}
|
||||
|
||||
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 {
|
||||
public:
|
||||
ELFX86_64AsmBackend(const Target &T, Triple::OSType OSType)
|
||||
: ELFX86AsmBackend(T, OSType) {}
|
||||
ELFX86_64AsmBackend(const Target &T, uint8_t OSABI)
|
||||
: ELFX86AsmBackend(T, OSABI) {}
|
||||
|
||||
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
|
||||
return createELFObjectWriter(createELFObjectTargetWriter(),
|
||||
|
@ -363,7 +363,7 @@ public:
|
|||
}
|
||||
|
||||
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())
|
||||
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) {
|
||||
|
@ -469,5 +470,6 @@ MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT) {
|
|||
if (TheTriple.isOSWindows())
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue