1 // REQUIRES: x86-registered-target 2 // REQUIRES: nvptx-registered-target 3 // REQUIRES: amdgpu-registered-target 4 5 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.elf.o 6 7 #if defined(RESOLVES) 8 int __attribute__((visibility("hidden"))) sym; 9 #elif defined(GLOBAL) 10 int __attribute__((visibility("protected"))) global; 11 #elif defined(WEAK) 12 int __attribute__((visibility("hidden"))) weak; 13 #elif defined(HIDDEN) 14 int __attribute__((visibility("hidden"))) hidden; 15 #elif defined(UNDEFINED) 16 extern int sym; 17 int baz() { return sym; } 18 #else 19 extern int sym; 20 21 extern int __attribute__((weak)) weak; 22 23 int foo() { return sym; } 24 int bar() { return weak; } 25 #endif 26 27 // 28 // Check that we extract a static library defining an undefined symbol. 29 // 30 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DRESOLVES -o %t.nvptx.resolves.bc 31 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DRESOLVES -o %t.amdgpu.resolves.bc 32 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DUNDEFINED -o %t.nvptx.undefined.bc 33 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DUNDEFINED -o %t.amdgpu.undefined.bc 34 // RUN: clang-offload-packager -o %t-lib.out \ 35 // RUN: --image=file=%t.nvptx.undefined.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 36 // RUN: --image=file=%t.amdgpu.undefined.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \ 37 // RUN: --image=file=%t.nvptx.resolves.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 38 // RUN: --image=file=%t.amdgpu.resolves.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 39 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 40 // RUN: llvm-ar rcs %t.a %t.o 41 // RUN: clang-offload-packager -o %t.out \ 42 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 43 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 44 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 45 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 46 // RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \ 47 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 48 // RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \ 49 // RUN: | FileCheck %s --check-prefix=LIBRARY-RESOLVES 50 51 // LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o 52 // LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o 53 54 // 55 // Check that we extract a static library that defines a global visibile to the 56 // host. 57 // 58 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DGLOBAL -o %t.nvptx.global.bc 59 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DGLOBAL -o %t.amdgpu.global.bc 60 // RUN: clang-offload-packager -o %t-lib.out \ 61 // RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 62 // RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 63 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 64 // RUN: llvm-ar rcs %t.a %t.o 65 // RUN: clang-offload-packager -o %t.out \ 66 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 67 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 68 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 69 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 70 // RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \ 71 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 72 // RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \ 73 // RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL 74 75 // LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o 76 // LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o 77 78 // 79 // Check that we do not extract a global symbol if the source file was not 80 // created by an offloading language that expects there to be a host version of 81 // the symbol. 82 // 83 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DGLOBAL -o %t.nvptx.global.bc 84 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DGLOBAL -o %t.amdgpu.global.bc 85 // RUN: clang-offload-packager -o %t-lib.out \ 86 // RUN: --image=file=%t.nvptx.global.bc,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 87 // RUN: --image=file=%t.amdgpu.global.bc,triple=amdgcn-amd-amdhsa,arch=gfx1030 88 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 89 // RUN: llvm-ar rcs %t.a %t.o 90 // RUN: clang-offload-packager -o %t.out \ 91 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 92 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 93 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 94 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 95 // RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \ 96 // RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL-NONE 97 98 // LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o 99 // LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o 100 101 // 102 // Check that we do not extract an external weak symbol. 103 // 104 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DWEAK -o %t.nvptx.weak.bc 105 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DWEAK -o %t.amdgpu.weak.bc 106 // RUN: clang-offload-packager -o %t-lib.out \ 107 // RUN: --image=file=%t.nvptx.weak.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 108 // RUN: --image=file=%t.amdgpu.weak.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 109 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 110 // RUN: llvm-ar rcs %t.a %t.o 111 // RUN: clang-offload-packager -o %t.out \ 112 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 113 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 114 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 115 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 116 // RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \ 117 // RUN: | FileCheck %s --check-prefix=LIBRARY-WEAK 118 119 // LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 120 // LIBRARY-WEAK-NOT: {{.*}}.o {{.*}}.o 121 // LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 122 123 // 124 // Check that we do not extract an unneeded hidden symbol. 125 // 126 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DHIDDEN -o %t.nvptx.hidden.bc 127 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DHIDDEN -o %t.amdgpu.hidden.bc 128 // RUN: clang-offload-packager -o %t-lib.out \ 129 // RUN: --image=file=%t.nvptx.hidden.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 130 // RUN: --image=file=%t.amdgpu.hidden.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 131 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 132 // RUN: llvm-ar rcs %t.a %t.o 133 // RUN: clang-offload-packager -o %t.out \ 134 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 135 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 136 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 137 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 138 // RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \ 139 // RUN: | FileCheck %s --check-prefix=LIBRARY-HIDDEN 140 141 // LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 142 // LIBRARY-HIDDEN-NOT: {{.*}}.o {{.*}}.o 143 // LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 144 145 // 146 // Check that we do not extract a static library that defines a global visibile 147 // to the host that is already defined. 148 // 149 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DGLOBAL -o %t.nvptx.global.bc 150 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DGLOBAL -o %t.amdgpu.global.bc 151 // RUN: clang-offload-packager -o %t-lib.out \ 152 // RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 153 // RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 154 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 155 // RUN: llvm-ar rcs %t.a %t.o 156 // RUN: clang-offload-packager -o %t.out \ 157 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 158 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 159 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 160 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 161 // RUN: --linker-path=/usr/bin/ld %t.o %t.a %t.a -o a.out 2>&1 \ 162 // RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL-DEFINED 163 164 // LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o 165 // LIBRARY-GLOBAL-DEFINED-NOT: {{.*}}gfx1030{{.*}}.o 166 // LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o 167 168 // 169 // Check that we can use --[no-]whole-archive to control extraction. 170 // 171 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DGLOBAL -o %t.nvptx.global.bc 172 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DGLOBAL -o %t.amdgpu.global.bc 173 // RUN: clang-offload-packager -o %t-lib.out \ 174 // RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 175 // RUN: --image=file=%t.nvptx.global.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_52 \ 176 // RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \ 177 // RUN: --image=file=%t.amdgpu.global.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx90a 178 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out 179 // RUN: llvm-ar rcs %t.a %t.o 180 // RUN: clang-offload-packager -o %t.out \ 181 // RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \ 182 // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 183 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t.out 184 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \ 185 // RUN: --linker-path=/usr/bin/ld %t.o --whole-archive %t.a -o a.out 2>&1 \ 186 // RUN: | FileCheck %s --check-prefix=LIBRARY-WHOLE-ARCHIVE 187 188 // LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o 189 // LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o 190 // LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_52 {{.*}}.o 191 // LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a {{.*}}.o 192