Skip to content

Commit

Permalink
Fix debug symbol generation (#34154)
Browse files Browse the repository at this point in the history
* Fix debug symbol generation

The debug symbol generation got recently broken. For most of the
shared libraries, the debug symbols were stripped twice due to
the fact that install_clr for them was invoked twice - once for
the default install location and once for the sharedFramework
location and the stripping was executed in both of them. First
stripping stripped the symbols off the target binary and set
so called debuglink in the binary to point to the symbol file.
This debuglink includes a crc32 of the dbg symbols file.
The second stripping tried to strip symbols from the already
stripped binary. That resulted in a small dbg symbols file
that didn't actually contain any useful symbols. Moreover,
it is not possible to set a debuglink in a binary if it is
already set there. So the second attempt failed and the crc
was left set to the crc of the previous debug. Thus when
debugger loads such a binary, it cannot find the debug symbols
file, as the crc doesn't match. And even if it matched, the
data would have no value.

The fix is to modify install_clr so that it has an extra
optional argument to specify the secondary install location and
use just one install_clr per target. The function then does the
stripping just once and the actual installation once or twice
depending on the secondary location argumenbt presence.

* Fix libraries and installer

* Fix installer placement of lib files
  • Loading branch information
janvorli authored Mar 30, 2020
1 parent 85a3d4e commit b186c97
Show file tree
Hide file tree
Showing 31 changed files with 67 additions and 77 deletions.
56 changes: 37 additions & 19 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -291,47 +291,65 @@ function(strip_symbols targetName outputFilename)
endif (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_IOS)

set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
else(CLR_CMAKE_HOST_UNIX)
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb PARENT_SCOPE)
endif(CLR_CMAKE_HOST_UNIX)
endfunction()

function(install_symbols targetName destination_path)
strip_symbols(${targetName} strip_destination_file)
function(install_with_stripped_symbols targetName kind destination)
strip_symbols(${targetName} symbol_file)
install_symbols(${symbol_file} ${destination})
if ("${kind}" STREQUAL "TARGETS")
set(install_source ${targetName})
elseif("${kind}" STREQUAL "PROGRAMS")
set(install_source $<TARGET_FILE:${targetName}>)
else()
message(FATAL_ERROR "The `kind` argument has to be either TARGETS or PROGRAMS, ${kind} was provided instead")
endif()
install(${kind} ${install_source} DESTINATION ${destination})
endfunction()

function(install_symbols symbol_file destination_path)
if(CLR_CMAKE_TARGET_WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION ${destination_path}/PDB)
install(FILES ${symbol_file} DESTINATION ${destination_path}/PDB)
else()
install(FILES ${strip_destination_file} DESTINATION ${destination_path})
install(FILES ${symbol_file} DESTINATION ${destination_path})
endif()
endfunction()

# install_clr(TARGETS TARGETS targetName [targetName2 ...] [DESTINATION destination])
# install_clr(TARGETS TARGETS targetName [targetName2 ...] [ADDITIONAL_DESTINATION destination])
function(install_clr)
set(oneValueArgs DESTINATION)
set(oneValueArgs ADDITIONAL_DESTINATION)
set(multiValueArgs TARGETS)
cmake_parse_arguments(PARSE_ARGV 0 INSTALL_CLR "${options}" "${oneValueArgs}" "${multiValueArgs}")

if ("${INSTALL_CLR_TARGETS}" STREQUAL "")
message(FATAL_ERROR "At least one target must be passed to install_clr(TARGETS )")
endif()

if ("${INSTALL_CLR_DESTINATION}" STREQUAL "")
set(INSTALL_CLR_DESTINATION ".")
set(destinations ".")

if (NOT "${INSTALL_CLR_ADDITIONAL_DESTINATION}" STREQUAL "")
list(APPEND destinations ${INSTALL_CLR_ADDITIONAL_DESTINATION})
endif()

foreach(targetName ${INSTALL_CLR_TARGETS})
list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
install_symbols(${targetName} ${INSTALL_CLR_DESTINATION})

