1; REQUIRES: x86
2
3; First ensure that the ThinLTO handling in lld handles
4; bitcode without summary sections gracefully and generates index file.
5; RUN: llvm-as %s -o %t.o
6; RUN: llvm-as %p/Inputs/thinlto.ll -o %t2.o
7; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t2.o -o %t3
8; RUN: ls %t2.o.thinlto.bc
9; RUN: not test -e %t3
10; RUN: ld.lld -m elf_x86_64 -shared %t.o %t2.o -o %t4
11; RUN: llvm-nm %t4 | FileCheck %s --check-prefix=NM
12
13; Basic ThinLTO tests.
14; RUN: opt -module-summary %s -o %t.o
15; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
16; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t4.o
17
18; Ensure lld generates an index and not a binary if requested.
19; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t2.o -o %t3
20; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
21; RUN: llvm-bcanalyzer -dump %t2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
22; RUN: not test -e %t3
23
24; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib
25; RUN: rm -f %t2.o.thinlto.bc
26; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o --start-lib %t2.o --end-lib -o %t5
27; RUN: ls %t2.o.thinlto.bc
28
29; Ensure lld writes linked files to linked objects file
30; RUN: ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only=%tlinkedobjfile -shared %t.o %t2.o %t4.o -o %t5
31; RUN: cat %tlinkedobjfile 2>&1 | FileCheck %s --check-prefix=IN1
32; IN1: {{.*}}thinlto.ll.tmp.o
33; IN1-NEXT: {{.*}}thinlto.ll.tmp2.o
34; IN1-NEXT: {{.*}}thinlto.ll.tmp4.o
35
36; Ensure lld generates error if unable to write to index file
37; RUN: rm -f %t4.o.thinlto.bc
38; RUN: touch %t4.o.thinlto.bc
39; RUN: chmod 400 %t4.o.thinlto.bc
40; RUN: not ld.lld -m elf_x86_64 --plugin-opt=thinlto-index-only -shared %t.o %t4.o -o %t5 2>&1 | FileCheck %s --check-prefix=ERR
41; ERR: cannot open {{.*}}4.o.thinlto.bc: {{P|p}}ermission denied
42
43; Ensure lld doesn't generates index files when thinlto-index-only is not enabled
44; RUN: rm -f %t.o.thinlto.bc
45; RUN: rm -f %t2.o.thinlto.bc
46; RUN: rm -f %t4.o.thinlto.bc
47; RUN: ld.lld -m elf_x86_64 -shared %t.o %t2.o %t4.o -o %t5
48; RUN: not ls %t.o.thinlto.bc
49; RUN: not ls %t2.o.thinlto.bc
50; RUN: not ls %t4.o.thinlto.bc
51
52; First force single-threaded mode
53; RUN: rm -f %t.lto.o %t1.lto.o
54; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t.o %t2.o -o %t
55; RUN: llvm-nm %t1.lto.o | FileCheck %s --check-prefix=NM1
56; RUN: llvm-nm %t2.lto.o | FileCheck %s --check-prefix=NM2
57
58; Next force multi-threaded mode
59; RUN: rm -f %t2.lto.o %t21.lto.o
60; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t.o %t2.o -o %t2
61; RUN: llvm-nm %t21.lto.o | FileCheck %s --check-prefix=NM1
62; RUN: llvm-nm %t22.lto.o | FileCheck %s --check-prefix=NM2
63
64; Then check without --thinlto-jobs (which currently default to hardware_concurrency)
65; We just check that we don't crash or fail (as it's not sure which tests are
66; stable on the final output file itself.
67; RUN: ld.lld -shared %t.o %t2.o -o %t2
68
69; Test to ensure that thinlto-index-only with obj-path creates the file.
70; RUN: rm -f %t5.o
71; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t5.o -shared %t.o %t2.o -o %t4
72; RUN: llvm-readobj -h %t5.o | FileCheck %s --check-prefix=FORMAT
73; RUN: llvm-nm %t5.o | count 0
74
75; NM: T f
76; NM1: T f
77; NM1-NOT: U g
78; NM2: T g
79; FORMAT: Format: ELF64-x86-64
80
81; The backend index for this module contains summaries from itself and
82; Inputs/thinlto.ll, as it imports from the latter.
83; BACKEND1: <MODULE_STRTAB_BLOCK
84; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp{{.*}}.o'
85; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp{{.*}}.o'
86; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
87; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
88; BACKEND1: <VERSION
89; BACKEND1: <FLAGS
90; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
91; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
92; BACKEND1: <COMBINED
93; BACKEND1: <COMBINED
94; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
95
96; The backend index for Input/thinlto.ll contains summaries from itself only,
97; as it does not import anything.
98; BACKEND2: <MODULE_STRTAB_BLOCK
99; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp2.o'
100; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
101; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
102; BACKEND2-NEXT: <VERSION
103; BACKEND2-NEXT: <FLAGS
104; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
105; BACKEND2-NEXT: <COMBINED
106; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
107
108target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
109target triple = "x86_64-unknown-linux-gnu"
110
111declare void @g(...)
112
113define void @f() {
114entry:
115  call void (...) @g()
116  ret void
117}
118