58 lines · c
1// REQUIRES: amdgpu-registered-target2// REQUIRES: lld3 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 them11// RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -o %t.amdgpu.bc12// 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=gfx120015 16// Test that linker wrapper outputs .hipfb file without -r option for HIP non-RDC17// 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 architectures19// 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 names27// CMD-LINUX-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic:xnack+{{.*}}.img28// CMD-LINUX-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img29// CMD-LINUX-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic:xnack+{{.*}}.img30// CMD-LINUX-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img31 32// On Windows, ':' is replaced with '@' in file names33// CMD-WIN-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic@xnack+{{.*}}.img34// CMD-WIN-DAG: clang{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img35// CMD-WIN-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx9-4-generic@xnack+{{.*}}.img36// CMD-WIN-DAG: ld.lld{{.*}} -o {{.*}}hipfb.amdgcn.gfx1200{{.*}}.img37 38// Verify the fat binary was created39// RUN: test -f %t.hipfb40 41// List code objects in the fat binary42// RUN: clang-offload-bundler -type=o -input=%t.hipfb -list | FileCheck %s --check-prefix=HIP-FATBIN-LIST43 44// HIP-FATBIN-LIST-DAG: hip-amdgcn-amd-amdhsa--gfx9-4-generic:xnack+45// HIP-FATBIN-LIST-DAG: hip-amdgcn-amd-amdhsa--gfx120046// HIP-FATBIN-LIST-DAG: host-x86_64-unknown-linux-gnu-47 48// Extract code objects for both architectures from the fat binary49// Use '-' instead of ':' in file names to avoid issues on Windows50// 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 -unbundle52 53// Verify extracted code objects exist and are not empty54// RUN: test -f %t.gfx9-4-generic-xnack+.co55// RUN: test -s %t.gfx9-4-generic-xnack+.co56// RUN: test -f %t.gfx1200.co57// RUN: test -s %t.gfx1200.co58