# We don't need to install the export libraries for our DLLs
# since they won't be directly linked against.
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${INSTALL_CLR_DESTINATION})

if(CLR_CMAKE_PGO_INSTRUMENT)
if(WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${INSTALL_CLR_DESTINATION}/PGD OPTIONAL)
endif()
endif()
strip_symbols(${targetName} symbol_file)

foreach(destination in ${destinations})
# We don't need to install the export libraries for our DLLs
# since they won't be directly linked against.
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination})
install_symbols(${symbol_file} ${destination})

if(CLR_CMAKE_PGO_INSTRUMENT)
if(WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
endif()
endif()
endforeach()
endif()
endforeach()
endfunction()
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/src/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ target_link_libraries(createdump

add_dependencies(createdump mscordaccore)

install_clr(TARGETS createdump)
install_clr(TARGETS createdump DESTINATION sharedFramework)
install_clr(TARGETS createdump ADDITIONAL_DESTINATION sharedFramework)
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/clretwrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_library_clr(clretwrc SHARED
)

# add the install targets
install_clr(TARGETS clretwrc)
install_clr(TARGETS clretwrc DESTINATION sharedFramework)
install_clr(TARGETS clretwrc ADDITIONAL_DESTINATION sharedFramework)

add_dependencies(clretwrc eventing_headers)
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/dbgshim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ endif(CLR_CMAKE_HOST_WIN32)
target_link_libraries(dbgshim ${DBGSHIM_LIBRARIES})

# add the install targets
install_clr(TARGETS dbgshim)
install_clr(TARGETS dbgshim DESTINATION sharedFramework)
install_clr(TARGETS dbgshim ADDITIONAL_DESTINATION sharedFramework)
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ endif(CLR_CMAKE_HOST_WIN32)
target_link_libraries(mscordaccore PRIVATE ${COREDAC_LIBRARIES})

# add the install targets
install_clr(TARGETS mscordaccore)
install_clr(TARGETS mscordaccore DESTINATION sharedFramework)
install_clr(TARGETS mscordaccore ADDITIONAL_DESTINATION sharedFramework)

if(CLR_CMAKE_HOST_WIN32)
set(LONG_NAME_HOST_ARCH ${CLR_CMAKE_HOST_ARCH})
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,4 @@ elseif(CLR_CMAKE_HOST_UNIX)
endif(CLR_CMAKE_HOST_WIN32)

# add the install targets
install_clr(TARGETS mscordbi)
install_clr(TARGETS mscordbi DESTINATION sharedFramework)
install_clr(TARGETS mscordbi ADDITIONAL_DESTINATION sharedFramework)
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ if(CLR_CMAKE_TARGET_WIN32)
endif(CLR_CMAKE_TARGET_WIN32)

# add the install targets
install_clr(TARGETS coreclr)
install_clr(TARGETS coreclr DESTINATION sharedFramework)
install_clr(TARGETS coreclr ADDITIONAL_DESTINATION sharedFramework)

# Enable profile guided optimization
add_pgo(coreclr)
3 changes: 1 addition & 2 deletions src/coreclr/src/dlls/mscorrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ if(CLR_CMAKE_HOST_WIN32)
include.rc
)

install_clr(TARGETS mscorrc)
install_clr(TARGETS mscorrc DESTINATION sharedFramework)
install_clr(TARGETS mscorrc ADDITIONAL_DESTINATION sharedFramework)
else()
build_resources(${CMAKE_CURRENT_SOURCE_DIR}/include.rc mscorrc TARGET_CPP_FILE)

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ else()
endif(CLR_CMAKE_HOST_UNIX)

# Shared function for generating JIT
# optional arguments: ADDITIONAL_DESTINATION path
function(add_jit jitName)
if(CLR_CMAKE_TARGET_WIN32)
add_definitions(-DFX_VER_INTERNALNAME_STR=${jitName}.dll)
Expand All @@ -385,7 +386,7 @@ function(add_jit jitName)
)

