Add support to the X86 backend for emitting ELF files. To use this, we
currently use: llc t.bc --filetype=obj
This will produce a t.o file which is dumpable with readelf. Currently
the file produced is empty, but the scaffolding to do more is now in place.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22292 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp
index dcf27ac..2330182 100644
--- a/lib/Target/X86/X86TargetMachine.cpp
+++ b/lib/Target/X86/X86TargetMachine.cpp
@@ -98,7 +98,8 @@
// does to emit statically compiled machine code.
bool X86TargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
CodeGenFileType FileType) {
- if (FileType != TargetMachine::AssemblyFile) return true;
+ if (FileType != TargetMachine::AssemblyFile &&
+ FileType != TargetMachine::ObjectFile) return true;
// FIXME: Implement efficient support for garbage collection intrinsics.
PM.add(createLowerGCPass());
@@ -146,7 +147,19 @@
PM.add(createX86CodePrinterPass(std::cerr, *this));
if (!DisableOutput)
- PM.add(createX86CodePrinterPass(Out, *this));
+ switch (FileType) {
+ default:
+ assert(0 && "Unexpected filetype here!");
+ case TargetMachine::AssemblyFile:
+ PM.add(createX86CodePrinterPass(Out, *this));
+ break;
+ case TargetMachine::ObjectFile:
+ // FIXME: We only support emission of ELF files for now, this should check
+ // the target triple and decide on the format to write (e.g. COFF on
+ // win32).
+ PM.add(createX86ELFObjectWriterPass(Out, *this));
+ break;
+ }
// Delete machine code for this function
PM.add(createMachineCodeDeleter());