Hook up -filetype=obj through the MachO streamer.  Here's a demo:

$ cat t.ll 
@g = global i32 42
$ llc t.ll -o t.o -filetype=obj
$ nm t.o
00000000 D _g

There is still a ton of work left.  Instructions are not being encoded
yet apparently.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95162 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index d255492..af33776 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -124,23 +124,30 @@
   OwningPtr<MCStreamer> AsmStreamer;
 
   switch (FileType) {
-  default:
-  case CGFT_ObjectFile:
-    return CGFT_ErrorOccurred;
-  case CGFT_AssemblyFile: {
+  default: return CGFT_ErrorOccurred;
+  case CGFT_AssemblyFile:
     AsmStreamer.reset(createAsmStreamer(*Context, Out, *getMCAsmInfo(),
                                         getTargetData()->isLittleEndian(),
                                         getVerboseAsm(), /*instprinter*/0,
                                         /*codeemitter*/0));
     break;
+  case CGFT_ObjectFile: {
+    // Create the code emitter for the target if it exists.  If not, .o file
+    // emission fails.
+    MCCodeEmitter *MCE = getTarget().createCodeEmitter(*this);
+    if (MCE == 0)
+      return CGFT_ErrorOccurred;
+    
+    AsmStreamer.reset(createMachOStreamer(*Context, Out, MCE));
+    break;
   }
   }
   
   // Create the AsmPrinter, which takes ownership of Context and AsmStreamer
   // if successful.
   FunctionPass *Printer =
-  getTarget().createAsmPrinter(Out, *this, *Context, *AsmStreamer,
-                               getMCAsmInfo());
+    getTarget().createAsmPrinter(Out, *this, *Context, *AsmStreamer,
+                                 getMCAsmInfo());
   if (Printer == 0)
     return CGFT_ErrorOccurred;