Skip to content

Commit b512633

Browse files
authored
[Driver][SYCL] Allow for -l:libname.a to be recognized for SYCL kernels (#17149)
The use of -l:libname.a was not properly recognizing the library passed in to be considered as an archive that contains SYCL kernels. Update the parsing behaviors to check for this syntax.
1 parent 1eccddb commit b512633

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

clang/lib/Driver/Driver.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -3888,8 +3888,21 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
38883888
auto resolveStaticLib = [&](StringRef LibName, bool IsStatic) -> bool {
38893889
if (!LibName.starts_with("-l"))
38903890
return false;
3891+
// Put together the library name. For any -l<arg> type names, we create
3892+
// a full name as lib<arg>.<ext>. For any -l:<arg> type names, we take the
3893+
// literal <arg>.
3894+
SmallString<128> RenderedLibName;
3895+
bool OverrideLinkType = false;
3896+
if (LibName.starts_with("-l:")) {
3897+
RenderedLibName = LibName.substr(3);
3898+
// We override the link type as passed in, as we want to treat the library
3899+
// in question as the name passed in.
3900+
OverrideLinkType = true;
3901+
} else
3902+
RenderedLibName = Twine("lib" + LibName.substr(2) + ".a").str();
3903+
38913904
for (auto &LPath : LibPaths) {
3892-
if (!IsStatic) {
3905+
if (!IsStatic && !OverrideLinkType) {
38933906
// Current linking state is dynamic. We will first check for the
38943907
// shared object and not pull in the static library if it is found.
38953908
SmallString<128> SoLibName(LPath);
@@ -3899,8 +3912,7 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
38993912
return false;
39003913
}
39013914
SmallString<128> FullName(LPath);
3902-
llvm::sys::path::append(FullName,
3903-
Twine("lib" + LibName.substr(2) + ".a").str());
3915+
llvm::sys::path::append(FullName, RenderedLibName);
39043916
if (llvm::sys::fs::exists(FullName)) {
39053917
LibArgs.push_back(Args.MakeArgString(FullName));
39063918
return true;

clang/test/Driver/sycl-offload-old-model.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
7777
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a %s 2>&1 \
7878
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
79+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -l:liblin64.a %s 2>&1 \
80+
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
7981
// IMPLIED_DEVICE_LIB: clang-offload-bundler{{.*}} "-type=aoo"{{.*}} "-targets=sycl-spir64_{{.*}}-unknown-unknown,sycl-spir64-unknown-unknown"{{.*}} "-unbundle"
8082

8183
/// Check that the default device triple is not used with -fno-sycl-link-spirv
@@ -119,6 +121,8 @@
119121
// Device section checking only occur when offloading is enabled
120122
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver %S/Inputs/SYCL/liblin64.a %s 2>&1 \
121123
// RUN: | FileCheck -check-prefix CHECK_SECTION %s
124+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver -L%S/Inputs/SYCL -l:liblin64.a %s 2>&1 \
125+
// RUN: | FileCheck -check-prefix CHECK_SECTION %s
122126
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu %S/Inputs/SYCL/liblin64.a %s 2>&1 \
123127
// RUN: | FileCheck -check-prefix NO_CHECK_SECTION %s
124128
// CHECK_SECTION: {{(/|\\)}}clang-offload-bundler{{.*}} "-type=ao"{{.*}} "-check-section"

clang/test/Driver/sycl-target-mismatch.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
33
// RUN: -### %s 2>&1 \
44
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
5+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -l:liblin64.a \
6+
// RUN: -### %s 2>&1 \
7+
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
58
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -llin64 \
69
// RUN: -### %s 2>&1 \
710
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
@@ -13,6 +16,9 @@
1316
// RUN: %clangxx -fsycl -fsycl-targets=spir64 %S/Inputs/SYCL/liblin64.a \
1417
// RUN: -### %s 2>&1 \
1518
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
19+
// RUN: %clangxx -fsycl -fsycl-targets=spir64 -L%S/Inputs/SYCL -l:liblin64.a \
20+
// RUN: -### %s 2>&1 \
21+
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
1622
// RUN: %clangxx -fsycl -fsycl-targets=spir64 -L%S/Inputs/SYCL -llin64 \
1723
// RUN: -### %s 2>&1 \
1824
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
@@ -22,6 +28,9 @@
2228
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
2329
// RUN: -Wno-sycl-target -### %s 2>&1 \
2430
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
31+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -l:liblin64.a \
32+
// RUN: -Wno-sycl-target -### %s 2>&1 \
33+
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
2534
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
2635
// RUN: -fsycl-force-target=spir64 -### %s 2>&1 \
2736
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG

0 commit comments

Comments
 (0)