diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2020-09-02 12:21:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 12:21:09 +0300 |
commit | e510e767e4861be955cefdc7187ddd875d1e6a9e (patch) | |
tree | 7c51325ce2789e2e537ddba5b4064fb699b5c3d8 | |
parent | a664bbc7b6b42a88bf3597834f620a41be8fcee5 (diff) |
Strip binaries more aggressively (#41039)
* Strip binaries more aggressively
We are currently stripping only debug symbols, but there are also other
symbols that can be stripped without affecting debuggability or anything
else. We were stripping the binaries in corefx that way in the past,
but some time ago we have unified the stripping between the former
three repos and started to strip just the debugging symbols.
This change strips all unneeded symbols, which results in significant
reduction of the binaries sizes. For example, libcoreclr.so went down
from 8732272 to 7027024 or libSystem.Security.Cryptography.Native.OpenSsl.so
went down from 163376 to 120952.
* Fix FreeBSD
* Fix FreeBSD and OSX
We use nm command to extract g_dacTable symbol value from libcoreclr
for the DAC purposes. On OSX, there are no dynamic symbols, on
FreeBSD, the stripping strips all regular symbols and leaves
dynamic ones only. So the nm needs to get a -D argument for
non OSX.
-rw-r--r-- | eng/native/functions.cmake | 2 | ||||
-rw-r--r-- | src/coreclr/src/debug/daccess/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/coreclr/src/pal/tools/gen-dactable-rva.sh | 8 |
3 files changed, 12 insertions, 3 deletions
diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 1bdcf1ddd38..420b7d1a88f 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -323,7 +323,7 @@ function(strip_symbols targetName outputFilename) POST_BUILD VERBATIM COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} - COMMAND ${CMAKE_OBJCOPY} --strip-debug ${strip_source_file} + COMMAND ${CMAKE_OBJCOPY} --strip-unneeded ${strip_source_file} COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file}" ) diff --git a/src/coreclr/src/debug/daccess/CMakeLists.txt b/src/coreclr/src/debug/daccess/CMakeLists.txt index b683d762885..9cef5f7f486 100644 --- a/src/coreclr/src/debug/daccess/CMakeLists.txt +++ b/src/coreclr/src/debug/daccess/CMakeLists.txt @@ -45,11 +45,14 @@ add_dependencies(daccess eventing_headers) if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) add_definitions(-DUSE_DAC_TABLE_RVA) + set(args $<$<NOT:$<BOOL:${CLR_CMAKE_HOST_OSX}>>:--dynamic> $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h) + add_custom_command( OUTPUT ${GENERATED_INCLUDE_DIR}/dactablerva.h DEPENDS coreclr VERBATIM - COMMAND sh ${CLR_DIR}/src/pal/tools/gen-dactable-rva.sh $<TARGET_FILE:coreclr> ${GENERATED_INCLUDE_DIR}/dactablerva.h + COMMAND_EXPAND_LISTS + COMMAND sh ${CLR_DIR}/src/pal/tools/gen-dactable-rva.sh ${args} COMMENT Generating ${GENERATED_INCLUDE_DIR}/dactablerva.h ) diff --git a/src/coreclr/src/pal/tools/gen-dactable-rva.sh b/src/coreclr/src/pal/tools/gen-dactable-rva.sh index c1fc13118de..62bb961015e 100644 --- a/src/coreclr/src/pal/tools/gen-dactable-rva.sh +++ b/src/coreclr/src/pal/tools/gen-dactable-rva.sh @@ -1 +1,7 @@ -${NM:-nm} -P -t x $1 | awk -F ' ' '/g_dacTable/ { print "#define DAC_TABLE_RVA 0x" substr("0000000000000000" $3, length($3) + 1); exit }' > $2 +if [ "$1" = "--dynamic" ]; then + __DynamicSymbolsOption="-D" + shift +else + __DynamicSymbolsOption="" +fi +${NM:-nm} $__DynamicSymbolsOption -P -t x $1 | awk -F ' ' '/g_dacTable/ { print "#define DAC_TABLE_RVA 0x" substr("0000000000000000" $3, length($3) + 1); exit }' > $2 |