Skip to content

Commit 0d5acd4

Browse files
authored
[SYCL][Driver] Fix fno-gpu-rdc SYCL libraries linking not using opaque pointers (#10418)
Fix fno-gpu-rdc SYCL libraries linking not using opaque pointers for non-SPIR targets. Issue was when specifiying -fno-gpu-rdc for an opaque pointer target, there would be object modules with typed pointers. so llvm-link would need the opaque-pointer flag but that wasn't being added previously due to relying on the default RDC behaviour where the first call to llvm-link linking the SYCL libraries with the kernel module is expected to have the kernel module as the first input. This isn't true in no-rdc mode, where the first input is a SYCL device library, hence checking the RDC mode before setting the state of `LinkSYCLDeviceLibs`. Test checking the behaviour was added as well.
1 parent 4658d2a commit 0d5acd4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
223223
};
224224
size_t InputFileNum = InputFiles.size();
225225
bool LinkSYCLDeviceLibs = (InputFileNum >= 2);
226-
LinkSYCLDeviceLibs = LinkSYCLDeviceLibs && !isSYCLDeviceLib(InputFiles[0]);
226+
// Per-object compilation (or non-relocatable device code mode) requires a
227+
// change in the link dependencies, such that the first input file is no
228+
// longer the prepended kernel BC module. The SYCL device libs are linked
229+
// first and the single output is linked with the kernel module separately.
230+
if (IsRDC) {
231+
LinkSYCLDeviceLibs =
232+
LinkSYCLDeviceLibs && !isSYCLDeviceLib(InputFiles[0]);
233+
} else {
234+
LinkSYCLDeviceLibs = LinkSYCLDeviceLibs && isSYCLDeviceLib(InputFiles[0]);
235+
}
227236
for (size_t Idx = 1; Idx < InputFileNum; ++Idx)
228237
LinkSYCLDeviceLibs =
229238
LinkSYCLDeviceLibs && isSYCLDeviceLib(InputFiles[Idx]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
///
2+
/// Checks that the SYCL libraries modules are first linked with opaque-pointers,
3+
/// when no GPU Relocatable Device Code mode is used.
4+
///
5+
6+
// UNSUPPORTED: system-windows
7+
8+
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -fno-gpu-rdc %s --sysroot=%S/Inputs/SYCL -### 2>&1 \
9+
// RUN: | FileCheck %s -check-prefix=CHECK_NORDC_OPAQUE_PTR
10+
// CHECK_NORDC_OPAQUE_PTR: clang{{.*}}
11+
// CHECK_NORDC_OPAQUE_PTR-NOT: llvm-link
12+
// CHECK_NORDC_OPAQUE_PTR: clang-offload-bundler
13+
// CHECK_NORDC_OPAQUE_PTR: llvm-link{{.*}}"-only-needed"{{.*}}"-opaque-pointers"{{.*}}libsycl-crt{{.*}}libsycl-complex{{.*}}libsycl-complex-fp64{{.*}}libsycl-cmath{{.*}}libsycl-cmath-fp64{{.*}}libsycl-imf{{.*}}libsycl-imf-fp64{{.*}}libsycl-imf-bf16{{.*}}libsycl-fallback-cassert{{.*}}libsycl-fallback-cstring{{.*}}libsycl-fallback-complex{{.*}}libsycl-fallback-complex-fp64{{.*}}libsycl-fallback-cmath
14+
// CHECK_NORDC_OPAQUE_PTR-NOT: "opaque-pointers"
15+
// CHECK_NORDC_OPAQUE_PTR-NEXT: llvm-link{{.*}}sycl-no-gpu-rdc-opaque-pointers{{.*}}libsycl-crt
16+
// CHECK_NORDC_OPAQUE_PTR-NEXT: sycl-post-link

0 commit comments

Comments
 (0)