diff --git a/patches/runtime/0019-Add-an-option-to-keep-native-debug-symbols.patch b/patches/runtime/0019-Add-an-option-to-keep-native-debug-symbols.patch new file mode 100644 index 0000000000..7f35877c3f --- /dev/null +++ b/patches/runtime/0019-Add-an-option-to-keep-native-debug-symbols.patch @@ -0,0 +1,203 @@ +From 2fcdb9db2f9fb707e9d79521a68a41470f47cbb7 Mon Sep 17 00:00:00 2001 +From: Omair Majid +Date: Fri, 25 Sep 2020 16:53:59 -0400 +Subject: [PATCH] Add an option to keep native debug symbols + +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 +--- + Directory.Build.props | 2 ++ + eng/build.sh | 13 +++++++++++++ + eng/native/build-commons.sh | 5 +++++ + eng/native/functions.cmake | 14 ++++++++++---- + src/coreclr/runtime.proj | 1 + + src/installer/corehost/build.proj | 1 + + src/libraries/Native/build-native.proj | 3 ++- + 7 files changed, 34 insertions(+), 5 deletions(-) + +diff --git a/Directory.Build.props b/Directory.Build.props +index e6dc7b84da1..b95ce4d3143 100644 +--- a/Directory.Build.props ++++ b/Directory.Build.props +@@ -97,6 +97,8 @@ + + + true ++ ++ false + + Properties + +diff --git a/eng/build.sh b/eng/build.sh +index eb0cb586ebf..f9403d2ef54 100755 +--- a/eng/build.sh ++++ b/eng/build.sh +@@ -74,6 +74,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." +@@ -377,6 +378,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 e5bec2b3b8c..15549012eda 100755 +--- a/eng/native/build-commons.sh ++++ b/eng/native/build-commons.sh +@@ -208,6 +208,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:" +@@ -323,6 +324,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 1509a17fa59..1b644e7cc52 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") +@@ -375,13 +377,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 $ 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) +diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj +index f0da8c09cd0..3e6a3df2397 100644 +--- a/src/coreclr/runtime.proj ++++ b/src/coreclr/runtime.proj +@@ -11,6 +11,7 @@ + <_CoreClrBuildArg Condition="'$(ContinuousIntegrationBuild)' == 'true'" Include="-ci" /> + <_CoreClrBuildArg Condition="'$(CrossBuild)' == 'true'" Include="-cross" /> + <_CoreClrBuildArg Condition="'$(PortableBuild)' != 'true'" Include="-portablebuild=false" /> ++ <_CoreClrBuildArg Condition="'$(KeepNativeSymbols)' != 'false'" Include="-keepnativesymbols" /> + <_CoreClrBuildArg Condition="!$([MSBuild]::IsOsPlatform(Windows))" Include="-os $(TargetOS)" /> + + <_CoreClrBuildArg Condition="$([MSBuild]::IsOsPlatform(Windows)) and +diff --git a/src/installer/corehost/build.proj b/src/installer/corehost/build.proj +index 69927e8304b..38c104ca005 100644 +--- a/src/installer/corehost/build.proj ++++ b/src/installer/corehost/build.proj +@@ -30,6 +30,7 @@ + $(Configuration) $(TargetArchitecture) -apphostver "$(AppHostVersion)" -hostver "$(HostVersion)" -fxrver "$(HostResolverVersion)" -policyver "$(HostPolicyVersion)" -commithash "$(LatestCommit)" -os $(TargetOS) + $(BuildArgs) -cmakeargs "-DVERSION_FILE_PATH=$(NativeVersionFile)" + $(BuildArgs) -portablebuild=false ++ $(BuildArgs) -keepnativesymbols + $(BuildArgs) -cross + $(BuildArgs) $(Compiler) + $(BuildArgs) $(CMakeArgs) +diff --git a/src/libraries/Native/build-native.proj b/src/libraries/Native/build-native.proj +index b0551571adf..af67b63ab41 100644 +--- a/src/libraries/Native/build-native.proj ++++ b/src/libraries/Native/build-native.proj +@@ -22,6 +22,7 @@ + <_ProcessorCountArg> -numproc $(MSBuildNodeCount) + <_PortableBuildArg Condition="'$(PortableBuild)' != 'true'"> -portablebuild=false + <_CrossBuildArg Condition="'$(CrossBuild)' == 'true'"> -cross ++ <_KeepNativeSymbolsBuildArg Condition="'$(KeepNativeSymbols)' != 'false'"> -keepnativesymbols + <_CMakeArgs Condition="'$(CMakeArgs)' != ''"> $(CMakeArgs) + + + <_BuildNativeCompilerArg Condition="'$(BuildNativeCompiler)' != ''"> $(BuildNativeCompiler) +- <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_CMakeArgs) $(Compiler) ++ <_BuildNativeUnixArgs>$(_BuildNativeArgs)$(_ProcessCountArg)$(_PortableBuildArg)$(_CrossBuildArg)$(_BuildNativeCompilerArg)$(_KeepNativeSymbolsBuildArg)$(_CMakeArgs) $(Compiler) + + + +-- +2.26.2 + diff --git a/repos/runtime.common.props b/repos/runtime.common.props index 1ca6c181b8..00432c52bd 100644 --- a/repos/runtime.common.props +++ b/repos/runtime.common.props @@ -35,6 +35,7 @@ $(CoreClrBuildArguments) /p:PackageRid=$(OverrideTargetRid) $(CoreClrBuildArguments) /p:NoPgoOptimize=true + $(CoreClrBuildArguments) /p:KeepNativeSymbols=true $(CoreClrBuildArguments) /p:RuntimeOS=$(OverrideTargetRid.Substring(0, $(OverrideTargetRid.IndexOf("-")))) $(CoreClrBuildArguments) /p:RuntimeOS=$(OverrideTargetRid) @@ -52,6 +53,7 @@ $(LibrariesBuildArguments) /p:RuntimeOS=$(OverrideTargetRid) $(LibrariesBuildArguments) /p:PortableBuild=$(OverridePortableBuild) $(LibrariesBuildArguments) /p:BuildAllPackages=true + $(LibrariesBuildArguments) /p:KeepNativeSymbols=true $(LibrariesBuildArguments) /p:BuiltSdkPackageOverride="" $(LibrariesBuildArguments) /p:DotNetSourceBuildIntermediatePath=$(GeneratedSourcePathOnline) $(LibrariesBuildArguments) /p:DotNetSourceBuildIntermediatePath=$(GeneratedSourcePathOffline) @@ -63,6 +65,7 @@ $(FlagParameterPrefix)restore $(FlagParameterPrefix)build $(InstallerBuildArguments) /p:PortableBuild=$(OverridePortableBuild) + $(InstallerBuildArguments) /p:KeepNativeSymbols=true $(InstallerBuildArguments) /p:TargetArchitecture=$(Platform) /p:DisableCrossgen=true /p:CrossBuild=true $(InstallerBuildArguments) /p:BuildDebPackage=false $(InstallerBuildArguments) /p:BuildAllPackages=true