xref: /llvm-project/lld/test/wasm/lto/thinlto-index-only.ll (revision 9a450a0096befc91bc947db6410d4c640c3d97cd)
1; RUN: rm -rf %t && split-file %s %t && cd %t
2; RUN: mkdir d
3
4;; First ensure that the ThinLTO handling in lld handles
5;; bitcode without summary sections gracefully and generates index file.
6; RUN: llvm-as 1.ll -o 1.o
7; RUN: llvm-as %p/Inputs/thinlto.ll -o d/2.o
8; RUN: wasm-ld --thinlto-index-only -shared 1.o d/2.o -o 3
9; RUN: ls d/2.o.thinlto.bc
10; RUN: not test -e 3
11; RUN: wasm-ld -shared 1.o d/2.o -o 3
12; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM
13
14;; Basic ThinLTO tests.
15; RUN: llvm-as 0.ll -o 0.o
16; RUN: opt -module-summary 1.ll -o 1.o
17; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o
18; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o 3.o
19; RUN: cp 3.o 4.o
20
21;; Ensure lld doesn't generates index files when --thinlto-index-only is not enabled.
22; RUN: rm -f 1.o.thinlto.bc d/2.o.thinlto.bc
23; RUN: wasm-ld -shared 1.o d/2.o -o /dev/null
24; RUN: not ls 1.o.thinlto.bc
25; RUN: not ls d/2.o.thinlto.bc
26
27;; Ensure lld generates an index and not a binary if requested.
28; RUN: wasm-ld --thinlto-index-only -shared 1.o --start-lib d/2.o 3.o --end-lib 4.o -o 4
29; RUN: not test -e 4
30; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
31; RUN: llvm-bcanalyzer -dump d/2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
32; RUN: llvm-dis < 3.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND3
33; RUN: llvm-dis < 4.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND4
34
35; RUN: rm -f 1.o.thinlto.bc d/2.o.thinlto.bc 3.o.thinlto.bc 4.o.thinlto.bc
36; RUN: wasm-ld --thinlto-index-only=4.txt --thinlto-emit-imports-files -shared 1.o --start-lib d/2.o 3.o --end-lib 4.o -o 4
37; RUN: not test -e 4
38; RUN: FileCheck %s --check-prefix=RSP --implicit-check-not={{.}} < 4.txt
39; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
40; RUN: llvm-bcanalyzer -dump d/2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2
41; RUN: llvm-dis < 3.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND3
42; RUN: llvm-dis < 4.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND4
43; RUN: FileCheck %s --check-prefix=IMPORTS1 --implicit-check-not={{.}} < 1.o.imports
44; RUN: count 0 < d/2.o.imports
45;; Test that LLD generates an empty index even for lazy object file that is not added to link.
46; RUN: count 0 < 3.o.imports
47; RUN: count 0 < 4.o.imports
48
49;; Test interaction with --save-temps.
50; RUN: rm -f 4.txt 1.o.thinlto.bc d/2.o.thinlto.bc 3.o.thinlto.bc 4.o.thinlto.bc
51; RUN: wasm-ld --thinlto-index-only=4.txt --thinlto-emit-imports-files --save-temps -shared 0.o 1.o --start-lib d/2.o 3.o --end-lib 4.o -o t
52; RUN: not test -e 4
53; RUN: FileCheck %s --check-prefix=RSP --implicit-check-not={{.}} < 4.txt
54; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1
55; RUN: FileCheck %s --check-prefix=IMPORTS1 --implicit-check-not={{.}} < 1.o.imports
56; RUN: FileCheck %s --check-prefix=RESOLUTION < t.resolution.txt
57; RUN: llvm-dis < t.index.bc | FileCheck %s --check-prefix=INDEX-BC
58
59; RSP:      1.o
60; RSP-NEXT: d/2.o
61; RSP-NEXT: 4.o
62
63; IMPORTS1: d/2.o
64
65; RESOLUTION:      0.o
66; RESOLUTION-NEXT: -r=0.o,foo,px
67; RESOLUTION-NEXT: 1.o
68
69; INDEX-BC:      ^0 = module: (path: "1.o", hash: (0, 0, 0, 0, 0))
70; INDEX-BC-NEXT: ^1 = module: (path: "4.o", hash: (0, 0, 0, 0, 0))
71; INDEX-BC-NEXT: ^2 = module: (path: "d/2.o", hash: (0, 0, 0, 0, 0))
72
73;; Ensure LLD generates an empty index for each bitcode file even if all bitcode files are lazy.
74; RUN: rm -f 1.o.thinlto.bc
75; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown /dev/null -o dummy.o
76; RUN: wasm-ld --thinlto-index-only -shared dummy.o --start-lib 1.o --end-lib -o /dev/null
77; RUN: ls 1.o.thinlto.bc
78
79;; Ensure when the same bitcode object is given as both lazy and non-lazy,
80;; LLD does not generate an empty index for the lazy object.
81; RUN: rm -f d/2.o.thinlto.bc
82; RUN: wasm-ld --thinlto-index-only -shared 1.o d/2.o --start-lib d/2.o --end-lib -o /dev/null
83; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
84; RUN: rm -f d/2.o.thinlto.bc
85; RUN: wasm-ld --thinlto-index-only -shared --start-lib d/2.o --end-lib d/2.o 1.o -o /dev/null
86; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
87
88;; Ensure when the same lazy bitcode object is given multiple times,
89;; no empty index file is generated if one of the copies is linked.
90; RUN: rm -f d/2.o.thinlto.bc
91; RUN: wasm-ld --thinlto-index-only -shared 1.o --start-lib d/2.o --end-lib --start-lib d/2.o --end-lib -o /dev/null
92; RUN: llvm-dis < d/2.o.thinlto.bc | grep -q '\^0 = module:'
93
94; NM: T f
95
96;; The backend index for this module contains summaries from itself and
97;; Inputs/thinlto.ll, as it imports from the latter.
98; BACKEND1: <MODULE_STRTAB_BLOCK
99; BACKEND1-NEXT: <ENTRY {{.*}} record string = '1.o'
100; BACKEND1-NEXT: <ENTRY {{.*}} record string = 'd/2.o'
101; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
102; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
103; BACKEND1: <VERSION
104; BACKEND1: <FLAGS
105; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
106; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
107; BACKEND1: <COMBINED
108; BACKEND1: <COMBINED
109; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
110
111;; The backend index for Input/thinlto.ll contains summaries from itself only,
112;; as it does not import anything.
113; BACKEND2: <MODULE_STRTAB_BLOCK
114; BACKEND2-NEXT: <ENTRY {{.*}} record string = 'd/2.o'
115; BACKEND2-NEXT: </MODULE_STRTAB_BLOCK
116; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
117; BACKEND2-NEXT: <VERSION
118; BACKEND2-NEXT: <FLAGS
119; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
120; BACKEND2-NEXT: <COMBINED
121; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
122
123; BACKEND3: ^0 = flags:
124
125; BACKEND4: ^0 = module: (path: "4.o", hash: (0, 0, 0, 0, 0))
126
127;--- 0.ll
128target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
129target triple = "wasm32-unknown-unknown"
130
131define void @foo() {
132  ret void
133}
134
135;--- 1.ll
136target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
137target triple = "wasm32-unknown-unknown"
138
139declare void @g(...)
140
141define void @f() {
142entry:
143  call void (...) @g()
144  ret void
145}
146