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 generates error if unable to write to index file
30; RUN: rm -f %t4.o.thinlto.bc
31; RUN: touch %t4.o.thinlto.bc
32; RUN: chmod 400 %t4.o.thinlto.bc
33; RUN: 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
34; ERR: failed to write {{.*}}4.o.thinlto.bc: Permission denied
35
36; First force single-threaded mode
37; RUN: rm -f %t.lto.o %t1.lto.o
38; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t.o %t2.o -o %t
39; RUN: llvm-nm %t1.lto.o | FileCheck %s --check-prefix=NM1
40; RUN: llvm-nm %t2.lto.o | FileCheck %s --check-prefix=NM2
41
42; Next force multi-threaded mode
43; RUN: rm -f %t2.lto.o %t21.lto.o
44; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t.o %t2.o -o %t2
45; RUN: llvm-nm %t21.lto.o | FileCheck %s --check-prefix=NM1
46; RUN: llvm-nm %t22.lto.o | FileCheck %s --check-prefix=NM2
47
48; Then check without --thinlto-jobs (which currently default to hardware_concurrency)
49; We just check that we don't crash or fail (as it's not sure which tests are
50; stable on the final output file itself.
51; RUN: ld.lld -shared %t.o %t2.o -o %t2
52
53; NM: T f
54; NM1: T f
55; NM1-NOT: U g
56; NM2: T g
57
58; The backend index for this module contains summaries from itself and
59; Inputs/thinlto.ll, as it imports from the latter.
60; BACKEND1: <MODULE_STRTAB_BLOCK
61; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/thinlto.ll.tmp{{.*}}.o'
62; BACKEND1-NEXT: <ENTRY {{.*}} record string = '{{.*}}/thinlto.ll.tmp{{.*}}.o'
63; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
64; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
65; BACKEND1: <VERSION
66; BACKEND1: <FLAGS
67; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
68; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
69; BACKEND1: <COMBINED
70; BACKEND1: <COMBINED
71; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
72
73; The backend index for Input/thinlto.ll contains summaries from itself only,
74; as it does not import anything.
75; BACKEND2: <MODULE_STRTAB_BLOCK
76; BACKEND2-NEXT: <ENTRY {{.*}} record string = '{{.*}}/thinlto.ll.tmp2.o'
77; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
78; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
79; BACKEND2-NEXT: <VERSION
80; BACKEND2-NEXT: <FLAGS
81; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
82; BACKEND2-NEXT: <COMBINED
83; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
84
85target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
86target triple = "x86_64-unknown-linux-gnu"
87
88declare void @g(...)
89
90define void @f() {
91entry:
92  call void (...) @g()
93  ret void
94}
95