gold-plugin: save the .o when given -save-temps.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 15 Jun 2015 13:36:27 +0000 (13:36 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 15 Jun 2015 13:36:27 +0000 (13:36 +0000)
The plugin now save the bitcode before and after optimizations and the
.o that is passed to the linker.

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

test/tools/gold/emit-llvm.ll
tools/gold/gold-plugin.cpp

index f851fbfb5e024177b1663e4a700e04e60d77bd62..bfb90c4bc28a2a01a2a402409c7047a0cae5d69a 100644 (file)
@@ -12,6 +12,7 @@
 ; RUN:    -shared %t.o -o %t3.o
 ; RUN: llvm-dis %t3.o.bc -o - | FileCheck %s
 ; RUN: llvm-dis %t3.o.opt.bc -o - | FileCheck --check-prefix=OPT %s
+; RUN: llvm-nm %t3.o.o | FileCheck --check-prefix=NM %s
 
 ; RUN: rm -f %t4.o
 ; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
@@ -19,6 +20,8 @@
 ; RUN:    -shared %t.o -o %t4.o
 ; RUN: not test -a %t4.o
 
+; NM: T f3
+
 target triple = "x86_64-unknown-linux-gnu"
 
 @g7 = extern_weak global i32
index 724e93cb8c74436091c61e284b1e65d41d836e83..68c9d1a6f6e4d7335332abd6931c0bc38d844098 100644 (file)
@@ -787,15 +787,20 @@ static void codegen(Module &M) {
   legacy::PassManager CodeGenPasses;
 
   SmallString<128> Filename;
+  if (!options::obj_path.empty())
+    Filename = options::obj_path;
+  else if (options::TheOutputType == options::OT_SAVE_TEMPS)
+    Filename = output_name + ".o";
+
   int FD;
-  if (options::obj_path.empty()) {
+  bool TempOutFile = Filename.empty();
+  if (TempOutFile) {
     std::error_code EC =
         sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename);
     if (EC)
       message(LDPL_FATAL, "Could not create temporary file: %s",
               EC.message().c_str());
   } else {
-    Filename = options::obj_path;
     std::error_code EC =
         sys::fs::openFileForWrite(Filename.c_str(), FD, sys::fs::F_None);
     if (EC)
@@ -816,7 +821,7 @@ static void codegen(Module &M) {
             "Unable to add .o file to the link. File left behind in: %s",
             Filename.c_str());
 
-  if (options::obj_path.empty())
+  if (TempOutFile)
     Cleanup.push_back(Filename.c_str());
 }