Debian Codegraph @

cross-project-tests/dtlto/savetemps.test

raw
1 REQUIRES: ld.lld
2
3 # Test that DTLTO temporary files are "best-effort" cleaned up unless
4 # --save-temps is specified. We use archives in this test as the handling for
5 # archives requires a superset of the temporary files used for object inputs.
6
7 RUN: rm -rf %t && split-file %s %t && cd %t
8
9 RUN: %clang --target=x86_64-linux-gnu -O2 t1.c t2.c -flto=thin -c
10
11 RUN: llvm-ar rcs t.a t1.o t2.o
12
13 DEFINE: %{tdir} = dummy-to-make-lit-work
14 DEFINE: %{action} = dummy-to-make-lit-work
15 DEFINE: %{test-temps-dtlto} = \
16 DEFINE: mkdir %{tdir} && %python %S/test_temps.py %{tdir} %{action} \
17 DEFINE: %clang --target=x86_64-linux-gnu -nostdlib -O2 -flto=thin \
18 DEFINE: -fuse-ld=lld -Wl,--whole-archive t.a -o %{tdir}/t.elf -shared \
19 DEFINE: -fthinlto-distributor=%python \
20 DEFINE: -Xthinlto-distributor=%S/local_codegen_and_wait.py
21
22 # Check that all temporary files are removed in normal operation.
23 REDEFINE: %{tdir} = empty
24 REDEFINE: %{action} = none
25 RUN: %{test-temps-dtlto}
26 RUN: ls %{tdir} | sort | FileCheck %s --check-prefixes=BOOKEND,ELF
27
28 # Check that --save-temps preserves temporary files.
29 REDEFINE: %{tdir} = savetemps
30 REDEFINE: %{action} = none
31 RUN: %{test-temps-dtlto} -Wl,--save-temps
32 RUN: ls %{tdir} | sort | FileCheck %s --check-prefixes=BOOKEND,TEMPS,INDEX,ELF
33
34 # Check that --thinlto-emit-index-files preserves the index files.
35 REDEFINE: %{tdir} = index
36 REDEFINE: %{action} = none
37 RUN: %{test-temps-dtlto} -Wl,--thinlto-emit-index-files
38 RUN: ls %{tdir} | sort | FileCheck %s --check-prefixes=BOOKEND,INDEX,ELF
39
40 # No files are expected before.
41 BOOKEND-NOT: {{.}}
42 TEMPS: {{^}}t.[[#PID:]].dist-file.json{{$}}
43 # Filename composition: <archive>(<member> at <offset>).<task>.<pid>.<task>.<pid>.native.o.
44 TEMPS: {{^}}t.a(t1.o at [[#T1_OFFSET:]]).1.[[#%X,HEXPID:]].1.[[#PID]].native.o{{$}}
45 INDEX: {{^}}t.a(t1.o at [[#T1_OFFSET:]]).1.[[#%X,HEXPID:]].1.[[#PID:]].native.o.thinlto.bc{{$}}
46 TEMPS: {{^}}t.a(t1.o at [[#T1_OFFSET]]).1.[[#%X,HEXPID]].o{{$}}
47 TEMPS: {{^}}t.a(t2.o at [[#T2_OFFSET:]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o{{$}}
48 INDEX: {{^}}t.a(t2.o at [[#T2_OFFSET:]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o.thinlto.bc{{$}}
49 TEMPS: {{^}}t.a(t2.o at [[#T2_OFFSET]]).2.[[#%X,HEXPID]].o{{$}}
50 ELF: {{^}}t.elf{{$}}
51 TEMPS: {{^}}t.elf.resolution.txt{{$}}
52 # No files are expected after.
53 BOOKEND-NOT: {{.}}
54
55 # Check that no warnings are produced if temporary files are missing. Note that
56 # the use of the name "removed" for the output directory triggers special
57 # behaviour in test_temps.py.
58 REDEFINE: %{tdir} = removed
59 REDEFINE: %{action} = remove
60 RUN: %{test-temps-dtlto} 2>&1 | FileCheck %s --check-prefix=NOWARN --allow-empty
61 RUN: ls %{tdir} | sort | FileCheck %s --check-prefixes=BOOKEND,ELF
62 # Sanity check for the expected test_temps.py behaviour.
63 NOWARN: Remove non-essential files in the output directory.
64 NOWARN-NOT: warning
65
66 #--- t1.c
67 __attribute__((retain)) int t1(int x) { return x; }
68
69 #--- t2.c
70 __attribute__((retain)) int t2(int x) { return x; }