Merge "Add an option to preserve symbols and debug_frame."

am: 8a7469a0d7

Change-Id: I8ac98401acf082ef1a2740a5dd29e9573faf3ed7
This commit is contained in:
Christopher Ferris 2019-05-21 13:19:43 -07:00 committed by android-build-merger
commit 0361ccc398
3 changed files with 46 additions and 15 deletions

View file

@ -267,11 +267,12 @@ type builderFlags struct {
groupStaticLibs bool
stripKeepSymbols bool
stripKeepSymbolsList string
stripKeepMiniDebugInfo bool
stripAddGnuDebuglink bool
stripUseGnuStrip bool
stripKeepSymbols bool
stripKeepSymbolsList string
stripKeepSymbolsAndDebugFrame bool
stripKeepMiniDebugInfo bool
stripAddGnuDebuglink bool
stripUseGnuStrip bool
proto android.ProtoFlags
protoC bool
@ -852,6 +853,9 @@ func TransformStrip(ctx android.ModuleContext, inputFile android.Path,
if flags.stripKeepSymbolsList != "" {
args += " -k" + flags.stripKeepSymbolsList
}
if flags.stripKeepSymbolsAndDebugFrame {
args += " --keep-symbols-and-debug-frame"
}
if flags.stripUseGnuStrip {
args += " --use-gnu-strip"
}

View file

@ -22,11 +22,12 @@ import (
type StripProperties struct {
Strip struct {
None *bool `android:"arch_variant"`
All *bool `android:"arch_variant"`
Keep_symbols *bool `android:"arch_variant"`
Keep_symbols_list []string `android:"arch_variant"`
Use_gnu_strip *bool `android:"arch_variant"`
None *bool `android:"arch_variant"`
All *bool `android:"arch_variant"`
Keep_symbols *bool `android:"arch_variant"`
Keep_symbols_list []string `android:"arch_variant"`
Keep_symbols_and_debug_frame *bool `android:"arch_variant"`
Use_gnu_strip *bool `android:"arch_variant"`
} `android:"arch_variant"`
}
@ -46,6 +47,8 @@ func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android.
} else {
if Bool(stripper.StripProperties.Strip.Keep_symbols) {
flags.stripKeepSymbols = true
} else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
flags.stripKeepSymbolsAndDebugFrame = true
} else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
flags.stripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
} else if !Bool(stripper.StripProperties.Strip.All) {

View file

@ -28,6 +28,7 @@
# --add-gnu-debuglink
# --keep-mini-debug-info
# --keep-symbols
# --keep-symbols-and-debug-frame
# --use-gnu-strip
# --remove-build-id
@ -39,11 +40,12 @@ usage() {
cat <<EOF
Usage: strip.sh [options] -k symbols -i in-file -o out-file -d deps-file
Options:
--add-gnu-debuglink Add a gnu-debuglink section to out-file
--keep-mini-debug-info Keep compressed debug info in out-file
--keep-symbols Keep symbols in out-file
--use-gnu-strip Use strip/objcopy instead of llvm-{strip,objcopy}
--remove-build-id Remove the gnu build-id section in out-file
--add-gnu-debuglink Add a gnu-debuglink section to out-file
--keep-mini-debug-info Keep compressed debug info in out-file
--keep-symbols Keep symbols in out-file
--keep-symbols-and-debug-frame Keep symbols and .debug_frame in out-file
--use-gnu-strip Use strip/objcopy instead of llvm-{strip,objcopy}
--remove-build-id Remove the gnu build-id section in out-file
EOF
exit 1
}
@ -63,6 +65,15 @@ do_strip() {
fi
}
do_strip_keep_symbols_and_debug_frame() {
REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {if ($2 != ".debug_frame") {print "--remove-section " $2}}' | xargs`
if [ -z "${use_gnu_strip}" ]; then
"${CLANG_BIN}/llvm-objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
else
"${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
fi
}
do_strip_keep_symbols() {
REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "--remove-section " $2}' | xargs`
if [ -z "${use_gnu_strip}" ]; then
@ -148,6 +159,7 @@ while getopts $OPTSTRING opt; do
add-gnu-debuglink) add_gnu_debuglink=true ;;
keep-mini-debug-info) keep_mini_debug_info=true ;;
keep-symbols) keep_symbols=true ;;
keep-symbols-and-debug-frame) keep_symbols_and_debug_frame=true ;;
remove-build-id) remove_build_id=true ;;
use-gnu-strip) use_gnu_strip=true ;;
*) echo "Unknown option --${OPTARG}"; usage ;;
@ -177,6 +189,16 @@ if [ ! -z "${keep_symbols}" -a ! -z "${keep_mini_debug_info}" ]; then
usage
fi
if [ ! -z "${keep_symbols}" -a ! -z "${keep_symbols_and_debug_frame}" ]; then
echo "--keep-symbols and --keep-symbols-and-debug-frame cannot be used together"
usage
fi
if [ ! -z "${keep_mini_debug_info}" -a ! -z "${keep_symbols_and_debug_frame}" ]; then
echo "--keep-symbols-mini-debug-info and --keep-symbols-and-debug-frame cannot be used together"
usage
fi
if [ ! -z "${symbols_to_keep}" -a ! -z "${keep_symbols}" ]; then
echo "--keep-symbols and -k cannot be used together"
usage
@ -195,6 +217,8 @@ elif [ ! -z "${symbols_to_keep}" ]; then
do_strip_keep_symbol_list
elif [ ! -z "${keep_mini_debug_info}" ]; then
do_strip_keep_mini_debug_info
elif [ ! -z "${keep_symbols_and_debug_frame}" ]; then
do_strip_keep_symbols_and_debug_frame
else
do_strip
fi