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