Skip to content

Commit 6e5dd48

Browse files
[SYCL] Generate and install stripped PDBs for SYCL libraries (#4915)
Adds stripped PDB files for SYCL library and the PI plugins when building with MSVC. Full PDB files will also be generated, but only the stripped variants will be installed. The stripped PDB files will only be generated and installed if the used linker supports the /PDBSTRIPPED options. LLD does not currently support this option. If the stripped PDB is not generated, no PDB files are installed for the SYCL libraries and PI plugins. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 0d9b4ae commit 6e5dd48

File tree

7 files changed

+41
-0
lines changed

7 files changed

+41
-0
lines changed

sycl/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)
1111

1212
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1313
include(AddSYCLExecutable)
14+
include(SYCLUtils)
1415

1516
set(SYCL_MAJOR_VERSION 5)
1617
set(SYCL_MINOR_VERSION 4)
@@ -48,6 +49,15 @@ if(MSVC)
4849
# Skip asynchronous C++ exceptions catching and assume "extern C" functions
4950
# never throw C++ exceptions.
5051
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
52+
53+
# Add PDB debug information
54+
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
55+
include(LLVMCheckLinkerFlag)
56+
llvm_check_linker_flag(CXX "/DEBUG" LINKER_SUPPORTS_DEBUG)
57+
if(LINKER_SUPPORTS_DEBUG)
58+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
59+
add_link_options("/DEBUG")
60+
endif()
5161
endif()
5262

5363
# Get clang's version

sycl/cmake/modules/SYCLUtils.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
2+
include(LLVMCheckLinkerFlag)
3+
4+
# add_stripped_pdb(TARGET_NAME)
5+
#
6+
# Will add option for generating stripped PDB file and install the generated
7+
# file as ${ARG_TARGET_NAME}.pdb in bin folder.
8+
# NOTE: LLD does not currently support /PDBSTRIPPED so the PDB file is optional.
9+
macro(add_stripped_pdb ARG_TARGET_NAME)
10+
llvm_check_linker_flag(CXX "/PDBSTRIPPED:${ARG_TARGET_NAME}.stripped.pdb"
11+
LINKER_SUPPORTS_PDBSTRIPPED)
12+
if(LINKER_SUPPORTS_PDBSTRIPPED)
13+
target_link_options(${ARG_TARGET_NAME}
14+
PRIVATE "/PDBSTRIPPED:${ARG_TARGET_NAME}.stripped.pdb")
15+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}.stripped.pdb"
16+
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
17+
RENAME "${ARG_TARGET_NAME}.pdb"
18+
COMPONENT ${ARG_TARGET_NAME}
19+
OPTIONAL)
20+
endif()
21+
endmacro()

sycl/plugins/cuda/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ if (MSVC)
4949
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
5050
# which are individually tagged for all pi* symbols in pi.h
5151
target_compile_definitions(pi_cuda PRIVATE __SYCL_BUILD_SYCL_DLL)
52+
# Install stripped PDB
53+
add_stripped_pdb(pi_cuda)
5254
else()
5355
# we set the visibility of all symbols 'hidden' by default.
5456
# In pi.h file, we set exported symbols with visibility==default individually

sycl/plugins/esimd_emulator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ if (MSVC)
105105
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
106106
# which are individually tagged for all pi* symbols in pi.h
107107
target_compile_definitions(pi_esimd_emulator PRIVATE __SYCL_BUILD_SYCL_DLL)
108+
# Install stripped PDB
109+
add_stripped_pdb(pi_esimd_emulator)
108110
else()
109111
# we set the visibility of all symbols 'hidden' by default.
110112
# In pi.h file, we set exported symbols with visibility==default individually

sycl/plugins/level_zero/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ if (MSVC)
114114
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
115115
# which are individually tagged for all pi* symbols in pi.h
116116
target_compile_definitions(pi_level_zero PRIVATE __SYCL_BUILD_SYCL_DLL)
117+
# Install stripped PDB
118+
add_stripped_pdb(pi_level_zero)
117119
else()
118120
# we set the visibility of all symbols 'hidden' by default.
119121
# In pi.h file, we set exported symbols with visibility==default individually

sycl/plugins/opencl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ if (MSVC)
3232
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
3333
# which are individually tagged for all pi* symbols in pi.h
3434
target_compile_definitions(pi_opencl PRIVATE __SYCL_BUILD_SYCL_DLL)
35+
# Install stripped PDB
36+
add_stripped_pdb(pi_opencl)
3537
else()
3638
# we set the visibility of all symbols 'hidden' by default.
3739
# In pi.h file, we set exported symbols with visibility==default individually

sycl/source/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function(add_sycl_rt_library LIB_NAME)
4848
if (MSVC)
4949
target_compile_definitions(${LIB_OBJ_NAME} PRIVATE __SYCL_BUILD_SYCL_DLL )
5050
target_link_libraries(${LIB_NAME} PRIVATE shlwapi)
51+
# Install stripped PDB
52+
add_stripped_pdb(${LIB_NAME})
5153
else()
5254
target_compile_options(${LIB_OBJ_NAME} PUBLIC
5355
-fvisibility=hidden -fvisibility-inlines-hidden)

0 commit comments

Comments
 (0)