aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris2019-05-17 18:39:54 -0500
committerChristopher Ferris2019-05-17 19:52:18 -0500
commitb43fe7a838ed44f61c6096023f9b66cccef69a17 (patch)
treebb7a6c7403f4dc958c9044d697db380c447d379b
parent4c83b8950af48bd503c89988f4de7c6c41023c71 (diff)
downloadplatform-build-soong-b43fe7a838ed44f61c6096023f9b66cccef69a17.tar.gz
platform-build-soong-b43fe7a838ed44f61c6096023f9b66cccef69a17.tar.xz
platform-build-soong-b43fe7a838ed44f61c6096023f9b66cccef69a17.zip
Add an option to preserve symbols and debug_frame.
New strip option named keep_symbols_and_debug_frame, that will keep the symbols and the .debug_frame. This is meant for use by libc.so only on arm32. Other libraries might want to use it to keep better unwinding information on device. Bug: 132992102 Test: Built libc.so with this option and verified that it contains Test: the .debug_frame section. Change-Id: I823a28199dec8316e8b26fe31ff9f17e6b11d406
-rw-r--r--cc/builder.go14
-rw-r--r--cc/strip.go13
-rwxr-xr-xscripts/strip.sh34
3 files changed, 46 insertions, 15 deletions
diff --git a/cc/builder.go b/cc/builder.go
index c99e4618..0a286725 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -254,11 +254,12 @@ type builderFlags struct {
254 254
255 groupStaticLibs bool 255 groupStaticLibs bool
256 256
257 stripKeepSymbols bool 257 stripKeepSymbols bool
258 stripKeepSymbolsList string 258 stripKeepSymbolsList string
259 stripKeepMiniDebugInfo bool 259 stripKeepSymbolsAndDebugFrame bool
260 stripAddGnuDebuglink bool 260 stripKeepMiniDebugInfo bool
261 stripUseGnuStrip bool 261 stripAddGnuDebuglink bool
262 stripUseGnuStrip bool
262 263
263 proto android.ProtoFlags 264 proto android.ProtoFlags
264 protoC bool 265 protoC bool
@@ -839,6 +840,9 @@ func TransformStrip(ctx android.ModuleContext, inputFile android.Path,
839 if flags.stripKeepSymbolsList != "" { 840 if flags.stripKeepSymbolsList != "" {
840 args += " -k" + flags.stripKeepSymbolsList 841 args += " -k" + flags.stripKeepSymbolsList
841 } 842 }
843 if flags.stripKeepSymbolsAndDebugFrame {
844 args += " --keep-symbols-and-debug-frame"
845 }
842 if flags.stripUseGnuStrip { 846 if flags.stripUseGnuStrip {
843 args += " --use-gnu-strip" 847 args += " --use-gnu-strip"
844 } 848 }
diff --git a/cc/strip.go b/cc/strip.go
index 7122585e..4daa7593 100644
--- a/cc/strip.go
+++ b/cc/strip.go
@@ -22,11 +22,12 @@ import (
22 22
23type StripProperties struct { 23type StripProperties struct {
24 Strip struct { 24 Strip struct {
25 None *bool `android:"arch_variant"` 25 None *bool `android:"arch_variant"`
26 All *bool `android:"arch_variant"` 26 All *bool `android:"arch_variant"`
27 Keep_symbols *bool `android:"arch_variant"` 27 Keep_symbols *bool `android:"arch_variant"`
28 Keep_symbols_list []string `android:"arch_variant"` 28 Keep_symbols_list []string `android:"arch_variant"`
29 Use_gnu_strip *bool `android:"arch_variant"` 29 Keep_symbols_and_debug_frame *bool `android:"arch_variant"`
30 Use_gnu_strip *bool `android:"arch_variant"`
30 } `android:"arch_variant"` 31 } `android:"arch_variant"`
31} 32}
32 33
@@ -46,6 +47,8 @@ func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android.
46 } else { 47 } else {
47 if Bool(stripper.StripProperties.Strip.Keep_symbols) { 48 if Bool(stripper.StripProperties.Strip.Keep_symbols) {
48 flags.stripKeepSymbols = true 49 flags.stripKeepSymbols = true
50 } else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
51 flags.stripKeepSymbolsAndDebugFrame = true
49 } else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 { 52 } else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
50 flags.stripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",") 53 flags.stripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
51 } else if !Bool(stripper.StripProperties.Strip.All) { 54 } else if !Bool(stripper.StripProperties.Strip.All) {
diff --git a/scripts/strip.sh b/scripts/strip.sh
index 0f77da8a..bd62619b 100755
--- a/scripts/strip.sh
+++ b/scripts/strip.sh
@@ -28,6 +28,7 @@
28# --add-gnu-debuglink 28# --add-gnu-debuglink
29# --keep-mini-debug-info 29# --keep-mini-debug-info
30# --keep-symbols 30# --keep-symbols
31# --keep-symbols-and-debug-frame
31# --use-gnu-strip 32# --use-gnu-strip
32# --remove-build-id 33# --remove-build-id
33 34
@@ -39,11 +40,12 @@ usage() {
39 cat <<EOF 40 cat <<EOF
40Usage: strip.sh [options] -k symbols -i in-file -o out-file -d deps-file 41Usage: strip.sh [options] -k symbols -i in-file -o out-file -d deps-file
41Options: 42Options:
42 --add-gnu-debuglink Add a gnu-debuglink section to out-file 43 --add-gnu-debuglink Add a gnu-debuglink section to out-file
43 --keep-mini-debug-info Keep compressed debug info in out-file 44 --keep-mini-debug-info Keep compressed debug info in out-file
44 --keep-symbols Keep symbols in out-file 45 --keep-symbols Keep symbols in out-file
45 --use-gnu-strip Use strip/objcopy instead of llvm-{strip,objcopy} 46 --keep-symbols-and-debug-frame Keep symbols and .debug_frame in out-file
46 --remove-build-id Remove the gnu build-id section in out-file 47 --use-gnu-strip Use strip/objcopy instead of llvm-{strip,objcopy}
48 --remove-build-id Remove the gnu build-id section in out-file
47EOF 49EOF
48 exit 1 50 exit 1
49} 51}
@@ -63,6 +65,15 @@ do_strip() {
63 fi 65 fi
64} 66}
65 67
68do_strip_keep_symbols_and_debug_frame() {
69 REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {if ($2 != ".debug_frame") {print "--remove-section " $2}}' | xargs`
70 if [ -z "${use_gnu_strip}" ]; then
71 "${CLANG_BIN}/llvm-objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
72 else
73 "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
74 fi
75}
76
66do_strip_keep_symbols() { 77do_strip_keep_symbols() {
67 REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "--remove-section " $2}' | xargs` 78 REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "--remove-section " $2}' | xargs`
68 if [ -z "${use_gnu_strip}" ]; then 79 if [ -z "${use_gnu_strip}" ]; then
@@ -148,6 +159,7 @@ while getopts $OPTSTRING opt; do
148 add-gnu-debuglink) add_gnu_debuglink=true ;; 159 add-gnu-debuglink) add_gnu_debuglink=true ;;
149 keep-mini-debug-info) keep_mini_debug_info=true ;; 160 keep-mini-debug-info) keep_mini_debug_info=true ;;
150 keep-symbols) keep_symbols=true ;; 161 keep-symbols) keep_symbols=true ;;
162 keep-symbols-and-debug-frame) keep_symbols_and_debug_frame=true ;;
151 remove-build-id) remove_build_id=true ;; 163 remove-build-id) remove_build_id=true ;;
152 use-gnu-strip) use_gnu_strip=true ;; 164 use-gnu-strip) use_gnu_strip=true ;;
153 *) echo "Unknown option --${OPTARG}"; usage ;; 165 *) echo "Unknown option --${OPTARG}"; usage ;;
@@ -177,6 +189,16 @@ if [ ! -z "${keep_symbols}" -a ! -z "${keep_mini_debug_info}" ]; then
177 usage 189 usage
178fi 190fi
179 191
192if [ ! -z "${keep_symbols}" -a ! -z "${keep_symbols_and_debug_frame}" ]; then
193 echo "--keep-symbols and --keep-symbols-and-debug-frame cannot be used together"
194 usage
195fi
196
197if [ ! -z "${keep_mini_debug_info}" -a ! -z "${keep_symbols_and_debug_frame}" ]; then
198 echo "--keep-symbols-mini-debug-info and --keep-symbols-and-debug-frame cannot be used together"
199 usage
200fi
201
180if [ ! -z "${symbols_to_keep}" -a ! -z "${keep_symbols}" ]; then 202if [ ! -z "${symbols_to_keep}" -a ! -z "${keep_symbols}" ]; then
181 echo "--keep-symbols and -k cannot be used together" 203 echo "--keep-symbols and -k cannot be used together"
182 usage 204 usage
@@ -195,6 +217,8 @@ elif [ ! -z "${symbols_to_keep}" ]; then
195 do_strip_keep_symbol_list 217 do_strip_keep_symbol_list
196elif [ ! -z "${keep_mini_debug_info}" ]; then 218elif [ ! -z "${keep_mini_debug_info}" ]; then
197 do_strip_keep_mini_debug_info 219 do_strip_keep_mini_debug_info
220elif [ ! -z "${keep_symbols_and_debug_frame}" ]; then
221 do_strip_keep_symbols_and_debug_frame
198else 222else
199 do_strip 223 do_strip
200fi 224fi