Skip to content

[Driver][SYCL] Allow for -l:libname.a to be recognized for SYCL kernels #17149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3888,8 +3888,21 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
auto resolveStaticLib = [&](StringRef LibName, bool IsStatic) -> bool {
if (!LibName.starts_with("-l"))
return false;
// Put together the library name. For any -l<arg> type names, we create
// a full name as lib<arg>.<ext>. For any -l:<arg> type names, we take the
// literal <arg>.
SmallString<128> RenderedLibName;
bool OverrideLinkType = false;
if (LibName.starts_with("-l:")) {
RenderedLibName = LibName.substr(3);
// We override the link type as passed in, as we want to treat the library
// in question as the name passed in.
OverrideLinkType = true;
} else
RenderedLibName = Twine("lib" + LibName.substr(2) + ".a").str();

for (auto &LPath : LibPaths) {
if (!IsStatic) {
if (!IsStatic && !OverrideLinkType) {
// Current linking state is dynamic. We will first check for the
// shared object and not pull in the static library if it is found.
SmallString<128> SoLibName(LPath);
Expand All @@ -3899,8 +3912,7 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
return false;
}
SmallString<128> FullName(LPath);
llvm::sys::path::append(FullName,
Twine("lib" + LibName.substr(2) + ".a").str());
llvm::sys::path::append(FullName, RenderedLibName);
if (llvm::sys::fs::exists(FullName)) {
LibArgs.push_back(Args.MakeArgString(FullName));
return true;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-offload-old-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
// 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 \
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
// 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 \
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_LIB %s
// IMPLIED_DEVICE_LIB: clang-offload-bundler{{.*}} "-type=aoo"{{.*}} "-targets=sycl-spir64_{{.*}}-unknown-unknown,sycl-spir64-unknown-unknown"{{.*}} "-unbundle"

/// Check that the default device triple is not used with -fno-sycl-link-spirv
Expand Down Expand Up @@ -119,6 +121,8 @@
// Device section checking only occur when offloading is enabled
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver %S/Inputs/SYCL/liblin64.a %s 2>&1 \
// RUN: | FileCheck -check-prefix CHECK_SECTION %s
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --no-offload-new-driver -L%S/Inputs/SYCL -l:liblin64.a %s 2>&1 \
// RUN: | FileCheck -check-prefix CHECK_SECTION %s
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu %S/Inputs/SYCL/liblin64.a %s 2>&1 \
// RUN: | FileCheck -check-prefix NO_CHECK_SECTION %s
// CHECK_SECTION: {{(/|\\)}}clang-offload-bundler{{.*}} "-type=ao"{{.*}} "-check-section"
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/sycl-target-mismatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -l:liblin64.a \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -llin64 \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG
Expand All @@ -13,6 +16,9 @@
// RUN: %clangxx -fsycl -fsycl-targets=spir64 %S/Inputs/SYCL/liblin64.a \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64 -L%S/Inputs/SYCL -l:liblin64.a \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64 -L%S/Inputs/SYCL -llin64 \
// RUN: -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
Expand All @@ -22,6 +28,9 @@
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
// RUN: -Wno-sycl-target -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -L%S/Inputs/SYCL -l:liblin64.a \
// RUN: -Wno-sycl-target -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/liblin64.a \
// RUN: -fsycl-force-target=spir64 -### %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=SPIR64_DIAG
Expand Down
Loading