Skip to content

Commit 42230e2

Browse files
authored
[LinkerWrapper] Allow 'all' as a generic bundled architecture (#81193)
Summary: Currently, the linker wrapper sorts input files into different link jobs according to their architectures. Here we assume each architecture is a unique and incompatible link job unless they are specifically marked compatible. This patch simply adds an `all` target to represent an architecture that should be linked against every single other architecture. This will be useful for modelling generic IR such as the ROCm device libraries or the NVPTX libdevice.
1 parent 9211e67 commit 42230e2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/test/Driver/linker-wrapper.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ __attribute__((visibility("protected"), used)) int x;
172172
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack+ -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
173173
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
174174

175+
// RUN: clang-offload-packager -o %t-lib.out \
176+
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=all
177+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o -fembed-offload-object=%t-lib.out
178+
// RUN: llvm-ar rcs %t.a %t.o
179+
// RUN: clang-offload-packager -o %t1.out \
180+
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx90a
181+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t1.o -fembed-offload-object=%t1.out
182+
// RUN: clang-offload-packager -o %t2.out \
183+
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908
184+
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t2.o -fembed-offload-object=%t2.out
185+
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
186+
// RUN: --linker-path=/usr/bin/ld -- %t1.o %t2.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=ARCH-ALL
187+
188+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
189+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o
190+
175191
// RUN: clang-offload-packager -o %t.out \
176192
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
177193
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu

llvm/lib/Object/OffloadBinary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ bool object::areTargetsCompatible(const OffloadFile::TargetID &LHS,
355355
if (LHS.first != RHS.first)
356356
return false;
357357

358+
// If the architecture is "all" we assume it is always compatible.
359+
if (LHS.second.equals("all") || RHS.second.equals("all"))
360+
return true;
361+
358362
// Only The AMDGPU target requires additional checks.
359363
llvm::Triple T(LHS.first);
360364
if (!T.isAMDGPU())

0 commit comments

Comments
 (0)