xref: /llvm-project/lld/test/ELF/lto/save-temps-eq.ll (revision f7669ba3d9443bc95dd63fa25beea13e6265fdc5)
1;; This test is similar to llvm/test/ThinLTO/X86/selective-save-temps.ll
2
3; REQUIRES: x86
4; UNSUPPORTED: system-windows
5;; Unsupported on Windows due to difficulty with escaping "opt" across platforms.
6;; lit substitutes 'opt' with /path/to/opt.
7
8; RUN: rm -rf %t && mkdir %t && cd %t
9; RUN: mkdir all all2 all3 build subset subset2 && cd build
10
11; RUN: opt -thinlto-bc -o main.o %s
12; RUN: opt -thinlto-bc -o thin1.o %S/Inputs/thinlto.ll
13
14;; Create the .all dir with save-temps saving everything, this will be used to compare
15;; with the output from individualized save-temps later
16; RUN: ld.lld main.o thin1.o --save-temps -o %t/all/a.out
17; RUN: mv a.out.lto.* *.o.*.bc %t/all
18;; Sanity check that everything got moved
19; RUN: ls | count 2
20
21;; Check precedence if both --save-temps and --save-temps= are present
22; RUN: ld.lld main.o thin1.o --save-temps=preopt --save-temps --save-temps=\opt -o %t/all2/a.out
23; RUN: cmp %t/all2/a.out %t/all/a.out
24; RUN: mv a.out.lto.* *.o.* %t/all2
25; RUN: ls | count 2
26; RUN: diff -r %t/all %t/all2
27
28;; The next 9 blocks follow this structure:
29;; for each option of save-temps=
30;;   Run linker and generate files
31;;   Make sure a.out exists and is correct (by diff-ing)
32;;     this is the only file that should recur between runs
33;;   (Also, for some stages, copy the generated files to %t/subset2 to check composability later)
34;;   Move files that were expected to be generated to %t/all3
35;;   Make sure there's no unexpected extra files
36;; After that, we'll diff %t/all and %t/all3 to make sure all contents are identical
37
38;; Check preopt
39; RUN: ld.lld main.o thin1.o --save-temps=preopt
40; RUN: cmp %t/all/a.out a.out && rm -f a.out
41; RUN: cp *.0.preopt.* %t/subset2
42; RUN: mv *.0.preopt.* %t/all3
43; RUN: ls | count 2
44
45;; Check promote
46; RUN: ld.lld main.o thin1.o --save-temps=promote
47; RUN: cmp %t/all/a.out a.out && rm -f a.out
48; RUN: mv *.1.promote* %t/all3
49; RUN: ls | count 2
50
51;; Check internalize
52; RUN: ld.lld main.o thin1.o --save-temps=internalize
53; RUN: cmp %t/all/a.out a.out && rm -f a.out
54; RUN: mv *.2.internalize* %t/all3
55; RUN: ls | count 2
56
57;; Check import
58; RUN: ld.lld main.o thin1.o --save-temps=import
59; RUN: cmp %t/all/a.out a.out && rm -f a.out
60; RUN: mv *.3.import* %t/all3
61; RUN: ls | count 2
62
63;; Check opt
64; RUN: ld.lld main.o thin1.o --save-temps=\opt
65; RUN: cmp %t/all/a.out a.out && rm -f a.out
66; RUN: cp *.4.opt* %t/subset2
67; RUN: mv *.4.opt* %t/all3
68; RUN: ls | count 2
69
70;; Check precodegen
71; RUN: ld.lld main.o thin1.o --save-temps=precodegen
72; RUN: cmp %t/all/a.out a.out && rm -f a.out
73; RUN: mv *.5.precodegen* %t/all3
74; RUN: ls | count 2
75
76;; Check combinedindex
77; RUN: ld.lld main.o thin1.o --save-temps=combinedindex
78; RUN: cmp %t/all/a.out a.out && rm -f a.out
79; RUN: mv *.index.bc %t/all3
80; RUN: mv *.index.dot %t/all3
81; RUN: ls | count 2
82
83;; Check prelink
84; RUN: ld.lld main.o thin1.o --save-temps=prelink
85; RUN: cmp %t/all/a.out a.out && rm -f a.out
86; RUN: cp a.out.lto.*.o %t/subset2
87; RUN: mv a.out.lto.*.o %t/all3
88; RUN: ls | count 2
89
90;; Check resolution
91; RUN: ld.lld main.o thin1.o --save-temps=resolution
92;; %t/all3 needs at least 1 copy of a.out, move it over now since its the last block
93; RUN: mv a.out %t/all3
94; RUN: mv *.resolution.txt %t/all3
95; RUN: ls | count 2
96
97;; If no files were left out from individual stages, the .all3 dir should be identical to .all
98; RUN: diff -r %t/all %t/all3
99
100;; Check multi-stage composability
101;; Similar to the above, but do it with a subset instead.
102;; .all -> .subset, .all3 -> .subset2
103; RUN: ld.lld main.o thin1.o --save-temps=preopt --save-temps=prelink --save-temps=\opt
104; RUN: cmp %t/all/a.out a.out && rm -f a.out
105; RUN: mv *.0.preopt.* %t/subset
106; RUN: mv *.4.opt* %t/subset
107; RUN: mv a.out.lto.*.o %t/subset
108; RUN: ls | count 2
109; RUN: diff -r %t/subset2 %t/subset
110
111;; Check error message
112; RUN: not ld.lld --save-temps=prelink --save-temps=\opt --save-temps=notastage 2>&1 \
113; RUN: | FileCheck %s
114; CHECK: unknown --save-temps value: notastage
115
116target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
117target triple = "x86_64-unknown-linux-gnu"
118
119declare void @g()
120
121define i32 @_start() {
122  call void @g()
123  ret i32 0
124}
125