| 1 |
REQUIRES: ld.lld,llvm-ar |
| 2 |
|
| 3 |
## Test that a DTLTO link succeeds and outputs the expected set of files |
| 4 |
## correctly when thin archives are present. |
| 5 |
|
| 6 |
RUN: rm -rf %t && split-file %s %t && cd %t |
| 7 |
|
| 8 |
## Compile bitcode. -O2 is required for cross-module importing. |
| 9 |
RUN: %clang -O2 --target=x86_64-linux-gnu -flto=thin -c \ |
| 10 |
RUN: foo.c bar.c dog.c cat.c start.c |
| 11 |
|
| 12 |
## Generate thin archives. |
| 13 |
RUN: llvm-ar rcs foo.a foo.o --thin |
| 14 |
## Create this bitcode thin archive in a subdirectory to test the expansion of |
| 15 |
## the path to a bitcode file that is referenced using "..", e.g., in this case |
| 16 |
## "../bar.o". |
| 17 |
RUN: mkdir lib |
| 18 |
RUN: llvm-ar rcs lib/bar.a bar.o --thin |
| 19 |
## Create this bitcode thin archive with an absolute path entry containing "..". |
| 20 |
RUN: llvm-ar rcs dog.a %t/lib/../dog.o --thin |
| 21 |
## The bitcode member of cat.a will not be used in the link. |
| 22 |
RUN: llvm-ar rcs cat.a cat.o --thin |
| 23 |
RUN: llvm-ar rcs start.a start.o --thin |
| 24 |
|
| 25 |
## Link from a different directory to ensure that thin archive member paths are |
| 26 |
## resolved correctly relative to the archive locations. |
| 27 |
RUN: mkdir %t/out && cd %t/out |
| 28 |
|
| 29 |
RUN: %clang --target=x86_64-linux-gnu -flto=thin -fuse-ld=lld %t/foo.a %t/lib/bar.a ../start.a %t/cat.a \ |
| 30 |
RUN: -Wl,--whole-archive ../dog.a \ |
| 31 |
RUN: -fthinlto-distributor=%python \ |
| 32 |
RUN: -Xthinlto-distributor=%llvm_src_root/utils/dtlto/local.py \ |
| 33 |
RUN: -Wl,--save-temps -nostdlib -Werror |
| 34 |
|
| 35 |
## Check that the required output files have been created. |
| 36 |
RUN: ls | sort | FileCheck %s |
| 37 |
|
| 38 |
## No files are expected before. |
| 39 |
CHECK-NOT: {{.}} |
| 40 |
|
| 41 |
## JSON jobs description. |
| 42 |
CHECK: {{^}}a.[[PID:[a-zA-Z0-9_]+]].dist-file.json{{$}} |
| 43 |
|
| 44 |
## Native output object files and individual summary index files. |
| 45 |
CHECK: {{^}}bar.3.[[PID]].native.o{{$}} |
| 46 |
CHECK: {{^}}bar.3.[[PID]].native.o.thinlto.bc{{$}} |
| 47 |
CHECK: {{^}}dog.1.[[PID]].native.o{{$}} |
| 48 |
CHECK: {{^}}dog.1.[[PID]].native.o.thinlto.bc{{$}} |
| 49 |
CHECK: {{^}}foo.2.[[PID]].native.o{{$}} |
| 50 |
CHECK: {{^}}foo.2.[[PID]].native.o.thinlto.bc{{$}} |
| 51 |
CHECK: {{^}}start.4.[[PID]].native.o{{$}} |
| 52 |
CHECK: {{^}}start.4.[[PID]].native.o.thinlto.bc{{$}} |
| 53 |
|
| 54 |
## No files are expected after. |
| 55 |
CHECK-NOT: {{.}} |
| 56 |
|
| 57 |
|
| 58 |
## It is important that cross-module inlining occurs for this test to show that Clang can |
| 59 |
## successfully load the bitcode file dependencies recorded in the summary indices. |
| 60 |
## Explicitly check that the expected importing has occurred. |
| 61 |
|
| 62 |
RUN: llvm-dis start.4.*.native.o.thinlto.bc -o - | \ |
| 63 |
RUN: FileCheck %s --check-prefixes=FOO,BAR,START |
| 64 |
|
| 65 |
RUN: llvm-dis dog.1.*.native.o.thinlto.bc -o - | \ |
| 66 |
RUN: FileCheck %s --check-prefixes=FOO,BAR,DOG,START |
| 67 |
|
| 68 |
RUN: llvm-dis foo.2.*.native.o.thinlto.bc -o - | \ |
| 69 |
RUN: FileCheck %s --check-prefixes=FOO,BAR,START |
| 70 |
|
| 71 |
RUN: llvm-dis bar.3.*.native.o.thinlto.bc -o - | \ |
| 72 |
RUN: FileCheck %s --check-prefixes=FOO,BAR,START |
| 73 |
|
| 74 |
FOO-DAG: foo.o |
| 75 |
BAR-DAG: bar.o |
| 76 |
DOG-DAG: dog.o |
| 77 |
START-DAG: start.o |
| 78 |
|
| 79 |
|
| 80 |
#--- foo.c |
| 81 |
extern int bar(int), _start(int); |
| 82 |
__attribute__((retain)) int foo(int x) { return x + bar(x) + _start(x); } |
| 83 |
|
| 84 |
#--- bar.c |
| 85 |
extern int foo(int), _start(int); |
| 86 |
__attribute__((retain)) int bar(int x) { return x + foo(x) + _start(x); } |
| 87 |
|
| 88 |
#--- dog.c |
| 89 |
extern int foo(int), bar(int), _start(int); |
| 90 |
__attribute__((retain)) int dog(int x) { return x + foo(x) + bar(x) + _start(x); } |
| 91 |
|
| 92 |
#--- cat.c |
| 93 |
__attribute__((retain)) void cat(int x) {} |
| 94 |
|
| 95 |
#--- start.c |
| 96 |
extern int foo(int), bar(int); |
| 97 |
__attribute__((retain)) int _start(int x) { return x + foo(x) + bar(x); } |