Skip to content

Commit 8d66114

Browse files
authored
[Clang] Only link C device libraries by default for OpenMP (#151239)
Summary: We link these implicitly for OpenMP because it's the canonical implementation of those C language features. This was inhereted by HIP and ended up with these resolving functions. There are some useful functions in here, but this can be problematic as it could potentially override functions intended to be provided by the ROCm device libraries. Additionally the HIP runtime does not currently provide the handling for the RPC server required to run the host resources so those just segfault.
1 parent b54709e commit 8d66114

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9214,8 +9214,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92149214
options::OPT_nogpulibc)) {
92159215
forAllAssociatedToolChains(C, JA, getToolChain(), [&](const ToolChain &TC) {
92169216
// The device C library is only available for NVPTX and AMDGPU targets
9217-
// currently.
9218-
if (!TC.getTriple().isNVPTX() && !TC.getTriple().isAMDGPU())
9217+
// and we only link it by default for OpenMP currently.
9218+
if ((!TC.getTriple().isNVPTX() && !TC.getTriple().isAMDGPU()) ||
9219+
!JA.isHostOffloading(Action::OFK_OpenMP))
92199220
return;
92209221
bool HasLibC = TC.getStdlibIncludePath().has_value();
92219222
if (HasLibC) {

clang/test/Driver/gpu-libc-headers.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

clang/test/Driver/gpu-libc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx90a --sysroot=%S/Inputs/basic_gpu_tree \
2+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS-AMDGPU
3+
// RUN: %clang -### --target=nvptx64-nvidia-cuda -march=sm_89 --sysroot=%S/Inputs/basic_gpu_tree \
4+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS-NVPTX
5+
// CHECK-HEADERS-AMDGPU: "-cc1"{{.*}}"-isysroot"{{.*}}"-internal-isystem" "{{.*}}include{{.*}}amdgcn-amd-amdhsa"
6+
// CHECK-HEADERS-NVPTX: "-cc1"{{.*}}"-isysroot"{{.*}}"-internal-isystem" "{{.*}}include{{.*}}nvptx64-nvidia-cuda"
7+
8+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
9+
// RUN: -nogpuinc %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS-DISABLED
10+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
11+
// RUN: -nostdinc %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS-DISABLED
12+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -nogpulib \
13+
// RUN: -nobuiltininc %s 2>&1 | FileCheck %s --check-prefix=CHECK-HEADERS-DISABLED
14+
// CHECK-HEADERS-DISABLED-NOT: "-cc1"{{.*}}"-internal-isystem" "{{.*}}include{{.*}}gpu-none-llvm"
15+
16+
17+
// RUN: %clang -### -fopenmp=libomp --target=x86_64-unknown-linux-gnu \
18+
// RUN: --offload-arch=gfx908 --rocm-path=%S/Inputs/rocm --sysroot=%S/Inputs/basic_gpu_tree \
19+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin %s 2>&1 | FileCheck %s --check-prefix=OPENMP-AMDGPU
20+
// OPENMP-AMDGPU: clang-linker-wrapper{{.*}}"--device-linker=amdgcn-amd-amdhsa=-lc"
21+
// RUN: %clang -### -fopenmp=libomp --target=x86_64-unknown-linux-gnu -foffload-lto \
22+
// RUN: --offload-arch=sm_52 --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda --sysroot=%S/Inputs/basic_gpu_tree \
23+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin %s 2>&1 | FileCheck %s --check-prefix=OPENMP-NVPTX
24+
// OPENMP-NVPTX: clang-linker-wrapper{{.*}}"--device-linker=nvptx64-nvidia-cuda=-lc"
25+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx908 \
26+
// RUN: --offload-new-driver --rocm-path=%S/Inputs/rocm --sysroot=%S/Inputs/basic_gpu_tree \
27+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin -x hip %s 2>&1 | FileCheck %s --check-prefix=HIP
28+
// HIP-NOT: "--device-linker=amdgcn-amd-amdhsa=-lc"
29+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fgpu-rdc --offload-arch=sm_52 \
30+
// RUN: --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda --sysroot=%S/Inputs/basic_gpu_tree \
31+
// RUN: -ccc-install-dir %S/Inputs/basic_gpu_tree/bin -x cuda %s 2>&1 | FileCheck %s --check-prefix=CUDA
32+
// CUDA-NOT: "--device-linker=nvptx64-nvidia-cuda=-lc"

0 commit comments

Comments
 (0)