llvm.org GIT mirror llvm / 678c35c
Enable ELF machine type to be specified explicitly in X86 backend git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167027 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao 8 years ago
3 changed file(s) with 19 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
353353 : ELFX86AsmBackend(T, OSABI, CPU) {}
354354
355355 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
356 return createX86ELFObjectWriter(OS, /*Is64Bit*/ false, OSABI);
356 return createX86ELFObjectWriter(OS, /*IsELF64*/ false, OSABI, ELF::EM_386);
357357 }
358358 };
359359
363363 : ELFX86AsmBackend(T, OSABI, CPU) {}
364364
365365 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
366 return createX86ELFObjectWriter(OS, /*Is64Bit*/ true, OSABI);
366 return createX86ELFObjectWriter(OS, /*IsELF64*/ true, OSABI, ELF::EM_X86_64);
367367 }
368368 };
369369
1919 namespace {
2020 class X86ELFObjectWriter : public MCELFObjectTargetWriter {
2121 public:
22 X86ELFObjectWriter(bool is64Bit, uint8_t OSABI);
22 X86ELFObjectWriter(bool IsELF64, uint8_t OSABI, uint16_t EMachine);
2323
2424 virtual ~X86ELFObjectWriter();
2525 protected:
2929 };
3030 }
3131
32 X86ELFObjectWriter::X86ELFObjectWriter(bool Is64Bit, uint8_t OSABI)
33 : MCELFObjectTargetWriter(Is64Bit, OSABI,
34 Is64Bit ? ELF::EM_X86_64 : ELF::EM_386,
35 /*HasRelocationAddend*/ Is64Bit) {}
32 X86ELFObjectWriter::X86ELFObjectWriter(bool IsELF64, uint8_t OSABI,
33 uint16_t EMachine)
34 : MCELFObjectTargetWriter(IsELF64, OSABI, EMachine,
35 // Only i386 uses Rel instead of RelA.
36 /*HasRelocationAddend*/ EMachine != ELF::EM_386) {}
3637
3738 X86ELFObjectWriter::~X86ELFObjectWriter()
3839 {}
4748 MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
4849 MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
4950 unsigned Type;
50 if (is64Bit()) {
51 if (getEMachine() == ELF::EM_X86_64) {
5152 if (IsPCRel) {
5253 switch ((unsigned)Fixup.getKind()) {
5354 default: llvm_unreachable("invalid fixup kind!");
129130 case FK_Data_1: Type = ELF::R_X86_64_8; break;
130131 }
131132 }
132 } else {
133 } else if (getEMachine() == ELF::EM_386) {
133134 if (IsPCRel) {
134135 switch ((unsigned)Fixup.getKind()) {
135136 default: llvm_unreachable("invalid fixup kind!");
209210 case FK_Data_1: Type = ELF::R_386_8; break;
210211 }
211212 }
212 }
213 } else
214 llvm_unreachable("Unsupported ELF machine type.");
213215
214216 return Type;
215217 }
216218
217219 MCObjectWriter *llvm::createX86ELFObjectWriter(raw_ostream &OS,
218 bool Is64Bit,
219 uint8_t OSABI) {
220 bool IsELF64,
221 uint8_t OSABI,
222 uint16_t EMachine) {
220223 MCELFObjectTargetWriter *MOTW =
221 new X86ELFObjectWriter(Is64Bit, OSABI);
224 new X86ELFObjectWriter(IsELF64, OSABI, EMachine);
222225 return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/true);
223226 }
8888
8989 /// createX86ELFObjectWriter - Construct an X86 ELF object writer.
9090 MCObjectWriter *createX86ELFObjectWriter(raw_ostream &OS,
91 bool Is64Bit,
92 uint8_t OSABI);
91 bool IsELF64,
92 uint8_t OSABI,
93 uint16_t EMachine);
9394 /// createX86WinCOFFObjectWriter - Construct an X86 Win COFF object writer.
9495 MCObjectWriter *createX86WinCOFFObjectWriter(raw_ostream &OS, bool Is64Bit);
9596 } // End llvm namespace