Debian Codegraph @

clang/test/Driver/nvlink-wrapper.c

raw
1 // REQUIRES: x86-registered-target
2 // REQUIRES: nvptx-registered-target
3
4 #if defined(X)
5 extern int y;
6 int foo() { return y; }
7
8 int x = 0;
9 #elif defined(Y)
10 int y = 42;
11 #elif defined(Z)
12 int z = 42;
13 #elif defined(W)
14 int w = 42;
15 #elif defined(U)
16 extern int x;
17 extern int __attribute__((weak)) w;
18
19 int bar() {
20 return x + w;
21 }
22 #else
23 extern int y;
24 extern int x;
25 int baz() { return y + x; }
26 #endif
27
28 // Create various inputs to test basic linking and LTO capabilities. Creating a
29 // CUDA binary requires access to the `ptxas` executable, so we just use x64.
30 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -o %t.o
31 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DX -o %t-x.o
32 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DY -o %t-y.o
33 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DZ -o %t-z.o
34 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DW -o %t-w.o
35 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DU -o %t-u.o
36 // RUN: llvm-ar rcs %t-x.a %t-x.o
37 // RUN: llvm-ar rcs %t-y.a %t-y.o
38 // RUN: llvm-ar rcs %t-z.a %t-z.o
39 // RUN: llvm-ar rcs %t-w.a %t-w.o
40 // RUN: llvm-ar rcs %t-u.a %t-u.o
41
42 //
43 // Check that we forward any unrecognized argument to 'nvlink'.
44 //
45 // RUN: clang-nvlink-wrapper --dry-run --assume-device-object -arch sm_52 %t-u.o -foo -o a.out 2>&1 \
46 // RUN: | FileCheck %s --check-prefix=ARGS
47 // ARGS: nvlink{{.*}} -arch sm_52 -foo -o a.out [[INPUT:.+]].cubin
48
49 //
50 // Check the symbol resolution for static archives. We expect to only link
51 // `libx.a` and `liby.a` because extern weak symbols do not extract and `libz.a`
52 // is not used at all.
53 //
54 // RUN: clang-nvlink-wrapper --dry-run --assume-device-object %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
55 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
56 // RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
57 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=FORWARD
58 // LINK: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin
59 // FORWARD: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.o {{.*}}-u-{{.*}}.o {{.*}}-y-{{.*}}.o {{.*}}-z-{{.*}}.o {{.*}}-w-{{.*}}.o
60
61 //
62 // Same as above but we use '--undefined' to forcibly extract 'libz.a'
63 //
64 // RUN: clang-nvlink-wrapper --dry-run --assume-device-object %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \
65 // RUN: -u z -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK
66 // UNDEFINED: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin{{.*}}-z-{{.*}}.cubin
67
68 //
69 // Check that the LTO interface works and properly preserves symbols used in a
70 // regular object file.
71 //
72 // RUN: clang-nvlink-wrapper --dry-run --assume-device-object %t.o %t-u.o %t-y.a \
73 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LTO
74 // LTO: ptxas{{.*}} -m64 -c [[PTX:.+]].s -O3 -arch sm_52 -o [[CUBIN:.+]].cubin
75 // LTO: nvlink{{.*}} -arch sm_52 -o a.out [[CUBIN]].cubin {{.*}}-u-{{.*}}.cubin {{.*}}-y-{{.*}}.cubin
76
77 //
78 // Check that we don't forward some arguments.
79 //
80 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
81 // RUN: -arch sm_52 --cuda-path/opt/cuda -o a.out 2>&1 | FileCheck %s --check-prefix=PATH
82 // PATH-NOT: --cuda-path=/opt/cuda
83
84 //
85 // Check that passes can be specified and debugged.
86 //
87 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
88 // RUN: --lto-debug-pass-manager --lto-newpm-passes=forceattrs \
89 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=PASSES
90 // PASSES: Running pass: ForceFunctionAttrsPass
91
92 //
93 // Check that '-plugin` is ingored like in `ld.lld`
94 //
95 // RUN: clang-nvlink-wrapper --dry-run %t.o -plugin foo.so -arch sm_52 -o a.out \
96 // RUN: 2>&1 | FileCheck %s --check-prefix=PLUGIN
97 // PLUGIN-NOT: -plugin