[llvm] r191829 - Fix option parsing in the gold plugin.

Rafael Espindola rafael.espindola at gmail.com
Wed Oct 2 07:36:23 PDT 2013


Author: rafael
Date: Wed Oct  2 09:36:23 2013
New Revision: 191829

URL: http://llvm.org/viewvc/llvm-project?rev=191829&view=rev
Log:
Fix option parsing in the gold plugin.

This was broken when options were moved up in r191680. No test because this is
specific LLVMgold.so/libLTO.so.

Patch by Tom Roeder!

Modified:
    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/lto.cpp

Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=191829&r1=191828&r2=191829&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Wed Oct  2 09:36:23 2013
@@ -79,6 +79,11 @@ struct LTOCodeGenerator {
   // and LTOCodeGenerator::writeMergedModules().
   //
   void setCodeGenDebugOptions(const char *opts);
+  
+  // Parse the options set in setCodeGenDebugOptions. Like
+  // setCodeGenDebugOptions, this must be called before
+  // LTOCodeGenerator::compilexxx() and LTOCodeGenerator::writeMergedModules()
+  void parseCodeGenDebugOptions();
 
   // Write the merged module to the file specified by the given path.
   // Return true on success.

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=191829&r1=191828&r2=191829&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Wed Oct  2 09:36:23 2013
@@ -264,11 +264,6 @@ bool LTOCodeGenerator::determineTarget(s
   if (TargetMach != NULL)
     return true;
 
-  // if options were requested, set them
-  if (!CodegenOptions.empty())
-    cl::ParseCommandLineOptions(CodegenOptions.size(),
-                                const_cast<char **>(&CodegenOptions[0]));
-
   std::string TripleStr = Linker.getModule()->getTargetTriple();
   if (TripleStr.empty())
     TripleStr = sys::getDefaultTargetTriple();
@@ -473,3 +468,10 @@ void LTOCodeGenerator::setCodeGenDebugOp
     CodegenOptions.push_back(strdup(o.first.str().c_str()));
   }
 }
+
+void LTOCodeGenerator::parseCodeGenDebugOptions() {
+  // if options were requested, set them
+  if (!CodegenOptions.empty())
+    cl::ParseCommandLineOptions(CodegenOptions.size(),
+                                const_cast<char **>(&CodegenOptions[0]));
+}

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=191829&r1=191828&r2=191829&view=diff
==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Wed Oct  2 09:36:23 2013
@@ -40,6 +40,9 @@ static std::string sLastErrorString;
 // *** Not thread safe ***
 static bool initialized = false;
 
+// Holds the command-line option parsing state of the LTO module.
+static bool parsedOptions = false;
+
 // Initialize the configured targets if they have not been initialized.
 static void lto_initialize() {
   if (!initialized) {
@@ -261,6 +264,10 @@ void lto_codegen_add_must_preserve_symbo
 /// that contains the merged contents of all modules added so far. Returns true
 /// on error (check lto_get_error_message() for details).
 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
+  if (!parsedOptions) {
+    cg->parseCodeGenDebugOptions();
+    parsedOptions = true;
+  }
   return !cg->writeMergedModules(path, sLastErrorString);
 }
 
@@ -271,6 +278,10 @@ bool lto_codegen_write_merged_modules(lt
 /// lto_codegen_compile() is called again. On failure, returns NULL (check
 /// lto_get_error_message() for details).
 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
+  if (!parsedOptions) {
+    cg->parseCodeGenDebugOptions();
+    parsedOptions = true;
+  }
   return cg->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE,
                      sLastErrorString);
 }
@@ -279,6 +290,10 @@ const void *lto_codegen_compile(lto_code
 /// native object file. The name of the file is written to name. Returns true on
 /// error.
 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
+  if (!parsedOptions) {
+    cg->parseCodeGenDebugOptions();
+    parsedOptions = true;
+  }
   return !cg->compile_to_file(name, DisableOpt, DisableInline, DisableGVNLoadPRE,
                               sLastErrorString);
 }





More information about the llvm-commits mailing list