[llvm-commits] [llvm] r70490 - in /llvm/trunk/tools: gold/gold-plugin.cpp lto/LTOCodeGenerator.cpp lto/LTOCodeGenerator.h lto/lto.cpp

Nick Lewycky nicholas at mxc.ca
Thu Apr 30 08:24:09 PDT 2009


Author: nicholas
Date: Thu Apr 30 10:24:09 2009
New Revision: 70490

URL: http://llvm.org/viewvc/llvm-project?rev=70490&view=rev
Log:
Allow a user of libLTO to specify the full pathname of the gcc executable to
run when assembling.

Wire this up to the gold plugin. You can now pass --plugin-opt gcc=/foo/bar/gcc
and it will run that gcc instead of looking for it on the path.

Modified:
    llvm/trunk/tools/gold/gold-plugin.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.h
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=70490&r1=70489&r2=70490&view=diff

==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Thu Apr 30 10:24:09 2009
@@ -44,6 +44,7 @@
   int gold_version = 0;
 
   bool generate_api_file = false;
+  const char *gcc_path = NULL;
 
   struct claimed_file {
     lto_module_t M;
@@ -101,6 +102,13 @@
       case LDPT_OPTION:
         if (strcmp("generate-api-file", tv->tv_u.tv_string) == 0) {
           generate_api_file = true;
+        } else if (strncmp("gcc=", tv->tv_u.tv_string, 4) == 0) {
+          if (gcc_path) {
+            (*message)(LDPL_WARNING, "Path to gcc specified twice. "
+                       "Discarding %s", tv->tv_u.tv_string);
+          } else {
+            gcc_path = strdup(tv->tv_u.tv_string + 4);
+          }
         } else {
           (*message)(LDPL_WARNING, "Ignoring flag %s", tv->tv_u.tv_string);
         }
@@ -336,6 +344,8 @@
 
   lto_codegen_set_pic_model(cg, output_type);
   lto_codegen_set_debug_model(cg, LTO_DEBUG_MODEL_DWARF);
+  if (gcc_path)
+    lto_codegen_set_gcc_path(cg, gcc_path);
 
   size_t bufsize = 0;
   const char *buffer = static_cast<const char *>(lto_codegen_compile(cg,

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=70490&r1=70489&r2=70490&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Thu Apr 30 10:24:09 2009
@@ -71,7 +71,7 @@
     : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
       _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
       _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
-      _nativeObjectFile(NULL)
+      _nativeObjectFile(NULL), _gccPath(NULL)
 {
 
 }
@@ -120,6 +120,13 @@
     return true;
 }
 
+void LTOCodeGenerator::setGccPath(const char* path)
+{
+    if ( _gccPath )
+        delete _gccPath;
+    _gccPath = new sys::Path(path);
+}
+
 void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
 {
     _mustPreserveSymbols[sym] = 1;
@@ -212,11 +219,16 @@
 bool LTOCodeGenerator::assemble(const std::string& asmPath, 
                                 const std::string& objPath, std::string& errMsg)
 {
-    // find compiler driver
-    const sys::Path gcc = sys::Program::FindProgramByName("gcc");
-    if ( gcc.isEmpty() ) {
-        errMsg = "can't locate gcc";
-        return true;
+    sys::Path gcc;
+    if ( _gccPath ) {
+        gcc = *_gccPath;
+    } else {
+        // find compiler driver
+        gcc = sys::Program::FindProgramByName("gcc");
+        if ( gcc.isEmpty() ) {
+            errMsg = "can't locate gcc";
+            return true;
+        }
     }
 
     // build argument list

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.h?rev=70490&r1=70489&r2=70490&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.h (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.h Thu Apr 30 10:24:09 2009
@@ -36,6 +36,7 @@
     bool                addModule(class LTOModule*, std::string& errMsg);
     bool                setDebugInfo(lto_debug_model, std::string& errMsg);
     bool                setCodePICModel(lto_codegen_model, std::string& errMsg);
+    void                setGccPath(const char* path);
     void                addMustPreserveSymbol(const char* sym);
     bool                writeMergedModules(const char* path, 
                                                            std::string& errMsg);
@@ -59,6 +60,7 @@
     StringSet                   _mustPreserveSymbols;
     llvm::MemoryBuffer*         _nativeObjectFile;
     std::vector<const char*>    _codegenOptions;
+    llvm::sys::Path*            _gccPath;
 };
 
 #endif // LTO_CODE_GENERATOR_H

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=70490&r1=70489&r2=70490&view=diff

==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Thu Apr 30 10:24:09 2009
@@ -202,6 +202,14 @@
 }
 
 //
+// sets the path to gcc
+//
+void lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path)
+{
+    cg->setGccPath(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
 // inlined into every usage and optimized away.





More information about the llvm-commits mailing list