Add support for assembling .s files on mac os x for intel
authorNate Begeman <natebegeman@mac.com>
Fri, 8 Jul 2005 00:23:26 +0000 (00:23 +0000)
committerNate Begeman <natebegeman@mac.com>
Fri, 8 Jul 2005 00:23:26 +0000 (00:23 +0000)
Add support for running bugpoint on mac os x for intel

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

lib/Support/ToolRunner.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h
tools/bugpoint/ToolRunner.cpp

index 4a08e1adc76ae13b5752bd63894096814b48ab2d..3cea3386dbb04abbd47fa94e19486e545a8aec4c 100644 (file)
@@ -441,7 +441,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
     InputFile.c_str(),           // Specify the input filename...
 #if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
     "-G",                        // Compile a shared library, `-G' for Sparc
-#elif (defined(__POWERPC__) || defined(__ppc__)) && defined(__APPLE__)
+#elif defined(__APPLE__)
     "-single_module",            // link all source files into a single module
     "-dynamiclib",               // `-dynamiclib' for MacOS X/PowerPC
     "-undefined",                // in data segment, rather than generating
index 80a59d751b600d0f8bdceb3e992c4f8f536c71fe..d9a818b6bd02fd927d2f7793545a27c050bd5db0 100644 (file)
@@ -44,7 +44,6 @@ namespace {
 
   struct PowerPCAsmPrinter : public AsmPrinter {
     std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
-    std::set<std::string> Strings;
 
     PowerPCAsmPrinter(std::ostream &O, TargetMachine &TM)
       : AsmPrinter(O, TM), LabelNumber(0) {}
index a7e6729141dd50896798da7497107cf2ac155cf8..05dff4094f2dc078f470b9d790e765e2337233f3 100755 (executable)
@@ -86,6 +86,37 @@ void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) {
     abort ();
     return;
   case MachineOperand::MO_GlobalAddress: {
+    // Darwin block shameless ripped from PowerPCAsmPrinter.cpp
+    if (forDarwin) {
+      if (!isCallOp) O << '$';
+      GlobalValue *GV = MO.getGlobal();
+      std::string Name = Mang->getValueName(GV);
+
+      // Dynamically-resolved functions need a stub for the function.  Be
+      // wary however not to output $stub for external functions whose addresses
+      // are taken.  Those should be emitted as $non_lazy_ptr below.
+      Function *F = dyn_cast<Function>(GV);
+      if (F && isCallOp && F->isExternal()) {
+        FnStubs.insert(Name);
+        O << "L" << Name << "$stub";
+        return;
+      }
+
+      // Link-once, External, or Weakly-linked global variables need 
+      // non-lazily-resolved stubs
+      if (GV->hasLinkOnceLinkage()) {
+        LinkOnceStubs.insert(Name);
+        O << "L" << Name << "$non_lazy_ptr";
+        return;
+      }
+      if (GV->isExternal() || GV->hasWeakLinkage()) {
+        GVStubs.insert(Name);
+        O << "L" << Name << "$non_lazy_ptr";
+        return;
+      }
+      O << Mang->getValueName(GV);
+      return;
+    }
     if (!isCallOp) O << '$';
     O << Mang->getValueName(MO.getGlobal());
     int Offset = MO.getOffset();
@@ -96,6 +127,12 @@ void X86ATTAsmPrinter::printOp(const MachineOperand &MO, bool isCallOp) {
     return;
   }
   case MachineOperand::MO_ExternalSymbol:
+    if (isCallOp && forDarwin) {
+      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+      FnStubs.insert(Name);
+      O << "L" << Name << "$stub";
+      return;
+    }
     if (!isCallOp) O << '$';
     O << GlobalPrefix << MO.getSymbolName();
     return;
index 332dda0daeaec873953d12632d2f04236d121768..072eca383c55ae9fb4bd476830578b7fb876b975 100644 (file)
@@ -50,7 +50,7 @@ bool X86SharedAsmPrinter::doInitialization(Module& M) {
   } else if (TT.empty()) {
   #if defined(__CYGWIN__) || defined(__MINGW32__)
     forCygwin = true;
-  #elif defined(__MACOSX__)
+  #elif defined(__APPLE__)
     forDarwin = true;
   #elif defined(_WIN32)
     leadingUnderscore = true;
@@ -79,7 +79,10 @@ void X86SharedAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
   if (CP.empty()) return;
 
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    O << "\t.section .rodata\n";
+    if (forDarwin)
+      O << "\t.data\n";
+    else
+      O << "\t.section .rodata\n";
     emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
     O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString
       << *CP[i] << "\n";
@@ -104,10 +107,13 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
                (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
                        I->hasWeakLinkage() /* FIXME: Verify correct */)) {
                SwitchSection(O, CurSection, ".data");
-               if (!forCygwin && I->hasInternalLinkage())
-                 O << "\t.local " << name << "\n";
-               O << "\t.comm " << name << "," << TD.getTypeSize(C->getType());
-               if (!forCygwin)
+               if (!forCygwin && !forDarwin && I->hasInternalLinkage())
+        O << "\t.local " << name << "\n";
+      if (forDarwin && I->hasInternalLinkage())
+         O << "\t.lcomm " << name << "," << Size << "," << Align;
+      else 
+        O << "\t.comm " << name << "," << Size;
+               if (!forCygwin && !forDarwin)
                  O << "," << (1 << Align);
                O << "\t\t# ";
                WriteAsOperand(O, I, true, true, &M);
@@ -152,6 +158,47 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
                emitGlobalConstant(C);
          }
     }
+  
+  if (forDarwin) {
+    // Output stubs for dynamically-linked functions
+    unsigned j = 1;
+    for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
+         i != e; ++i, ++j)
+    {
+      O << "\t.symbol_stub\n";
+      O << "L" << *i << "$stub:\n";
+      O << "\t.indirect_symbol " << *i << "\n";
+      O << "\tjmp\t*L" << j << "$lz\n";
+      O << "L" << *i << "$stub_binder:\n";
+      O << "\tpushl\t$L" << j << "$lz\n";
+      O << "\tjmp\tdyld_stub_binding_helper\n";
+      O << "\t.section __DATA, __la_sym_ptr3,lazy_symbol_pointers\n";
+      O << "L" << j << "$lz:\n";
+      O << "\t.indirect_symbol " << *i << "\n";
+      O << "\t.long\tL" << *i << "$stub_binder\n";
+    }
+
+    O << "\n";
+  
+    // Output stubs for external global variables
+    if (GVStubs.begin() != GVStubs.end())
+      O << ".data\n.non_lazy_symbol_pointer\n";
+    for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
+         i != e; ++i) {
+      O << "L" << *i << "$non_lazy_ptr:\n";
+      O << "\t.indirect_symbol " << *i << "\n";
+      O << "\t.long\t0\n";
+    }
+
+    // Output stubs for link-once variables
+    if (LinkOnceStubs.begin() != LinkOnceStubs.end())
+      O << ".data\n.align 2\n";
+    for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
+         e = LinkOnceStubs.end(); i != e; ++i) {
+      O << "L" << *i << "$non_lazy_ptr:\n"
+        << "\t.long\t" << *i << '\n';
+    }
+  }
 
   AsmPrinter::doFinalization(M);
   return false; // success
