| 1 |
// REQUIRES: amdgpu-registered-target |
| 2 |
// REQUIRES: lld |
| 3 |
|
| 4 |
// Test HIP non-RDC linker wrapper behavior with new offload driver. |
| 5 |
// The linker wrapper should output .hipfb files directly without using -r option. |
| 6 |
|
| 7 |
// An externally visible variable so static libraries extract. |
| 8 |
__attribute__((visibility("protected"), used)) int x; |
| 9 |
|
| 10 |
// Create device binaries and package them |
| 11 |
// RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -o %t.amdgpu.bc |
| 12 |
// RUN: llvm-offload-binary -o %t.out \ |
| 13 |
// RUN: --image=file=%t.amdgpu.bc,kind=hip,triple=amdgcn-amd-amdhsa,arch=gfx9-4-generic:xnack+ \ |
| 14 |
// RUN: --image=file=%t.amdgpu.bc,kind=hip,triple=amdgcn-amd-amdhsa,arch=gfx1200 |
| 15 |
|
| 16 |
// Test that linker wrapper outputs .hipfb file without -r option for HIP non-RDC |
| 17 |
// The linker wrapper is called directly with the packaged device binary (not embedded in host object) |
| 18 |
// Note: When called directly (not through the driver), the linker wrapper processes architectures |
| 19 |
// from the packaged binary. The test verifies it can process at least one architecture correctly. |
| 20 |
// RUN: %if system-windows %{ \ |
| 21 |
// RUN: clang-linker-wrapper --wrapper-verbose --device-linker=amdgcn-amd-amdhsa=-v --device-compiler=-v --emit-fatbin-only --linker-path=/usr/bin/ld %t.out -o %t.hipfb 2>&1 | FileCheck %s --check-prefix=CMD-WIN \ |
| 22 |
// RUN: %} %else %{ \ |
| 23 |
// RUN: clang-linker-wrapper --wrapper-verbose --device-linker=amdgcn-amd-amdhsa=-v --device-compiler=-v --emit-fatbin-only --linker-path=/usr/bin/ld %t.out -o %t.hipfb 2>&1 | FileCheck %s --check-prefix=CMD-LINUX \ |
| 24 |
// RUN: %} |
| 25 |
|
| 26 |
// On Linux, ':' is preserved in file names |
| 27 |
// CMD-LINUX-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic:xnack+{{.*}}.img |
| 28 |
// CMD-LINUX-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img |
| 29 |
// CMD-LINUX-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic:xnack+{{.*}}.img |
| 30 |
// CMD-LINUX-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img |
| 31 |
|
| 32 |
// On Windows, ':' is replaced with '@' in file names |
| 33 |
// CMD-WIN-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic@xnack+{{.*}}.img |
| 34 |
// CMD-WIN-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img |
| 35 |
// CMD-WIN-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic@xnack+{{.*}}.img |
| 36 |
// CMD-WIN-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img |
| 37 |
|
| 38 |
// Verify the fat binary was created |
| 39 |
// RUN: test -f %t.hipfb |
| 40 |
|
| 41 |
// List code objects in the fat binary |
| 42 |
// RUN: clang-offload-bundler -type=o -input=%t.hipfb -list | FileCheck %s --check-prefix=HIP-FATBIN-LIST |
| 43 |
|
| 44 |
// HIP-FATBIN-LIST-DAG: hip-amdgcn-amd-amdhsa--gfx9-4-generic:xnack+ |
| 45 |
// HIP-FATBIN-LIST-DAG: hip-amdgcn-amd-amdhsa--gfx1200 |
| 46 |
// HIP-FATBIN-LIST-DAG: host-x86_64-unknown-linux-gnu- |
| 47 |
|
| 48 |
// Extract code objects for both architectures from the fat binary |
| 49 |
// Use '-' instead of ':' in file names to avoid issues on Windows |
| 50 |
// RUN: clang-offload-bundler -type=o -targets=hip-amdgcn-amd-amdhsa--gfx9-4-generic:xnack+,hip-amdgcn-amd-amdhsa--gfx1200 \ |
| 51 |
// RUN: -output=%t.gfx9-4-generic-xnack+.co -output=%t.gfx1200.co -input=%t.hipfb -unbundle |
| 52 |
|
| 53 |
// Verify extracted code objects exist and are not empty |
| 54 |
// RUN: test -f %t.gfx9-4-generic-xnack+.co |
| 55 |
// RUN: test -s %t.gfx9-4-generic-xnack+.co |
| 56 |
// RUN: test -f %t.gfx1200.co |
| 57 |
// RUN: test -s %t.gfx1200.co |