[clang] [SYCL][Driver] Pass path to libsycl.so by default for SYCL compilation. (PR #174877)
Srividya Sundaram via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 15:48:52 PST 2026
https://github.com/srividya-sundaram updated https://github.com/llvm/llvm-project/pull/174877
>From abe1af7679a1e07026e628c34ef907fee03923c1 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 7 Jan 2026 14:42:11 -0800
Subject: [PATCH 01/17] [SYCL][Driver] Pass -lsycl by default for SYCL
compilation.
---
clang/include/clang/Options/Options.td | 4 ++++
clang/lib/Driver/ToolChains/Gnu.cpp | 7 +++++++
clang/test/Driver/sycl-offload-jit.cpp | 5 +++++
3 files changed, 16 insertions(+)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index a08100ef9d0cd..b26703823f76d 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7309,6 +7309,10 @@ def fsycl : Flag<["-"], "fsycl">,
HelpText<"Enable SYCL C++ extensions">;
def fno_sycl : Flag<["-"], "fno-sycl">,
HelpText<"Disable SYCL C++ extensions">;
+def nolibsycl : Flag<["-"], "nolibsycl">,
+ Flags<[NoXarchOption]>,
+ Visibility<[ClangOption, CLOption, ]>,
+ HelpText<"Do not link SYCL runtime library">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index ac31a45b557f1..6a94a3a674ab1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -514,6 +514,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+ // For SYCL compilations, pass the linker option '-lsycl' by default to
+ // the clang-linker-wrapper tool which links the SYCL runtime library.
+ if (Args.hasArg(options::OPT_fsycl) &&
+ !Args.hasArg(options::OPT_nolibsycl)) {
+ CmdArgs.push_back("-lsycl");
+ }
+
// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
// forcibly link with libatomic as a workaround.
// TODO: Issue #41880 and D118021.
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index 72c2390a3fe4b..7f8fe64866882 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -29,6 +29,11 @@
// CHK-DEVICE-TRIPLE-SAME: "-O2"
// CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
+// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation.
+// RUN: %clang -### -fsycl %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LSYCL %s
+// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L/lib"{{.*}} "-lsycl"
+
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
// RUN: %clang -### -fsycl -c %s 2>&1 \
>From ed23d5cbe6766b82800d2bb2d2416780cf23d768 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 7 Jan 2026 14:57:11 -0800
Subject: [PATCH 02/17] Remove extra colon.
---
clang/include/clang/Options/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index b26703823f76d..c78158d590a60 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7311,7 +7311,7 @@ def fno_sycl : Flag<["-"], "fno-sycl">,
HelpText<"Disable SYCL C++ extensions">;
def nolibsycl : Flag<["-"], "nolibsycl">,
Flags<[NoXarchOption]>,
- Visibility<[ClangOption, CLOption, ]>,
+ Visibility<[ClangOption, CLOption]>,
HelpText<"Do not link SYCL runtime library">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
>From f15d50f9323bef854edf15f05fcc518d1d83ecf4 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Thu, 8 Jan 2026 14:55:17 -0800
Subject: [PATCH 03/17] Remove redundant visibility code.
---
clang/include/clang/Options/Options.td | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index c78158d590a60..385c7edc65e6d 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7311,7 +7311,6 @@ def fno_sycl : Flag<["-"], "fno-sycl">,
HelpText<"Disable SYCL C++ extensions">;
def nolibsycl : Flag<["-"], "nolibsycl">,
Flags<[NoXarchOption]>,
- Visibility<[ClangOption, CLOption]>,
HelpText<"Do not link SYCL runtime library">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
>From 0f9f975b3d15ce29773b7e9d9cf297fd30fd2ca0 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Fri, 9 Jan 2026 16:38:13 -0800
Subject: [PATCH 04/17] Add -L/path/to/sycl/lib along with -lsycl for SYCL
offload.
---
clang/lib/Driver/ToolChains/Linux.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index cd2c4deb63d14..d8ac80d9e2714 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,6 +370,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
+ // Add -L/path/to/sycl/lib when -fsycl is specified or when libsycl.so is
+ // available. The -lsycl option is added implicitly by -fsycl and links
+ // against the SYCL runtime library (libsycl.so), which is located in this
+ // directory.
+ if (StringRef(D.Dir).starts_with(SysRoot) &&
+ (Args.hasArg(options::OPT_fsycl) ||
+ D.getVFS().exists(D.Dir + "/../lib/libsycl.so")))
+ addPathIfExists(D, D.Dir + "/../lib", Paths);
+
addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
}
>From c828efa58ae642187f1fc735d418d073e8fa48db Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Mon, 12 Jan 2026 11:43:03 -0800
Subject: [PATCH 05/17] Include SYCL header search locations by default for
SYCL compilation.
---
.../clang/Driver/SyclInstallationDetector.h | 5 +++++
clang/lib/Driver/ToolChains/SYCL.cpp | 19 +++++++++++++++----
clang/test/Driver/sycl-offload-jit.cpp | 6 ++++--
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/clang/include/clang/Driver/SyclInstallationDetector.h b/clang/include/clang/Driver/SyclInstallationDetector.h
index 6925ec24bcd29..e2526bb4b3517 100644
--- a/clang/include/clang/Driver/SyclInstallationDetector.h
+++ b/clang/include/clang/Driver/SyclInstallationDetector.h
@@ -16,11 +16,16 @@ namespace driver {
class SYCLInstallationDetector {
public:
+ SYCLInstallationDetector(const Driver &D);
SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args);
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
+
+private:
+ const Driver &D;
+ llvm::SmallVector<llvm::SmallString<128>, 4> InstallationCandidates;
};
} // namespace driver
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 85859f344b491..fa73f808cb090 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "SYCL.h"
#include "clang/Driver/CommonArgs.h"
+#include "llvm/Support/VirtualFileSystem.h"
using namespace clang::driver;
using namespace clang::driver::toolchains;
@@ -14,18 +15,28 @@ using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;
+SYCLInstallationDetector::SYCLInstallationDetector(const Driver &D)
+ : D(D), InstallationCandidates() {
+ InstallationCandidates.emplace_back(D.Dir + "/..");
+}
+
SYCLInstallationDetector::SYCLInstallationDetector(
const Driver &D, const llvm::Triple &HostTriple,
- const llvm::opt::ArgList &Args) {}
+ const llvm::opt::ArgList &Args)
+ : SYCLInstallationDetector(D) {}
void SYCLInstallationDetector::addSYCLIncludeArgs(
const ArgList &DriverArgs, ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nobuiltininc))
return;
- // Add the SYCL header search locations in the specified order.
- // FIXME: Add the header file locations once the SYCL library and headers
- // are properly established within the build.
+ // Add the SYCL header search locations.
+ // These are icluded for both SYCL host and device compilations.
+ SmallString<128> IncludePath(D.Dir);
+ llvm::sys::path::append(IncludePath, "..");
+ llvm::sys::path::append(IncludePath, "include");
+ CC1Args.push_back("-internal-isystem");
+ CC1Args.push_back(DriverArgs.MakeArgString(IncludePath));
}
// Unsupported options for SYCL device compilation.
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index 7f8fe64866882..dca4297ee3c34 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -31,8 +31,10 @@
// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation.
// RUN: %clang -### -fsycl %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK-LSYCL %s
-// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L/lib"{{.*}} "-lsycl"
+// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
+// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include"
+// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include"
+// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L{{.*}}build/bin/../lib"{{.*}} "-lsycl"
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
>From 726509d04e2d7a24bf7705275ebbf4baa72355cf Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Mon, 12 Jan 2026 11:46:45 -0800
Subject: [PATCH 06/17] Fix spelling.
---
clang/lib/Driver/ToolChains/SYCL.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index fa73f808cb090..2a9b2055b73e6 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -31,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
return;
// Add the SYCL header search locations.
- // These are icluded for both SYCL host and device compilations.
+ // These are included for both SYCL host and device compilations.
SmallString<128> IncludePath(D.Dir);
llvm::sys::path::append(IncludePath, "..");
llvm::sys::path::append(IncludePath, "include");
>From cce6d33d0d329d9c59b438f834e0f82e0ceb2e05 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Mon, 12 Jan 2026 13:26:52 -0800
Subject: [PATCH 07/17] Address review comments.
---
clang/lib/Driver/ToolChains/SYCL.cpp | 3 +--
clang/test/Driver/sycl-offload-jit.cpp | 6 +++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 2a9b2055b73e6..da2d196df948e 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -33,8 +33,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
// Add the SYCL header search locations.
// These are included for both SYCL host and device compilations.
SmallString<128> IncludePath(D.Dir);
- llvm::sys::path::append(IncludePath, "..");
- llvm::sys::path::append(IncludePath, "include");
+ llvm::sys::path::append(IncludePath, "..", "include");
CC1Args.push_back("-internal-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(IncludePath));
}
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index dca4297ee3c34..ae3c50067b180 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -32,9 +32,9 @@
// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation.
// RUN: %clang -### -fsycl %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
-// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include"
-// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}build/bin/../include"
-// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L{{.*}}build/bin/../lib"{{.*}} "-lsycl"
+// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin/../include"
+// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin/../include"
+// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L{{.*}}bin/../lib"{{.*}} "-lsycl"
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
>From b284b43dd27b0d15252cb19e50d8f95327df777f Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Mon, 12 Jan 2026 15:38:58 -0800
Subject: [PATCH 08/17] Update comment.
---
clang/test/Driver/sycl-offload-jit.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index ae3c50067b180..39f74e474bdc9 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -30,6 +30,7 @@
// CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation.
+// The test also checks if SYCL header include paths are added to the SYCL host and device compilation.
// RUN: %clang -### -fsycl %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin/../include"
>From 595355de4c10544fdd8e5a870c758fe6bdd275df Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Tue, 13 Jan 2026 13:34:46 -0800
Subject: [PATCH 09/17] Fix comment.
---
clang/lib/Driver/ToolChains/Gnu.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 6a94a3a674ab1..9f8d2a3d2c8a8 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -514,8 +514,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
- // For SYCL compilations, pass the linker option '-lsycl' by default to
- // the clang-linker-wrapper tool which links the SYCL runtime library.
+ // For SYCL compilations, pass -lsycl to the platform linker by default.
if (Args.hasArg(options::OPT_fsycl) &&
!Args.hasArg(options::OPT_nolibsycl)) {
CmdArgs.push_back("-lsycl");
>From 4b2343ba556fc502ade9983ef71001c6cf68cdd8 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Tue, 20 Jan 2026 14:37:51 -0800
Subject: [PATCH 10/17] Pass path to libsycl.so for SYCL compilations.
---
.../clang/Driver/SyclInstallationDetector.h | 7 +++++--
clang/include/clang/Options/Options.td | 6 +-----
clang/lib/Driver/ToolChains/Gnu.cpp | 6 ------
clang/lib/Driver/ToolChains/Linux.cpp | 3 +++
clang/lib/Driver/ToolChains/SYCL.cpp | 17 +++++++++++------
clang/test/Driver/sycl-offload-jit.cpp | 4 ++--
6 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/clang/include/clang/Driver/SyclInstallationDetector.h b/clang/include/clang/Driver/SyclInstallationDetector.h
index e2526bb4b3517..f92228817f045 100644
--- a/clang/include/clang/Driver/SyclInstallationDetector.h
+++ b/clang/include/clang/Driver/SyclInstallationDetector.h
@@ -16,16 +16,19 @@ namespace driver {
class SYCLInstallationDetector {
public:
- SYCLInstallationDetector(const Driver &D);
SYCLInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args);
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
+ // Return the filesystem path to the SYCL runtime library (libsycl.so), that
+ // was detected.
+ StringRef getSYCLRTLibPath() const { return SYCLRTLibPath; }
+
private:
const Driver &D;
- llvm::SmallVector<llvm::SmallString<128>, 4> InstallationCandidates;
+ SmallString<0> SYCLRTLibPath;
};
} // namespace driver
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 385c7edc65e6d..8607cf7f55d94 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7307,11 +7307,7 @@ defm : FlangIgnoredDiagOpt<"target-lifetime">;
let Group = sycl_Group in {
def fsycl : Flag<["-"], "fsycl">,
HelpText<"Enable SYCL C++ extensions">;
-def fno_sycl : Flag<["-"], "fno-sycl">,
- HelpText<"Disable SYCL C++ extensions">;
-def nolibsycl : Flag<["-"], "nolibsycl">,
- Flags<[NoXarchOption]>,
- HelpText<"Do not link SYCL runtime library">;
+def fno_sycl : Flag<["-"], "fno-sycl">, HelpText<"Disable SYCL C++ extensions">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9f8d2a3d2c8a8..ac31a45b557f1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -514,12 +514,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
- // For SYCL compilations, pass -lsycl to the platform linker by default.
- if (Args.hasArg(options::OPT_fsycl) &&
- !Args.hasArg(options::OPT_nolibsycl)) {
- CmdArgs.push_back("-lsycl");
- }
-
// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
// forcibly link with libatomic as a workaround.
// TODO: Issue #41880 and D118021.
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index d8ac80d9e2714..dec455db771a7 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -863,6 +863,9 @@ void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
llvm::SmallVector<std::pair<StringRef, StringRef>> Libraries;
if (ActiveKinds & Action::OFK_HIP)
Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
+ else if (ActiveKinds & Action::OFK_SYCL) {
+ Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(), "libsycl.so");
+ }
for (auto [Path, Library] : Libraries) {
if (Args.hasFlag(options::OPT_frtlib_add_rpath,
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index da2d196df948e..33c2b9b0bc6a8 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -15,15 +15,20 @@ using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;
-SYCLInstallationDetector::SYCLInstallationDetector(const Driver &D)
- : D(D), InstallationCandidates() {
- InstallationCandidates.emplace_back(D.Dir + "/..");
-}
-
SYCLInstallationDetector::SYCLInstallationDetector(
const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args)
- : SYCLInstallationDetector(D) {}
+ : D(D) {
+ // Detect the presence of the SYCL runtime library (libsycl.so) in the
+ // filesystem. This is used to determine whether a usable SYCL installation
+ // is available for the current driver invocation.
+ StringRef SysRoot = D.SysRoot;
+ if (StringRef(D.Dir).starts_with(SysRoot) &&
+ (Args.hasArg(options::OPT_fsycl) ||
+ D.getVFS().exists(D.Dir + "/../lib/libsycl.so"))) {
+ SYCLRTLibPath = D.Dir + "/../lib";
+ }
+}
void SYCLInstallationDetector::addSYCLIncludeArgs(
const ArgList &DriverArgs, ArgStringList &CC1Args) const {
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index 39f74e474bdc9..4015d89a8d9a4 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -29,13 +29,13 @@
// CHK-DEVICE-TRIPLE-SAME: "-O2"
// CHK-DEVICE-TRIPLE: llvm-offload-binary{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
-// Check if -lsycl is passed to clang-linker-wrapper tool by default for SYCL compilation.
+// Check if path to libsycl.so is passed to clang-linker-wrapper tool by default for SYCL compilation.
// The test also checks if SYCL header include paths are added to the SYCL host and device compilation.
// RUN: %clang -### -fsycl %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-LSYCL,CHECK-SYCL-HEADERS-HOST,CHECK-SYCL-HEADERS-DEVICE %s
// CHECK-SYCL-HEADERS-DEVICE: "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin/../include"
// CHECK-SYCL-HEADERS-HOST: "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin/../include"
-// CHECK-LSYCL: clang-linker-wrapper{{.*}} "-L{{.*}}bin/../lib"{{.*}} "-lsycl"
+// CHECK-LSYCL: clang-linker-wrapper{{.*}} "{{.*}}bin/../lib/libsycl.so"
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
>From 5cd742f1a7d43b6b4ca541c2a88c6420e8ade55b Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Tue, 20 Jan 2026 14:50:57 -0800
Subject: [PATCH 11/17] Remove passing -L/path/to/sycl/lib
---
clang/lib/Driver/ToolChains/Linux.cpp | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index dec455db771a7..5e62781ba0c1f 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,15 +370,6 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
- // Add -L/path/to/sycl/lib when -fsycl is specified or when libsycl.so is
- // available. The -lsycl option is added implicitly by -fsycl and links
- // against the SYCL runtime library (libsycl.so), which is located in this
- // directory.
- if (StringRef(D.Dir).starts_with(SysRoot) &&
- (Args.hasArg(options::OPT_fsycl) ||
- D.getVFS().exists(D.Dir + "/../lib/libsycl.so")))
- addPathIfExists(D, D.Dir + "/../lib", Paths);
-
addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
}
>From 7819b4b175258fb3abf3cd13c16d2d9b17692ecb Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Tue, 20 Jan 2026 14:56:56 -0800
Subject: [PATCH 12/17] Remove fno-sycl.
---
clang/include/clang/Options/Options.td | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 8607cf7f55d94..347b80ee91e61 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7307,7 +7307,6 @@ defm : FlangIgnoredDiagOpt<"target-lifetime">;
let Group = sycl_Group in {
def fsycl : Flag<["-"], "fsycl">,
HelpText<"Enable SYCL C++ extensions">;
-def fno_sycl : Flag<["-"], "fno-sycl">, HelpText<"Disable SYCL C++ extensions">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
>From 965a5b3317702da7b82ac00aa8b3f075497e0744 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Tue, 20 Jan 2026 14:59:26 -0800
Subject: [PATCH 13/17] Put back accidental removal of fno_sycl
---
clang/include/clang/Options/Options.td | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 347b80ee91e61..bd66afdb38a91 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7307,6 +7307,8 @@ defm : FlangIgnoredDiagOpt<"target-lifetime">;
let Group = sycl_Group in {
def fsycl : Flag<["-"], "fsycl">,
HelpText<"Enable SYCL C++ extensions">;
+def fno_sycl : Flag<["-"], "fno-sycl">,
+ HelpText<"Disable SYCL C++ extensions">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
>From d19e341eeda9525cacc4b1f48bd0dc7da46b3d18 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Thu, 22 Jan 2026 11:04:51 -0800
Subject: [PATCH 14/17] Remove whitespace.
---
clang/include/clang/Options/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index bd66afdb38a91..a08100ef9d0cd 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7308,7 +7308,7 @@ let Group = sycl_Group in {
def fsycl : Flag<["-"], "fsycl">,
HelpText<"Enable SYCL C++ extensions">;
def fno_sycl : Flag<["-"], "fno-sycl">,
- HelpText<"Disable SYCL C++ extensions">;
+ HelpText<"Disable SYCL C++ extensions">;
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
>From 70cb205de2bf589d9b33006915d55eb949588251 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Feb 2026 14:27:22 -0800
Subject: [PATCH 15/17] Remove unnecessary braces.
---
clang/lib/Driver/ToolChains/Linux.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 5e62781ba0c1f..171752c3d840b 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -854,9 +854,8 @@ void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
llvm::SmallVector<std::pair<StringRef, StringRef>> Libraries;
if (ActiveKinds & Action::OFK_HIP)
Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
- else if (ActiveKinds & Action::OFK_SYCL) {
+ else if (ActiveKinds & Action::OFK_SYCL)
Libraries.emplace_back(SYCLInstallation->getSYCLRTLibPath(), "libsycl.so");
- }
for (auto [Path, Library] : Libraries) {
if (Args.hasFlag(options::OPT_frtlib_add_rpath,
>From e879c4e5567d0dc7a7b8ff1e8313a28d2403ddcd Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Feb 2026 15:08:08 -0800
Subject: [PATCH 16/17] Use llvm::sys::path::append.
---
clang/lib/Driver/ToolChains/SYCL.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 33c2b9b0bc6a8..720cda46e74b0 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -23,10 +23,12 @@ SYCLInstallationDetector::SYCLInstallationDetector(
// filesystem. This is used to determine whether a usable SYCL installation
// is available for the current driver invocation.
StringRef SysRoot = D.SysRoot;
- if (StringRef(D.Dir).starts_with(SysRoot) &&
+ SmallString<128> DriverDir(D.Dir);
+ if (DriverDir.starts_with(SysRoot) &&
(Args.hasArg(options::OPT_fsycl) ||
- D.getVFS().exists(D.Dir + "/../lib/libsycl.so"))) {
- SYCLRTLibPath = D.Dir + "/../lib";
+ D.getVFS().exists(DriverDir + "/../lib/libsycl.so"))) {
+ llvm::sys::path::append(DriverDir, "/../lib");
+ SYCLRTLibPath = DriverDir;
}
}
>From 75d0988d0546a3e9eb4f125b361be0af9c0620b3 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Feb 2026 15:48:07 -0800
Subject: [PATCH 17/17] Update llvm::sys::path::append usage.
---
clang/lib/Driver/ToolChains/SYCL.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 720cda46e74b0..033fd98183737 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -27,7 +27,7 @@ SYCLInstallationDetector::SYCLInstallationDetector(
if (DriverDir.starts_with(SysRoot) &&
(Args.hasArg(options::OPT_fsycl) ||
D.getVFS().exists(DriverDir + "/../lib/libsycl.so"))) {
- llvm::sys::path::append(DriverDir, "/../lib");
+ llvm::sys::path::append(DriverDir, "..", "lib");
SYCLRTLibPath = DriverDir;
}
}
More information about the cfe-commits
mailing list