Debian Codegraph @

cross-project-tests/dtlto/archive.test

raw
1 REQUIRES: x86-registered-target,ld.lld,llvm-ar
2
3 # Test that a DTLTO link succeeds and outputs the expected set of files
4 # correctly when archives are present.
5
6 RUN: rm -rf %t && split-file %s %t && cd %t
7 # Compile sources into bitcode. -O2 is required for cross-module importing.
8 RUN: %clang -O2 --target=x86_64-linux-gnu -flto=thin -c foo.c boo.c moo.c loo.c voo.c main.c
9
10 RUN: llvm-ar rcs archive.a foo.o boo.o moo.o
11 RUN: llvm-ar rcsT archive.thin.a loo.o voo.o
12
13 # Build with DTLTO.
14 RUN: %clang -O2 --target=x86_64-linux-gnu -Werror -flto=thin \
15 RUN: -fuse-ld=lld -nostdlib -e main \
16 RUN: main.o archive.a archive.thin.a -o main.elf \
17 RUN: -Wl,--thinlto-distributor=%python \
18 RUN: -Wl,--thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \
19 RUN: -Wl,--thinlto-remote-compiler=%clang \
20 RUN: -Wl,--save-temps
21
22 # Check that the required output files have been created.
23 RUN: ls | FileCheck %s --check-prefix=OUTPUTS
24
25 # JSON jobs description.
26 OUTPUTS-DAG: {{^}}main.[[#PID:]].dist-file.json
27
28 # Main source.
29 OUTPUTS-DAG: {{^}}main.1.[[#PID]].native.o{{$}}
30 OUTPUTS-DAG: {{^}}main.1.[[#PID]].native.o.thinlto.bc{{$}}
31
32 # Regular archive members.
33 # Filename composition: <archive>(<member> at <offset>).<task>.<pid>.<task>.<pid>.native.o.
34 OUTPUTS-DAG: {{^}}archive.a(boo.o at [[#BOO_OFFSET:]]).2.[[#%X,HEXPID:]].2.[[#PID]].native.o{{$}}
35 OUTPUTS-DAG: {{^}}archive.a(boo.o at [[#BOO_OFFSET]]).2.[[#%X,HEXPID]].2.[[#PID]].native.o.thinlto.bc{{$}}
36
37 OUTPUTS-DAG: {{^}}archive.a(foo.o at [[#FOO_OFFSET:]]).3.[[#%X,HEXPID]].3.[[#PID]].native.o{{$}}
38 OUTPUTS-DAG: {{^}}archive.a(foo.o at [[#FOO_OFFSET]]).3.[[#%X,HEXPID]].3.[[#PID]].native.o.thinlto.bc{{$}}
39
40 OUTPUTS-DAG: {{^}}archive.a(moo.o at [[#MOO_OFFSET:]]).4.[[#%X,HEXPID]].4.[[#PID]].native.o{{$}}
41 OUTPUTS-DAG: {{^}}archive.a(moo.o at [[#MOO_OFFSET]]).4.[[#%X,HEXPID]].4.[[#PID]].native.o.thinlto.bc{{$}}
42
43 # Thin archive members.
44 OUTPUTS-DAG: {{^}}voo.5.[[#PID]].native.o{{$}}
45 OUTPUTS-DAG: {{^}}voo.5.[[#PID]].native.o.thinlto.bc{{$}}
46
47 OUTPUTS-DAG: {{^}}loo.6.[[#PID]].native.o{{$}}
48 OUTPUTS-DAG: {{^}}loo.6.[[#PID]].native.o.thinlto.bc{{$}}
49
50 # Executable file.
51 OUTPUTS-DAG: {{^}}main.elf{{$}}
52
53 #--- foo.c
54 volatile int foo_int;
55 __attribute__((retain)) int foo(int x) { return x + foo_int; }
56
57 #--- boo.c
58 extern int foo(int x);
59 __attribute__((retain)) int boo(int x) { return foo(x); }
60
61 #--- moo.c
62 __attribute__((retain)) int moo() { return 3; }
63
64 #--- loo.c
65 extern int moo(int x);
66 __attribute__((retain)) int loo(int x) { return moo(x); }
67
68 #--- voo.c
69 extern int foo(int x);
70 extern int loo(int x);
71 __attribute__((retain)) int voo(int x) { return foo(x) + loo(x + 1) + 7; }
72
73 #--- main.c
74 extern int boo(int x);
75 extern int moo();
76 extern int voo(int x);
77 __attribute__((retain)) int main(int argc, char** argv) {
78 return boo(argc) + moo() + voo(argc + 3);
79 }