Skip to content

[Driver][SYCL] Update sycl lib linking with -fms-runtime-lib #19380

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 1 commit into from
Jul 16, 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
26 changes: 11 additions & 15 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5428,19 +5428,13 @@ static void ProcessVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
// Add SYCL dependent library
if (Args.hasArg(options::OPT_fsycl) &&
!Args.hasArg(options::OPT_nolibsycl)) {
if (RTOptionID == options::OPT__SLASH_MDd) {
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
"-previewd");
else
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
} else {
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
"-preview");
else
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION);
}
SmallString<128> SYCLLibName("sycl" SYCL_MAJOR_VERSION);
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
SYCLLibName += "-preview";
if (RTOptionID == options::OPT__SLASH_MDd)
SYCLLibName += "d";
CmdArgs.push_back(
Args.MakeArgString(Twine("--dependent-lib=") + SYCLLibName));
CmdArgs.push_back("--dependent-lib=sycl-devicelib-host");
}
}
Expand Down Expand Up @@ -7045,11 +7039,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Add the sycld debug library when --dependent-lib=msvcrtd is used from
// the command line. This is to allow for CMake based builds using the
// Linux based driver on Windows to correctly pull in the expected debug
// library.
// library. Do not add when -fms-runtime-lib is used, as that pulls in the
// libraries separately.
if (Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl) &&
!D.IsCLMode()) {
if (TC.getTriple().isWindowsMSVCEnvironment()) {
if (isDependentLibAdded(Args, "msvcrtd")) {
if (isDependentLibAdded(Args, "msvcrtd") &&
!Args.hasArg(options::OPT_fms_runtime_lib_EQ)) {
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
"-previewd");
Expand Down
9 changes: 6 additions & 3 deletions clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.hasArg(options::OPT_fsycl_host_compiler_EQ)) {
CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
TC.getDriver().Dir + "/../lib"));
// When msvcrtd is added via --dependent-lib, we add the sycld
// equivalent. Do not add the -defaultlib as it conflicts.
if (!isDependentLibAdded(Args, "msvcrtd")) {
// When msvcrtd is added via --dependent-lib or -fms-runtime-lib=dll_dbg we
// add the sycld equivalent. Do not add the -defaultlib as it conflicts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*sycl ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference here should be sycld as given the conditions the sycld library will already have been added via different means, so we do not want to add the sycl variant as it will conflict.

StringRef RuntimeVal;
if (const Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ))
RuntimeVal = A->getValue();
if (!isDependentLibAdded(Args, "msvcrtd") && RuntimeVal != "dll_dbg") {
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION "-preview.lib");
else
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-offload-old-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@
// RUN: %clangxx -fsycl --no-offload-new-driver -Xclang --dependent-lib=msvcrtd \
// RUN: -target x86_64-unknown-windows-msvc -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
/// Check sycld is pulled in when -fms-runtime-lib=dll_dbg
// RUN: %clangxx -fsycl --no-offload-new-driver -fms-runtime-lib=dll_dbg \
// RUN: -target x86_64-unknown-windows-msvc -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycl{{[0-9]*}}d"
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycl{{[0-9]*}}.lib"

Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,21 @@
// RUN: %clangxx -fsycl --offload-new-driver -Xclang --dependent-lib=msvcrtd \
// RUN: -target x86_64-unknown-windows-msvc -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
/// Check sycld.lib is pulled in with -fms-runtime-lib=dll_dbg
// RUN: %clangxx -fsycl --offload-new-driver -fms-runtime-lib=dll_dbg \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the behavior if --offload-new-driver is not passed?

// RUN: -target x86_64-unknown-windows-msvc -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycl{{[0-9]*}}d"
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycl{{[0-9]*}}.lib"

/// Only a single instance of sycld should be pulled in when both the
/// -Xclang --dependent-lib=msvcrtd and -fms-runtime-lib=dll_dbg is used.
// RUN: %clangxx -fsycl --offload-new-driver -fms-runtime-lib=dll_dbg -Xclang \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supported in clang_cl mode?

// RUN: --dependent-lib=msvcrtd --target=x86_64-unknown-windows-msvc -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LINK-SYCLD %s
// CHECK-LINK-SYCLD: "--dependent-lib=sycl{{[0-9]*}}d"
// CHECK-LINK-SYCLD-NOT: "--dependent-lib=sycl{{[0-9]*}}d"

/// ###########################################################################

/// Check -Xsycl-target-frontend does not trigger an error when no -fsycl-targets is specified
Expand Down
Loading