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 -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 %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 // LINK: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin 57 58 // 59 // Same as above but we use '--undefined' to forcibly extract 'libz.a' 60 // 61 // RUN: clang-nvlink-wrapper --dry-run %t-x.a %t-u.a %t-y.a %t-z.a %t-w.a %t.o \ 62 // RUN: -u z -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LINK 63 // UNDEFINED: nvlink{{.*}} -arch sm_52 -o a.out [[INPUT:.+]].cubin {{.*}}-x-{{.*}}.cubin{{.*}}-y-{{.*}}.cubin{{.*}}-z-{{.*}}.cubin 64 65 // 66 // Check that the LTO interface works and properly preserves symbols used in a 67 // regular object file. 68 // 69 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \ 70 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LTO 71 // LTO: ptxas{{.*}} -m64 -c [[PTX:.+]].s -O3 -arch sm_52 -o [[CUBIN:.+]].cubin 72 // LTO: nvlink{{.*}} -arch sm_52 -o a.out [[CUBIN]].cubin {{.*}}-u-{{.*}}.cubin {{.*}}-y-{{.*}}.cubin 73 74 // 75 // Check that we don't forward some arguments. 76 // 77 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \ 78 // RUN: -arch sm_52 --cuda-path/opt/cuda -o a.out 2>&1 | FileCheck %s --check-prefix=PATH 79 // PATH-NOT: --cuda-path=/opt/cuda 80 81 // 82 // Check that passes can be specified and debugged. 83 // 84 // RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \ 85 // RUN: --lto-debug-pass-manager --lto-newpm-passes=forceattrs \ 86 // RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=PASSES 87 // PASSES: Running pass: ForceFunctionAttrsPass 88 89 // 90 // Check that '-plugin` is ingored like in `ld.lld` 91 // 92 // RUN: clang-nvlink-wrapper --dry-run %t.o -plugin foo.so -arch sm_52 -o a.out \ 93 // RUN: 2>&1 | FileCheck %s --check-prefix=PLUGIN 94 // PLUGIN-NOT: -plugin 95