SYCL: Only use whole-archive device link when necessary

Fixes: #28165
This commit is contained in:
Vito Gamberini committed 2026-10-14 12:27:10 -04:00
1 parent 07ebd37501
commit 46ec181d8e
2 files changed
+19 -6

No files matched your search

+1 -5
View File
@@ -134,18 +134,14 @@ if(CMAKE_SYCL_DEVICE_LINK_OPTIONS)
string(JOIN " " pic_options ${CMAKE_SYCL_COMPILE_OPTIONS_PIC})
string(JOIN " " device_pic_options ${CMAKE_SYCL_DEVICE_LINK_OPTIONS_PIC})
string(JOIN " " device_options ${CMAKE_SYCL_DEVICE_LINK_OPTIONS})
string(JOIN " " whole_archive ${CMAKE_SYCL_DEVICE_LINK_OPTIONS_WHOLE_ARCHIVE})
string(JOIN " " no_whole_archive ${CMAKE_SYCL_DEVICE_LINK_OPTIONS_NO_WHOLE_ARCHIVE})
if(NOT CMAKE_SYCL_DEVICE_LINK_LIBRARY)
set(CMAKE_SYCL_DEVICE_LINK_LIBRARY
"<CMAKE_SYCL_COMPILER> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${pic_options} ${device_options} ${device_pic_options} -o <TARGET> ${whole_archive} <OBJECTS> <LINK_LIBRARIES> ${no_whole_archive}")
"<CMAKE_SYCL_COMPILER> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${pic_options} ${device_options} ${device_pic_options} -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()
if(NOT CMAKE_SYCL_DEVICE_LINK_EXECUTABLE)
set(CMAKE_SYCL_DEVICE_LINK_EXECUTABLE "${CMAKE_SYCL_DEVICE_LINK_LIBRARY}")
endif()
unset(device_options)
unset(whole_archive)
unset(no_whole_archive)
unset(pic_options)
unset(device_pic_options)
endif()
+18 -1
View File
@@ -15,6 +15,7 @@
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmLinkItem.h"
#include "cmList.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
@@ -109,6 +110,16 @@ void cmLinkLineDeviceComputer::ComputeLinkLibraries(
ItemVector const& items = cli.GetItems();
std::string config = cli.GetConfig();
bool skipItemAfterFramework = false;
auto const librariesBegin = linkLibraries.size();
cmMakefile const* mf = cli.GetTarget()->Makefile;
std::string const wholeArchive =
cmJoin(cmList(mf->GetSafeDefinition(cmStrCat(
"CMAKE_", this->Language, "_DEVICE_LINK_OPTIONS_WHOLE_ARCHIVE"))),
" ");
std::string const noWholeArchive = cmJoin(
cmList(mf->GetSafeDefinition(cmStrCat(
"CMAKE_", this->Language, "_DEVICE_LINK_OPTIONS_NO_WHOLE_ARCHIVE"))),
" ");
for (auto const& item : items) {
if (skipItemAfterFramework) {
@@ -161,7 +172,7 @@ void cmLinkLineDeviceComputer::ComputeLinkLibraries(
linkLib.Value = item.Value.Value;
}
if (emitted.insert(linkLib.Value).second) {
if (!linkLib.Value.empty() && emitted.insert(linkLib.Value).second) {
linkLib.Value += " ";
cmLinkImplementation const* linkImpl =
@@ -186,6 +197,12 @@ void cmLinkLineDeviceComputer::ComputeLinkLibraries(
if (!stdLibString.empty()) {
linkLibraries.emplace_back(cmStrCat(stdLibString, ' '));
}
if (linkLibraries.size() > librariesBegin && !wholeArchive.empty()) {
linkLibraries.insert(linkLibraries.begin() + librariesBegin,
BT<std::string>(cmStrCat(wholeArchive, ' ')));
linkLibraries.emplace_back(cmStrCat(noWholeArchive, ' '));
}
}
std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*,