98 lines · c
1// REQUIRES: x86-registered-target2// REQUIRES: nvptx-registered-target3 4#if defined(X)5extern int y;6int foo() { return y; }7 8int x = 0;9#elif defined(Y)10int y = 42;11#elif defined(Z)12int z = 42;13#elif defined(W)14int w = 42;15#elif defined(U)16extern int x;17extern int __attribute__((weak)) w;18 19int bar() {20 return x + w;21}22#else23extern int y;24extern int x;25int baz() { return y + x; }26#endif27 28// Create various inputs to test basic linking and LTO capabilities. Creating a29// 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.o31// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DX -o %t-x.o32// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DY -o %t-y.o33// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DZ -o %t-z.o34// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DW -o %t-w.o35// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -DU -o %t-u.o36// RUN: llvm-ar rcs %t-x.a %t-x.o37// RUN: llvm-ar rcs %t-y.a %t-y.o38// RUN: llvm-ar rcs %t-z.a %t-z.o39// RUN: llvm-ar rcs %t-w.a %t-w.o40// RUN: llvm-ar rcs %t-u.a %t-u.o41 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=ARGS47// ARGS: nvlink{{.*}} -arch sm_52 -foo -o a.out [[INPUT:.+]].cubin48 49//50// Check the symbol resolution for static archives. We expect to only link51// `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=LINK56// 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=FORWARD58// LINK: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin59// FORWARD: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.o {{.*}}-u-{{.*}}.o {{.*}}-y-{{.*}}.o {{.*}}-z-{{.*}}.o {{.*}}-w-{{.*}}.o60 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=LINK66// UNDEFINED: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin{{.*}}-z-{{.*}}.cubin67 68//69// Check that the LTO interface works and properly preserves symbols used in a70// 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=LTO74// LTO: ptxas{{.*}} -m64 -c [[PTX:.+]].s -O3 -arch sm_52 -o [[CUBIN:.+]].cubin75// LTO: nvlink{{.*}} -arch sm_52 -o a.out [[CUBIN]].cubin {{.*}}-u-{{.*}}.cubin {{.*}}-y-{{.*}}.cubin76 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=PATH82// PATH-NOT: --cuda-path=/opt/cuda83 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=PASSES90// PASSES: Running pass: ForceFunctionAttrsPass91 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=PLUGIN97// PLUGIN-NOT: -plugin98