1; First ensure that the ThinLTO handling in the gold plugin handles
2; bitcode without summary sections gracefully.
3; RUN: llvm-as %s -o %t.o
4; RUN: llvm-as %p/Inputs/thinlto.ll -o %t2.o
5; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
6; RUN:    -m elf_x86_64 \
7; RUN:    --plugin-opt=thinlto \
8; RUN:    --plugin-opt=thinlto-index-only \
9; RUN:    -shared %t.o %t2.o -o %t3
10; RUN: not test -e %t3
11; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
12; RUN:    -m elf_x86_64 \
13; RUN:    --plugin-opt=thinlto \
14; RUN:    -shared %t.o %t2.o -o %t4
15; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
16
17; Next generate summary sections and test gold handling.
18; RUN: opt -module-summary %s -o %t.o
19; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
20
21; Ensure gold generates an index and not a binary if requested.
22; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
23; RUN:    -m elf_x86_64 \
24; RUN:    --plugin-opt=thinlto \
25; RUN:    --plugin-opt=thinlto-index-only \
26; RUN:    -shared %t.o %t2.o -o %t3
27; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
28; RUN: llvm-bcanalyzer -dump %t2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
29; RUN: not test -e %t3
30
31; Ensure gold generates an index as well as a binary with save-temps in ThinLTO mode.
32; First force single-threaded mode
33; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
34; RUN:    -m elf_x86_64 \
35; RUN:    --plugin-opt=save-temps \
36; RUN:    --plugin-opt=thinlto \
37; RUN:    --plugin-opt=jobs=1 \
38; RUN:    -shared %t.o %t2.o -o %t4
39; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
40; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
41
42; Check with --no-map-whole-files
43; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
44; RUN:    -m elf_x86_64 \
45; RUN:    --plugin-opt=save-temps \
46; RUN:    --plugin-opt=thinlto \
47; RUN:    --plugin-opt=jobs=1 \
48; RUN:    --no-map-whole-files \
49; RUN:    -shared %t.o %t2.o -o %t4
50; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
51; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
52
53; Next force multi-threaded mode
54; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
55; RUN:    -m elf_x86_64 \
56; RUN:    --plugin-opt=save-temps \
57; RUN:    --plugin-opt=thinlto \
58; RUN:    --plugin-opt=jobs=2 \
59; RUN:    -shared %t.o %t2.o -o %t4
60; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
61; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
62
63; Test --plugin-opt=obj-path to ensure unique object files generated.
64; RUN: rm -f %t5.o %t5.o1
65; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
66; RUN:    -m elf_x86_64 \
67; RUN:    --plugin-opt=thinlto \
68; RUN:    --plugin-opt=jobs=2 \
69; RUN:    --plugin-opt=obj-path=%t5.o \
70; RUN:    -shared %t.o %t2.o -o %t4
71; RUN: llvm-nm %t5.o | FileCheck %s --check-prefix=NM2
72; RUN: llvm-nm %t5.o1 | FileCheck %s --check-prefix=NM2
73
74; NM: T f
75; NM2: T {{f|g}}
76
77; The backend index for this module contains summaries from itself and
78; Inputs/thinlto.ll, as it imports from the latter.
79; BACKEND1: <MODULE_STRTAB_BLOCK
80; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
81; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
82; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
83; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
84; BACKEND1-NEXT: <VERSION
85; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
86; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
87; BACKEND1-NEXT: <COMBINED
88; BACKEND1-NEXT: <COMBINED
89; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK
90
91; The backend index for Input/thinlto.ll contains summaries from itself only,
92; as it does not import anything.
93; BACKEND2: <MODULE_STRTAB_BLOCK
94; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp2.o'
95; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
96; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
97; BACKEND2-NEXT: <VERSION
98; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
99; BACKEND2-NEXT: <COMBINED
100; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
101
102; COMBINED: <MODULE_STRTAB_BLOCK
103; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
104; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
105; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
106; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
107; COMBINED-NEXT: <VERSION
108; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
109; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
110; COMBINED-NEXT: <COMBINED
111; COMBINED-NEXT: <COMBINED
112; COMBINED-NEXT: </GLOBALVAL_SUMMARY_BLOCK
113
114target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
115target triple = "x86_64-unknown-linux-gnu"
116
117declare void @g(...)
118
119define void @f() {
120entry:
121  call void (...) @g()
122  ret void
123}
124