# add the install targets
install_clr(TARGETS ${jitName})
install_clr(TARGETS ${jitName} ${ARGN})
endfunction()

set(JIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/src/jit/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ if(FEATURE_READYTORUN)
add_definitions(-DFEATURE_READYTORUN_COMPILER)
endif(FEATURE_READYTORUN)

add_jit(clrjit)

# add the install targets
install_clr(TARGETS clrjit DESTINATION sharedFramework)
add_jit(clrjit ADDITIONAL_DESTINATION sharedFramework)

# Enable profile guided optimization
add_pgo(clrjit)
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ set_target_properties(coreclrtraceptprovider PROPERTIES LINKER_LANGUAGE CXX)
# Install the static eventprovider library
_install(TARGETS eventprovider DESTINATION lib)
# Install the static coreclrtraceptprovider library
install_clr(TARGETS coreclrtraceptprovider)
install_clr(TARGETS coreclrtraceptprovider DESTINATION sharedFramework)
install_clr(TARGETS coreclrtraceptprovider ADDITIONAL_DESTINATION sharedFramework)
3 changes: 1 addition & 2 deletions src/coreclr/src/tools/crossgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ add_subdirectory(../../zap ../../zap)
add_subdirectory(../../vm/crossgen ../../vm/crossgen)

# add the install targets
install_clr(TARGETS crossgen)
install_clr(TARGETS crossgen DESTINATION sharedFramework)
install_clr(TARGETS crossgen ADDITIONAL_DESTINATION sharedFramework)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/comhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ if (CLR_CMAKE_TARGET_WIN32)
target_link_libraries(comhost ${WINLIBS})
endif()

install(TARGETS comhost DESTINATION corehost)
install_symbols(comhost corehost)
install_with_stripped_symbols(comhost TARGETS corehost)
target_link_libraries(comhost libhostcommon)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/exe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if(NOT CLR_CMAKE_TARGET_WIN32)
disable_pax_mprotect(${DOTNET_PROJECT_NAME})
endif()

install(TARGETS ${DOTNET_PROJECT_NAME} DESTINATION corehost)
install_symbols(${DOTNET_PROJECT_NAME} corehost)
install_with_stripped_symbols(${DOTNET_PROJECT_NAME} TARGETS corehost)

set_common_libs("exe")
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/fxr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ set(HEADERS

include(../lib.cmake)

install(TARGETS hostfxr DESTINATION corehost)
install_symbols(hostfxr corehost)
install_with_stripped_symbols(hostfxr TARGETS corehost)
target_link_libraries(hostfxr libhostcommon)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/hostpolicy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ set(HEADERS

include(../lib.cmake)

install(TARGETS hostpolicy DESTINATION corehost)
install_symbols(hostpolicy corehost)
install_with_stripped_symbols(hostpolicy TARGETS corehost)
target_link_libraries(hostpolicy libhostcommon)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/ijwhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_AR
target_link_libraries(ijwhost Advapi32.lib Ole32.lib)
endif()

install(TARGETS ijwhost DESTINATION corehost)
install_symbols (ijwhost corehost)
install_with_stripped_symbols(ijwhost TARGETS corehost)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/nethost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ add_definitions(-DFEATURE_LIBHOST=1)
add_definitions(-DNETHOST_EXPORT)

install(FILES nethost.h DESTINATION corehost)
install(TARGETS nethost DESTINATION corehost)
install(TARGETS libnethost DESTINATION corehost)
install_symbols(nethost corehost)
install_with_stripped_symbols(nethost TARGETS corehost)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/test/mockcoreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ endif()

include(../testlib.cmake)

install(TARGETS mockcoreclr DESTINATION corehost_test)
install_symbols(mockcoreclr corehost_test)
install_with_stripped_symbols(mockcoreclr TARGETS corehost_test)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/test/mockhostfxr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ set(SOURCES

include(../testlib.cmake)

install(TARGETS mockhostfxr_2_2 DESTINATION corehost_test)
install_symbols(mockhostfxr_2_2 corehost_test)
install_with_stripped_symbols(mockhostfxr_2_2 TARGETS corehost_test)
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ set(SOURCES

include(../testlib.cmake)

install(TARGETS mockhostpolicy DESTINATION corehost_test)
install_symbols(mockhostpolicy corehost_test)
install_with_stripped_symbols(mockhostpolicy TARGETS corehost_test)
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/test/testexe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/../common.cmake)

add_executable(${DOTNET_PROJECT_NAME} ${SOURCES})

install(TARGETS ${DOTNET_PROJECT_NAME} DESTINATION corehost_test)
install_symbols(${DOTNET_PROJECT_NAME} corehost_test)
install_with_stripped_symbols(${DOTNET_PROJECT_NAME} TARGETS corehost_test)

set_common_libs("exe")
3 changes: 1 addition & 2 deletions src/installer/corehost/cli/winrthost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ endif()

target_link_libraries(winrthost RuntimeObject.lib libhostmisc libhostcommon)

install(TARGETS winrthost DESTINATION corehost)
install_symbols(winrthost corehost)
install_with_stripped_symbols(winrthost TARGETS corehost)
6 changes: 0 additions & 6 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ if(CLR_CMAKE_TARGET_UNIX)
add_definitions(-DTARGET_UNIX)
endif(CLR_CMAKE_TARGET_UNIX)

function(install_library_and_symbols targetName)
install_symbols(${targetName} .)
set(install_source_file $<TARGET_FILE:${targetName}>)
install(PROGRAMS ${install_source_file} DESTINATION .)
endfunction()

include(configure.cmake)

add_subdirectory(System.IO.Compression.Native)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (GEN_SHARED_LIB)
dl
)

install_library_and_symbols (System.Globalization.Native)
install_with_stripped_symbols (System.Globalization.Native PROGRAMS .)
endif()

add_library(System.Globalization.Native-Static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (GEN_SHARED_LIB)
target_link_libraries(System.IO.Compression.Native
${ZLIB_LIBRARIES}
)
install_library_and_symbols (System.IO.Compression.Native)
install_with_stripped_symbols (System.IO.Compression.Native PROGRAMS .)
endif ()

add_library(System.IO.Compression.Native-Static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ add_library(System.IO.Ports.Native-Static

set_target_properties(System.IO.Ports.Native-Static PROPERTIES OUTPUT_NAME System.IO.Ports.Native CLEAN_DIRECT_OUTPUT 1)

install_library_and_symbols (System.IO.Ports.Native)
install_with_stripped_symbols (System.IO.Ports.Native PROGRAMS .)
install (TARGETS System.IO.Ports.Native-Static DESTINATION .)
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (GEN_SHARED_LIB)
target_link_libraries(System.Native ${INOTIFY_LIBRARY})
endif ()
endif ()
install_library_and_symbols (System.Native)
install_with_stripped_symbols (System.Native PROGRAMS .)
endif ()

add_library(System.Native-Static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ target_link_libraries(System.Net.Security.Native
${LIBGSS}
)

install_library_and_symbols (System.Net.Security.Native)
install_with_stripped_symbols (System.Net.Security.Native PROGRAMS .)
install (TARGETS System.Net.Security.Native-Static DESTINATION .)
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ target_link_libraries(System.Security.Cryptography.Native.Apple
${SECURITY_LIBRARY}
)

install_library_and_symbols (System.Security.Cryptography.Native.Apple)
install_with_stripped_symbols (System.Security.Cryptography.Native.Apple PROGRAMS .)
install (TARGETS System.Security.Cryptography.Native.Apple-Static DESTINATION .)
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ endif()

include(configure.cmake)

install_library_and_symbols (System.Security.Cryptography.Native.OpenSsl)
install_with_stripped_symbols (System.Security.Cryptography.Native.OpenSsl PROGRAMS .)
install (TARGETS System.Security.Cryptography.Native.OpenSsl-Static DESTINATION .)

0 comments on commit b186c97

Please sign in to comment.