Skip to content

[SYCL] Generate and install stripped PDBs for SYCL libraries #4915

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 2 commits into from
Nov 17, 2021
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
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)
Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also be done for hip plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To my knowledge, the HIP plugin is not currently supported on Windows. As soon as it is, I imagine the CMake will include this entire MSVC section, adjusted for the HIP plugin.

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