diff options
author | Fangrui Song <i@maskray.me> | 2020-07-20 09:58:31 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-07-21 10:20:50 -0700 |
commit | 021056563632ca625dab6e8270cec2e2fae7a8cb (patch) | |
tree | 34439011cbbc71562848726cc0d72e1f88285280 | |
parent | cebd637c88624dfd44520848cb1f43dc8a02ba80 (diff) | |
download | llvm-021056563632ca625dab6e8270cec2e2fae7a8cb.zip llvm-021056563632ca625dab6e8270cec2e2fae7a8cb.tar.gz llvm-021056563632ca625dab6e8270cec2e2fae7a8cb.tar.bz2 |
[LLVMgold.so] -plugin-opt=save-temps: save combined module to .lto.o instead of .o
This matches LLD and fixes https://sourceware.org/bugzilla/show_bug.cgi?id=26262#c1
.o is a bad choice for save-temps output because it is easy to override the bitcode file (*.o)
```
# Use bfd for the example, -fuse-ld=gold is similar.
clang -flto -c a.c # generate bitcode file a.o
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps # override a.o
# The user repeats the command but get surprised, because a.o is now a combined module.
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps
```
Reviewed By: tejohnson
Differential Revision: https://reviews.llvm.org/D84132
(cherry picked from commit 55fa315b0352b63454206600d6803fafacb42d5e)
-rw-r--r-- | llvm/test/tools/gold/X86/parallel.ll | 6 | ||||
-rw-r--r-- | llvm/test/tools/gold/X86/relocation-model-pic.ll | 16 | ||||
-rw-r--r-- | llvm/test/tools/gold/X86/thinlto.ll | 2 | ||||
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 2 |
4 files changed, 13 insertions, 13 deletions
diff --git a/llvm/test/tools/gold/X86/parallel.ll b/llvm/test/tools/gold/X86/parallel.ll index dabb5c4..6972efc 100644 --- a/llvm/test/tools/gold/X86/parallel.ll +++ b/llvm/test/tools/gold/X86/parallel.ll @@ -1,10 +1,10 @@ ; RUN: llvm-as -o %t.bc %s -; RUN: rm -f %t.0.5.precodegen.bc %t.1.5.precodegen.bc %t.o %t.o1 +; RUN: rm -f %t.0.5.precodegen.bc %t.1.5.precodegen.bc %t.lto.o %t.lto.o1 ; RUN: env LD_PRELOAD=%llvmshlibdir/LLVMgold%shlibext %gold -plugin %llvmshlibdir/LLVMgold%shlibext -u foo -u bar -plugin-opt lto-partitions=2 -plugin-opt save-temps -m elf_x86_64 -o %t %t.bc ; RUN: llvm-dis %t.0.5.precodegen.bc -o - | FileCheck --check-prefix=CHECK-BC0 %s ; RUN: llvm-dis %t.1.5.precodegen.bc -o - | FileCheck --check-prefix=CHECK-BC1 %s -; RUN: llvm-nm %t.o | FileCheck --check-prefix=CHECK0 %s -; RUN: llvm-nm %t.o1 | FileCheck --check-prefix=CHECK1 %s +; RUN: llvm-nm %t.lto.o | FileCheck --check-prefix=CHECK0 %s +; RUN: llvm-nm %t.lto.o1 | FileCheck --check-prefix=CHECK1 %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" diff --git a/llvm/test/tools/gold/X86/relocation-model-pic.ll b/llvm/test/tools/gold/X86/relocation-model-pic.ll index ad7d298..98034e4 100644 --- a/llvm/test/tools/gold/X86/relocation-model-pic.ll +++ b/llvm/test/tools/gold/X86/relocation-model-pic.ll @@ -10,44 +10,44 @@ ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --shared \ ; RUN: --plugin-opt=save-temps %t.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=PIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --export-dynamic --noinhibit-exec -pie \ ; RUN: --plugin-opt=save-temps %t.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=PIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --export-dynamic --noinhibit-exec \ ; RUN: --plugin-opt=save-temps %t.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=STATIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: -r \ ; RUN: --plugin-opt=save-temps %t.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=STATIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC ;; PIC source. ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --shared \ ; RUN: --plugin-opt=save-temps %t.pic.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=PIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --export-dynamic --noinhibit-exec -pie \ ; RUN: --plugin-opt=save-temps %t.pic.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=PIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: --export-dynamic --noinhibit-exec \ ; RUN: --plugin-opt=save-temps %t.pic.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=STATIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ ; RUN: -r \ ; RUN: --plugin-opt=save-temps %t.pic.o -o %t-out -; RUN: llvm-readobj -r %t-out.o | FileCheck %s --check-prefix=PIC +; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC ; PIC: R_X86_64_GOTPCREL foo diff --git a/llvm/test/tools/gold/X86/thinlto.ll b/llvm/test/tools/gold/X86/thinlto.ll index 6857778..3ed07ff 100644 --- a/llvm/test/tools/gold/X86/thinlto.ll +++ b/llvm/test/tools/gold/X86/thinlto.ll @@ -42,7 +42,7 @@ ; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED ; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM ; Ensure ld does not emit empty combined module in default. -; RUN: ls %t4.o* | count 2 +; RUN: ls %t4.lto.o* | count 2 ; Check with --no-map-whole-files ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 7654d44..0124e0a 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -1050,7 +1050,7 @@ static std::vector<std::pair<SmallString<128>, bool>> runLTO() { if (!options::obj_path.empty()) Filename = options::obj_path; else if (options::TheOutputType == options::OT_SAVE_TEMPS) - Filename = output_name + ".o"; + Filename = output_name + ".lto.o"; else if (options::TheOutputType == options::OT_ASM_ONLY) Filename = output_name; bool SaveTemps = !Filename.empty(); |