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: <COMBINED
86; BACKEND1-NEXT: <COMBINED
87; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK
88; BACKEND1-NEXT: <VALUE_SYMTAB
89; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
90; where funcguid is the lower 64 bits of the function name MD5.
91; BACKEND1-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
92; BACKEND1-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
93; BACKEND1-NEXT: </VALUE_SYMTAB
94
95; The backend index for Input/thinlto.ll contains summaries from itself only,
96; as it does not import anything.
97; BACKEND2: <MODULE_STRTAB_BLOCK
98; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp2.o'
99; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
100; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
101; BACKEND2-NEXT: <VERSION
102; BACKEND2-NEXT: <COMBINED
103; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
104; BACKEND2-NEXT: <VALUE_SYMTAB
105; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
106; where funcguid is the lower 64 bits of the function name MD5.
107; BACKEND2-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0=1 op1=-5300342847281564238
108; BACKEND2-NEXT: </VALUE_SYMTAB
109
110; COMBINED: <MODULE_STRTAB_BLOCK
111; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
112; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/test/tools/gold/X86/Output/thinlto.ll.tmp{{.*}}.o'
113; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
114; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
115; COMBINED-NEXT: <VERSION
116; COMBINED-NEXT: <COMBINED
117; COMBINED-NEXT: <COMBINED
118; COMBINED-NEXT: </GLOBALVAL_SUMMARY_BLOCK
119; COMBINED-NEXT: <VALUE_SYMTAB
120; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
121; where funcguid is the lower 64 bits of the function name MD5.
122; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
123; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
124; COMBINED-NEXT: </VALUE_SYMTAB
125
126target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
127target triple = "x86_64-unknown-linux-gnu"
128
129declare void @g(...)
130
131define void @f() {
132entry:
133  call void (...) @g()
134  ret void
135}
136