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%shlibext \
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%shlibext \
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%shlibext \
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: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=DIS1
30; RUN: llvm-dis %t2.o.thinlto.bc -o - | FileCheck %s --check-prefix=DIS2
31; RUN: not test -e %t3
32
33; Ensure gold generates an index as well as a binary with save-temps in ThinLTO mode.
34; First force single-threaded mode
35; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
36; RUN:    -m elf_x86_64 \
37; RUN:    --plugin-opt=save-temps \
38; RUN:    --plugin-opt=thinlto \
39; RUN:    --plugin-opt=jobs=1 \
40; RUN:    -shared %t.o %t2.o -o %t4
41; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
42; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
43
44; Check with --no-map-whole-files
45; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
46; RUN:    -m elf_x86_64 \
47; RUN:    --plugin-opt=save-temps \
48; RUN:    --plugin-opt=thinlto \
49; RUN:    --plugin-opt=jobs=1 \
50; RUN:    --no-map-whole-files \
51; RUN:    -shared %t.o %t2.o -o %t4
52; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
53; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
54
55; Next force multi-threaded mode
56; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
57; RUN:    -m elf_x86_64 \
58; RUN:    --plugin-opt=save-temps \
59; RUN:    --plugin-opt=thinlto \
60; RUN:    --plugin-opt=jobs=2 \
61; RUN:    -shared %t.o %t2.o -o %t4
62; RUN: llvm-bcanalyzer -dump %t4.index.bc | FileCheck %s --check-prefix=COMBINED
63; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
64
65; Test --plugin-opt=obj-path to ensure unique object files generated.
66; RUN: rm -f %t5.o %t5.o1
67; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
68; RUN:    -m elf_x86_64 \
69; RUN:    --plugin-opt=thinlto \
70; RUN:    --plugin-opt=jobs=2 \
71; RUN:    --plugin-opt=obj-path=%t5.o \
72; RUN:    -shared %t.o %t2.o -o %t4
73; RUN: llvm-nm %t5.o1 | FileCheck %s --check-prefix=NM2
74; RUN: llvm-nm %t5.o2 | FileCheck %s --check-prefix=NM2
75
76; Test to ensure that thinlto-index-only with obj-path creates the file.
77; RUN: rm -f %t5.o %t5.o1
78; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
79; RUN:    -m elf_x86_64 \
80; RUN:    --plugin-opt=thinlto \
81; RUN:    --plugin-opt=jobs=2 \
82; RUN:    --plugin-opt=thinlto-index-only \
83; RUN:    --plugin-opt=obj-path=%t5.o \
84; RUN:    -shared %t.o %t2.o -o %t4
85; RUN: llvm-readobj -h %t5.o | FileCheck %s --check-prefix=FORMAT
86; RUN: llvm-nm %t5.o | count 0
87
88; NM: T f
89; NM2: T {{f|g}}
90; FORMAT: Format: ELF64-x86-64
91
92; The backend index for this module contains summaries from itself and
93; Inputs/thinlto.ll, as it imports from the latter.
94; BACKEND1: <MODULE_STRTAB_BLOCK
95; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
96; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
97; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
98; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
99; BACKEND1-NEXT: <VERSION
100; BACKEND1-NEXT: <FLAGS
101; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
102; BACKEND1-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
103; BACKEND1-NEXT: <COMBINED
104; BACKEND1-NEXT: <COMBINED
105; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK
106
107; The backend index for Input/thinlto.ll contains summaries from itself only,
108; as it does not import anything.
109; BACKEND2: <MODULE_STRTAB_BLOCK
110; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp2.o'
111; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
112; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
113; BACKEND2-NEXT: <VERSION
114; BACKEND2-NEXT: <FLAGS
115; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
116; BACKEND2-NEXT: <COMBINED
117; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
118
119; DIS1: ^0 = module: (path: "{{.*}}thinlto.ll.tmp.o", hash: (0, 0, 0, 0, 0))
120; DIS1: ^1 = module: (path: "{{.*}}thinlto.ll.tmp2.o", hash: (0, 0, 0, 0, 0))
121; DIS1: ^2 = gv: (guid: 13146401226427987378, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 1, dsoLocal: 0), insts: 1)))
122; DIS1: ^3 = gv: (guid: 14740650423002898831, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 1, dsoLocal: 0), insts: 2, calls: ((callee: ^2)))))
123
124; DIS2: ^0 = module: (path: "{{.*}}thinlto.ll.tmp2.o", hash: (0, 0, 0, 0, 0))
125; DIS2: ^1 = gv: (guid: 13146401226427987378, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 1, dsoLocal: 0), insts: 1)))
126
127; COMBINED: <MODULE_STRTAB_BLOCK
128; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
129; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
130; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
131; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
132; COMBINED-NEXT: <VERSION
133; COMBINED-NEXT: <FLAGS
134; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
135; COMBINED-NEXT: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
136; COMBINED-NEXT: <COMBINED
137; COMBINED-NEXT: <COMBINED
138; COMBINED-NEXT: </GLOBALVAL_SUMMARY_BLOCK
139
140target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
141target triple = "x86_64-unknown-linux-gnu"
142
143declare void @g(...)
144
145define void @f() {
146entry:
147  call void (...) @g()
148  ret void
149}
150