Skip to content

Commit

Permalink
[SYCL] Generate and install stripped PDBs for SYCL libraries (#4915)
Browse files Browse the repository at this point in the history
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 <steffen.larsen@intel.com>
  • Loading branch information
steffenlarsen authored Nov 17, 2021
1 parent 0d9b4ae commit 6e5dd48
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(AddSYCLExecutable)
include(SYCLUtils)

set(SYCL_MAJOR_VERSION 5)
set(SYCL_MINOR_VERSION 4)
Expand Down Expand Up @@ -48,6 +49,15 @@ if(MSVC)
# Skip asynchronous C++ exceptions catching and assume "extern C" functions
# never throw C++ exceptions.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")

# Add PDB debug information
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(LLVMCheckLinkerFlag)
llvm_check_linker_flag(CXX "/DEBUG" LINKER_SUPPORTS_DEBUG)
if(LINKER_SUPPORTS_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
add_link_options("/DEBUG")
endif()
endif()

# Get clang's version
Expand Down
21 changes: 21 additions & 0 deletions sycl/cmake/modules/SYCLUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(LLVMCheckLinkerFlag)

# add_stripped_pdb(TARGET_NAME)
#
# Will add option for generating stripped PDB file and install the generated
# file as ${ARG_TARGET_NAME}.pdb in bin folder.
# NOTE: LLD does not currently support /PDBSTRIPPED so the PDB file is optional.
macro(add_stripped_pdb ARG_TARGET_NAME)
llvm_check_linker_flag(CXX "/PDBSTRIPPED:${ARG_TARGET_NAME}.stripped.pdb"
LINKER_SUPPORTS_PDBSTRIPPED)
if(LINKER_SUPPORTS_PDBSTRIPPED)
target_link_options(${ARG_TARGET_NAME}
PRIVATE "/PDBSTRIPPED:${ARG_TARGET_NAME}.stripped.pdb")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}.stripped.pdb"
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
RENAME "${ARG_TARGET_NAME}.pdb"
COMPONENT ${ARG_TARGET_NAME}
OPTIONAL)
endif()
endmacro()
2 changes: 2 additions & 0 deletions sycl/plugins/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ if (MSVC)
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
# which are individually tagged for all pi* symbols in pi.h
target_compile_definitions(pi_cuda PRIVATE __SYCL_BUILD_SYCL_DLL)
# Install stripped PDB
add_stripped_pdb(pi_cuda)
else()
# we set the visibility of all symbols 'hidden' by default.
# In pi.h file, we set exported symbols with visibility==default individually
Expand Down
2 changes: 2 additions & 0 deletions sycl/plugins/esimd_emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ if (MSVC)
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
# which are individually tagged for all pi* symbols in pi.h
target_compile_definitions(pi_esimd_emulator PRIVATE __SYCL_BUILD_SYCL_DLL)
# Install stripped PDB
add_stripped_pdb(pi_esimd_emulator)
else()
# we set the visibility of all symbols 'hidden' by default.
# In pi.h file, we set exported symbols with visibility==default individually
Expand Down
2 changes: 2 additions & 0 deletions sycl/plugins/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ if (MSVC)
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
# which are individually tagged for all pi* symbols in pi.h
target_compile_definitions(pi_level_zero PRIVATE __SYCL_BUILD_SYCL_DLL)
# Install stripped PDB
add_stripped_pdb(pi_level_zero)
else()
# we set the visibility of all symbols 'hidden' by default.
# In pi.h file, we set exported symbols with visibility==default individually
Expand Down
2 changes: 2 additions & 0 deletions sycl/plugins/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if (MSVC)
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
# which are individually tagged for all pi* symbols in pi.h
target_compile_definitions(pi_opencl PRIVATE __SYCL_BUILD_SYCL_DLL)
# Install stripped PDB
add_stripped_pdb(pi_opencl)
else()
# we set the visibility of all symbols 'hidden' by default.
# In pi.h file, we set exported symbols with visibility==default individually
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function(add_sycl_rt_library LIB_NAME)
if (MSVC)
target_compile_definitions(${LIB_OBJ_NAME} PRIVATE __SYCL_BUILD_SYCL_DLL )
target_link_libraries(${LIB_NAME} PRIVATE shlwapi)
# Install stripped PDB
add_stripped_pdb(${LIB_NAME})
else()
target_compile_options(${LIB_OBJ_NAME} PUBLIC
-fvisibility=hidden -fvisibility-inlines-hidden)
Expand Down

0 comments on commit 6e5dd48

Please sign in to comment.