[lld] r265254 - [LTO] Fix -save-temps in case -o is not specified.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 19:16:57 PDT 2016


Author: davide
Date: Sat Apr  2 21:16:56 2016
New Revision: 265254

URL: http://llvm.org/viewvc/llvm-project?rev=265254&view=rev
Log:
[LTO] Fix -save-temps in case -o is not specified.

Currently we create a file called .lto.bc. In UNIX,
ls(1) by default doesn't show up files starting with
a dot, as they're (only by convention) hidden.
This makes the output of -save-temps a little bit
hard to find. Use "a.out.lto.bc" instead if the
output file is not specified.

While here, change an existing -save-temps test to
exercise this more interesting behaviour.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/test/ELF/lto/save-temps.ll

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=265254&r1=265253&r2=265254&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Apr  2 21:16:56 2016
@@ -434,14 +434,18 @@ template <class ELFT> void LinkerDriver:
   for (StringRef S : Config->Undefined)
     Symtab.addUndefinedOpt(S);
 
+  // -save-temps creates a file based on the output file name so we want
+  // to set it right before LTO. This code can't be moved to option parsing
+  // because linker scripts can override the output filename using the
+  // OUTPUT() directive.
+  if (Config->OutputFile.empty())
+    Config->OutputFile = "a.out";
+
   Symtab.addCombinedLtoObject();
 
   for (auto *Arg : Args.filtered(OPT_wrap))
     Symtab.wrap(Arg->getValue());
 
-  if (Config->OutputFile.empty())
-    Config->OutputFile = "a.out";
-
   // Write the result to the file.
   Symtab.scanShlibUndefined();
   if (Config->GcSections)

Modified: lld/trunk/test/ELF/lto/save-temps.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/save-temps.ll?rev=265254&r1=265253&r2=265254&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/save-temps.ll (original)
+++ lld/trunk/test/ELF/lto/save-temps.ll Sat Apr  2 21:16:56 2016
@@ -1,12 +1,12 @@
 ; REQUIRES: x86
-; RUN: rm -f %t %t.lto.bc %t.lto.o
+; RUN: rm -f a.out a.out.lto.bc a.out.lto.o
 ; RUN: llvm-as %s -o %t.o
 ; RUN: llvm-as %p/Inputs/save-temps.ll -o %t2.o
-; RUN: ld.lld -shared -m elf_x86_64 %t.o %t2.o -o %t -save-temps
-; RUN: llvm-nm %t | FileCheck %s
-; RUN: llvm-nm %t.lto.bc | FileCheck %s
-; RUN: llvm-nm %t.lto.o | FileCheck %s
-; RUN: llvm-dis %t.lto.bc
+; RUN: ld.lld -shared -m elf_x86_64 %t.o %t2.o -save-temps
+; RUN: llvm-nm a.out | FileCheck %s
+; RUN: llvm-nm a.out.lto.bc | FileCheck %s
+; RUN: llvm-nm a.out.lto.o | FileCheck %s
+; RUN: llvm-dis a.out.lto.bc
 
 target triple = "x86_64-unknown-linux-gnu"
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"




More information about the llvm-commits mailing list