[x32] Add AsmBackend for X32 which uses ELF32 with x86_64 (the author is Pavel Chupin).
authorZinovy Nis <zinovy.nis@gmail.com>
Thu, 10 Jul 2014 13:03:26 +0000 (13:03 +0000)
committerZinovy Nis <zinovy.nis@gmail.com>
Thu, 10 Jul 2014 13:03:26 +0000 (13:03 +0000)
This is minimal change for backend required to have "hello world" compiled and working on x32 target (x86_64-linux-gnux32). More patches for x32 will follow.

Differential Revision: http://reviews.llvm.org/D4181

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212716 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

index c12a57a06d66bbb331e0503d572f6dbcbfa485ee..23bca0d53d3d584dde652461e80579c5a4b96a3b 100644 (file)
@@ -366,6 +366,17 @@ public:
   }
 };
 
+class ELFX86_X32AsmBackend : public ELFX86AsmBackend {
+public:
+  ELFX86_X32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
+      : ELFX86AsmBackend(T, OSABI, CPU) {}
+
+  MCObjectWriter *createObjectWriter(raw_ostream &OS) const override {
+    return createX86ELFObjectWriter(OS, /*IsELF64*/ false, OSABI,
+                                    ELF::EM_X86_64);
+  }
+};
+
 class ELFX86_64AsmBackend : public ELFX86AsmBackend {
 public:
   ELFX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU)
@@ -824,5 +835,8 @@ MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
     return new WindowsX86AsmBackend(T, true, CPU);
 
   uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
+
+  if (TheTriple.getEnvironment() == Triple::GNUX32)
+    return new ELFX86_X32AsmBackend(T, OSABI, CPU);
   return new ELFX86_64AsmBackend(T, OSABI, CPU);
 }