index 3b05ed96f922377f2215e4a34f753a0fe7416a6a..4f53de8fb581696eef6be4369746b94de1adb2e1 100755 (executable)
@@ -19,6 +19,8 @@
 #include "X86.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/ADT/Statistic.h"
+#include <set>
+
 
 namespace llvm {
 namespace x86 {
@@ -36,6 +38,9 @@ struct X86SharedAsmPrinter : public AsmPrinter {
   bool forCygwin;
   bool forDarwin;
 
+  // Necessary for Darwin to print out the apprioriate types of linker stubs
+  std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
+
   inline static bool isScale(const MachineOperand &MO) {
     return MO.isImmediate() &&
           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
index 4a08e1adc76ae13b5752bd63894096814b48ab2d..3cea3386dbb04abbd47fa94e19486e545a8aec4c 100644 (file)
@@ -441,7 +441,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
     InputFile.c_str(),           // Specify the input filename...
 #if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
     "-G",                        // Compile a shared library, `-G' for Sparc
-#elif (defined(__POWERPC__) || defined(__ppc__)) && defined(__APPLE__)
+#elif defined(__APPLE__)
     "-single_module",            // link all source files into a single module
     "-dynamiclib",               // `-dynamiclib' for MacOS X/PowerPC
     "-undefined",                // in data segment, rather than generating