From bd475367c3dcb4478a70409c99b959ebdb117be3 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Fri, 3 May 2019 01:17:03 -0700 Subject: Strip libgcc to only keep fallback symbols We use libgcc as fallback for symbols not present in libclang_rt builtins, however we didn't know what exact symbols were being used, some may not be intended to fallback. Create libgcc_stripped, which only contains unwind symbols from libgcc. Bug: 29275768 Test: bionic-unit-tests Change-Id: I98df02ead7f6cca4e76ec92d4f880de4e03f5b5c Merged-In: I5b349fa6138e51663bf3b67109b880b4356da8e8 (cherry picked from commit acee27cd7236554d0112001c96b9b5790c1c7097) --- scripts/strip.sh | 54 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/strip.sh b/scripts/strip.sh index d5369071..0f77da8a 100755 --- a/scripts/strip.sh +++ b/scripts/strip.sh @@ -24,6 +24,7 @@ # -i ${file}: input file (required) # -o ${file}: output file (required) # -d ${file}: deps file (required) +# -k symbols: Symbols to keep (optional) # --add-gnu-debuglink # --keep-mini-debug-info # --keep-symbols @@ -32,11 +33,11 @@ set -o pipefail -OPTSTRING=d:i:o:-: +OPTSTRING=d:i:o:k:-: usage() { cat < "${outfile}.symbolList" + KEEP_SYMBOLS="-w --strip-unneeded-symbol=* --keep-symbols=" + KEEP_SYMBOLS+="${outfile}.symbolList" + + "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS} +} + do_strip_keep_mini_debug_info() { rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz" local fail= @@ -124,19 +139,21 @@ do_remove_build_id() { while getopts $OPTSTRING opt; do case "$opt" in - d) depsfile="${OPTARG}" ;; - i) infile="${OPTARG}" ;; - o) outfile="${OPTARG}" ;; - -) - case "${OPTARG}" in - add-gnu-debuglink) add_gnu_debuglink=true ;; - keep-mini-debug-info) keep_mini_debug_info=true ;; - keep-symbols) keep_symbols=true ;; - remove-build-id) remove_build_id=true ;; - *) echo "Unknown option --${OPTARG}"; usage ;; - esac;; - ?) usage ;; - *) echo "'${opt}' '${OPTARG}'" + d) depsfile="${OPTARG}" ;; + i) infile="${OPTARG}" ;; + o) outfile="${OPTARG}" ;; + k) symbols_to_keep="${OPTARG}" ;; + -) + case "${OPTARG}" in + add-gnu-debuglink) add_gnu_debuglink=true ;; + keep-mini-debug-info) keep_mini_debug_info=true ;; + keep-symbols) keep_symbols=true ;; + remove-build-id) remove_build_id=true ;; + use-gnu-strip) use_gnu_strip=true ;; + *) echo "Unknown option --${OPTARG}"; usage ;; + esac;; + ?) usage ;; + *) echo "'${opt}' '${OPTARG}'" esac done @@ -160,6 +177,11 @@ if [ ! -z "${keep_symbols}" -a ! -z "${keep_mini_debug_info}" ]; then usage fi +if [ ! -z "${symbols_to_keep}" -a ! -z "${keep_symbols}" ]; then + echo "--keep-symbols and -k cannot be used together" + usage +fi + if [ ! -z "${add_gnu_debuglink}" -a ! -z "${keep_mini_debug_info}" ]; then echo "--add-gnu-debuglink cannot be used with --keep-mini-debug-info" usage @@ -169,6 +191,8 @@ rm -f "${outfile}.tmp" if [ ! -z "${keep_symbols}" ]; then do_strip_keep_symbols +elif [ ! -z "${symbols_to_keep}" ]; then + do_strip_keep_symbol_list elif [ ! -z "${keep_mini_debug_info}" ]; then do_strip_keep_mini_debug_info else -- cgit v1.2.3