From 92200d237a4292043cf84df0c414db9acf73ccfc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 15 Jun 2015 13:36:27 +0000 Subject: [PATCH] gold-plugin: save the .o when given -save-temps. The plugin now save the bitcode before and after optimizations and the .o that is passed to the linker. llvm-svn: 239726 --- llvm/test/tools/gold/emit-llvm.ll | 3 +++ llvm/tools/gold/gold-plugin.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/llvm/test/tools/gold/emit-llvm.ll b/llvm/test/tools/gold/emit-llvm.ll index f851fbf..bfb90c4 100644 --- a/llvm/test/tools/gold/emit-llvm.ll +++ b/llvm/test/tools/gold/emit-llvm.ll @@ -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 diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 724e93c..68c9d1a 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -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()); } -- 2.7.4