diff options
author | Omair Majid <omajid@redhat.com> | 2020-10-01 08:28:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 08:28:11 +0300 |
commit | 2f1694ea116cc9819644382861690f17f1c8517b (patch) | |
tree | fbf3357224dd052f12afa5e841a06ef4311e64c4 /eng | |
parent | 746ca52cf3405d9faeb3d2644b56e3761b375002 (diff) |
Add an option to keep native debug symbols (#39203)
When packaging .NET for Linux distributions, the package builders
generally use a different workflow for shipping symbols to users:
1. The package maintainer builds code with the debug flags (such as
`-g`) to generate full native debug info and symbols.
2. Nothing is stripped from build by the package maintainer.
3. The build system (`rpmbuild`, `debuild`) removes the debug
info (or debug symbols) from the code and creates separate
`-debuginfo` or `-debug` packages that contain just the debug
symbols.
4. These debug packages are then distributed along with the normal
packages using the normal Linux distribution mechanisms. This lets
users install the exact set of debug symbols matching their other
package.
To support this workflow in dotnet/runtime, we need to add optional
support for not stripping debug symbols. I used it has follows:
CFLAGS=-g CXXFLAGS=-g ./build.sh --keepnativesymbols true
After this build, the built binaries include all debug symbols.
I can then rely on the distro package build system to identify, strip,
package and ship the debug info/symbols separately.
See https://github.com/dotnet/runtime/issues/3781 and
https://github.com/dotnet/source-build/issues/267 for more details on
the background and motivation.
For some related fixes, see:
- https://github.com/dotnet/coreclr/pull/3445
- https://github.com/dotnet/corefx/pull/24979
Diffstat (limited to 'eng')
-rwxr-xr-x | eng/build.sh | 13 | ||||
-rwxr-xr-x | eng/native/build-commons.sh | 5 | ||||
-rw-r--r-- | eng/native/functions.cmake | 14 |
3 files changed, 28 insertions, 4 deletions
diff --git a/eng/build.sh b/eng/build.sh index f271bb0ca76..1179f8efd27 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -76,6 +76,7 @@ usage() echo " --gcc Optional argument to build using gcc in PATH (default)." echo " --gccx.y Optional argument to build using gcc version x.y." echo " --portablebuild Optional argument: set to false to force a non-portable build." + echo " --keepnativesymbols Optional argument: set to true to keep native symbols/debuginfo in generated binaries." echo "" echo "Command line arguments starting with '/p:' are passed through to MSBuild." @@ -402,6 +403,18 @@ while [[ $# > 0 ]]; do shift 2 ;; + -keepnativesymbols) + if [ -z ${2+x} ]; then + echo "No value for keepNativeSymbols is supplied. See help (--help) for supported values." 1>&2 + exit 1 + fi + passedKeepNativeSymbols="$(echo "$2" | awk '{print tolower($0)}')" + if [ "$passedKeepNativeSymbols" = true ]; then + arguments="$arguments /p:KeepNativeSymbols=true" + fi + shift 2 + ;; + *) extraargs="$extraargs $1" shift 1 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 877ef003bbe..2e94d68fe69 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -225,6 +225,7 @@ usage() echo "-portablebuild: pass -portablebuild=false to force a non-portable build." echo "-skipconfigure: skip build configuration." echo "-skipgenerateversion: disable version generation even if MSBuild is supported." + echo "-keepnativesymbols: keep native/unmanaged debug symbols." echo "-verbose: optional argument to enable verbose build output." echo "" echo "Additional Options:" @@ -354,6 +355,10 @@ while :; do __CompilerMinorVersion="${parts[1]}" ;; + keepnativesymbols|-keepnativesymbols) + __CMakeArgs="$__CMakeArgs -DCLR_CMAKE_KEEP_NATIVE_SYMBOLS=true" + ;; + msbuildonunsupportedplatform|-msbuildonunsupportedplatform) __msbuildonunsupportedplatform=1 ;; diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 525c289d988..27396aa5bb5 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -336,8 +336,10 @@ function(strip_symbols targetName outputFilename) endfunction() function(install_with_stripped_symbols targetName kind destination) - strip_symbols(${targetName} symbol_file) - install_symbols(${symbol_file} ${destination}) + if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + strip_symbols(${targetName} symbol_file) + install_symbols(${symbol_file} ${destination}) + endif() if ("${kind}" STREQUAL "TARGETS") set(install_source ${targetName}) elseif("${kind}" STREQUAL "PROGRAMS") @@ -374,13 +376,17 @@ function(install_clr) 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) - strip_symbols(${targetName} symbol_file) + if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + strip_symbols(${targetName} symbol_file) + endif() foreach(destination ${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 (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + install_symbols(${symbol_file} ${destination}) + endif() if(CLR_CMAKE_PGO_INSTRUMENT) if(WIN32) |