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: %gold -plugin %llvmshlibdir/LLVMgold.so \
65; RUN:    -m elf_x86_64 \
66; RUN:    --plugin-opt=thinlto \
67; RUN:    --plugin-opt=jobs=2 \
68; RUN:    --plugin-opt=obj-path=%t5.o \
69; RUN:    -shared %t.o %t2.o -o %t4
70; RUN: llvm-nm %t5.o0 | FileCheck %s --check-prefix=NM2
71; RUN: llvm-nm %t5.o1 | FileCheck %s --check-prefix=NM2
72
73; NM: T f
74; NM2: T {{f|g}}
75
76; The backend index for this module contains summaries from itself and
77; Inputs/thinlto.ll, as it imports from the latter.
78; BACKEND1: <MODULE_STRTAB_BLOCK
79; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
80; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
81; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
82; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
83; BACKEND1-NEXT: <VERSION
84; BACKEND1-NEXT: <COMBINED
85; BACKEND1-NEXT: <COMBINED
86; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK
87; BACKEND1-NEXT: <VALUE_SYMTAB
88; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
89; where funcguid is the lower 64 bits of the function name MD5.
90; BACKEND1-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
91; BACKEND1-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
92; BACKEND1-NEXT: </VALUE_SYMTAB
93
94; The backend index for Input/thinlto.ll contains summaries from itself only,
95; as it does not import anything.
96; BACKEND2: <MODULE_STRTAB_BLOCK
97; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp2.o'
98; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
99; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
100; BACKEND2-NEXT: <VERSION
101; BACKEND2-NEXT: <COMBINED
102; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
103; BACKEND2-NEXT: <VALUE_SYMTAB
104; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
105; where funcguid is the lower 64 bits of the function name MD5.
106; BACKEND2-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0=1 op1=-5300342847281564238
107; BACKEND2-NEXT: </VALUE_SYMTAB
108
109; COMBINED: <MODULE_STRTAB_BLOCK
110; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
111; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
112; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
113; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
114; COMBINED-NEXT: <VERSION
115; COMBINED-NEXT: <COMBINED
116; COMBINED-NEXT: <COMBINED
117; COMBINED-NEXT: </GLOBALVAL_SUMMARY_BLOCK
118; COMBINED-NEXT: <VALUE_SYMTAB
119; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
120; where funcguid is the lower 64 bits of the function name MD5.
121; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
122; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
123; COMBINED-NEXT: </VALUE_SYMTAB
124
125target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
126target triple = "x86_64-unknown-linux-gnu"
127
128declare void @g(...)
129
130define void @f() {
131entry:
132  call void (...) @g()
133  ret void
134}
135