diff options
-rw-r--r-- | lld/ELF/Driver.cpp | 10 | ||||
-rw-r--r-- | lld/test/ELF/lto/save-temps.ll | 12 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0a5123c2daf..e828700a97e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -434,14 +434,18 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { 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) diff --git a/lld/test/ELF/lto/save-temps.ll b/lld/test/ELF/lto/save-temps.ll index a7fe96708d7..5c47741e575 100644 --- a/lld/test/ELF/lto/save-temps.ll +++ b/lld/test/ELF/lto/save-temps.ll @@ -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" |