<rdar://problem/6940611> libLTO.dylib needs to let linker specify path to assembler
authorNick Kledzik <kledzik@apple.com>
Thu, 4 Jun 2009 00:28:45 +0000 (00:28 +0000)
committerNick Kledzik <kledzik@apple.com>
Thu, 4 Jun 2009 00:28:45 +0000 (00:28 +0000)
Add lto_codegen_set_assembler_path() API which allows the linker to specify the
path to the assembler tool to run.  When assembler is used (instead of compiler)
different command line options are used.
Add LTO_API_VERSION #define so clients (linkers) can conditionalize use of new APIs.

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

include/llvm-c/lto.h
tools/lto/LTOCodeGenerator.cpp
tools/lto/LTOCodeGenerator.h
tools/lto/lto.cpp
tools/lto/lto.exports

index 819861769084e67a5ddd703f0d92e94c9fbd8eea..5d92fc5af013594f2d51dcb648eac4bd583ae462 100644 (file)
@@ -19,6 +19,8 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#define LTO_API_VERSION 3
+
 typedef enum {
     LTO_SYMBOL_ALIGNMENT_MASK         = 0x0000001F,    /* log2 of alignment */
     LTO_SYMBOL_PERMISSIONS_MASK       = 0x000000E0,    
@@ -207,6 +209,14 @@ extern void
 lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path);
 
 
+/**
+ * Sets the location of the assembler tool to run. If not set, libLTO
+ * will use gcc to invoke the assembler.
+ */
+extern void
+lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
+
+
 /**
  * Adds to a list of all global symbols that must exist in the final
  * generated code.  If a function is not listed, it might be
index 7aa591ab742fb25653c2c97671b92c7571d117bd..17c83bb5cf68426a47e5f7dcbcb0929cd5f22781 100644 (file)
@@ -72,7 +72,7 @@ LTOCodeGenerator::LTOCodeGenerator()
     : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
       _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
       _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
-      _nativeObjectFile(NULL), _gccPath(NULL)
+      _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
 {
 
 }
@@ -128,6 +128,13 @@ void LTOCodeGenerator::setGccPath(const char* path)
     _gccPath = new sys::Path(path);
 }
 
+void LTOCodeGenerator::setAssemblerPath(const char* path)
+{
+    if ( _assemblerPath )
+        delete _assemblerPath;
+    _assemblerPath = new sys::Path(path);
+}
+
 void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
 {
     _mustPreserveSymbols[sym] = 1;
@@ -220,13 +227,18 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
 bool LTOCodeGenerator::assemble(const std::string& asmPath, 
                                 const std::string& objPath, std::string& errMsg)
 {
-    sys::Path gcc;
-    if ( _gccPath ) {
-        gcc = *_gccPath;
+    sys::Path tool;
+    bool needsCompilerOptions = true;
+    if ( _assemblerPath ) {
+        tool = *_assemblerPath;
+        needsCompilerOptions = false;
+    }
+    else if ( _gccPath ) {
+        tool = *_gccPath;
     } else {
         // find compiler driver
-        gcc = sys::Program::FindProgramByName("gcc");
-        if ( gcc.isEmpty() ) {
+        tool = sys::Program::FindProgramByName("gcc");
+        if ( tool.isEmpty() ) {
             errMsg = "can't locate gcc";
             return true;
         }
@@ -235,7 +247,7 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath,
     // build argument list
     std::vector<const char*> args;
     std::string targetTriple = _linker.getModule()->getTargetTriple();
-    args.push_back(gcc.c_str());
+    args.push_back(tool.c_str());
     if ( targetTriple.find("darwin") != targetTriple.size() ) {
         if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
             args.push_back("-arch");
@@ -275,16 +287,18 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath,
             args.push_back("armv6");
         }
     }
-    args.push_back("-c");
-    args.push_back("-x");
-    args.push_back("assembler");
+    if ( needsCompilerOptions ) {
+        args.push_back("-c");
+        args.push_back("-x");
+        args.push_back("assembler");
+    }
     args.push_back("-o");
     args.push_back(objPath.c_str());
     args.push_back(asmPath.c_str());
     args.push_back(0);
 
     // invoke assembler
-    if ( sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 0, 0, &errMsg) ) {
+    if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) {
         errMsg = "error in assembly";    
         return true;
     }
index 57398b0650037ac63ee900dbd9d93030b83596e9..e02a7ab1159f1b6ed267e3970e49ed80db067f44 100644 (file)
@@ -37,6 +37,7 @@ public:
     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
     void                setGccPath(const char* path);
+    void                setAssemblerPath(const char* path);
     void                addMustPreserveSymbol(const char* sym);
     bool                writeMergedModules(const char* path, 
                                                            std::string& errMsg);
@@ -61,6 +62,7 @@ private:
     llvm::MemoryBuffer*         _nativeObjectFile;
     std::vector<const char*>    _codegenOptions;
     llvm::sys::Path*            _gccPath;
+    llvm::sys::Path*            _assemblerPath;
 };
 
 #endif // LTO_CODE_GENERATOR_H
index 5c3f90aa485d90985ba10d1ec09e02fd3debd5e2..7eb39ef210009b968ef512b50d09359328d0ef9a 100644 (file)
@@ -209,6 +209,14 @@ void lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path)
     cg->setGccPath(path);
 }
 
+//
+// sets the path to the assembler tool
+//
+void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path)
+{
+    cg->setAssemblerPath(path);
+}
+
 //
 // adds to a list of all global symbols that must exist in the final
 // generated code.  If a function is not listed there, it might be
index aff755937b5b2fd789afecf5ec8ae3cb061a5b0d..01f43d1c36daf421720cbfa9121adbaef94dc2c1 100644 (file)
@@ -20,4 +20,5 @@ _lto_codegen_set_debug_model
 _lto_codegen_set_pic_model
 _lto_codegen_write_merged_modules
 _lto_codegen_debug_options
+_lto_codegen_set_assembler_path