diff options
author | Yi Kong <yikong@google.com> | 2019-05-03 01:17:03 -0700 |
---|---|---|
committer | Yi Kong <yikong@google.com> | 2019-05-03 08:24:10 +0000 |
commit | bd475367c3dcb4478a70409c99b959ebdb117be3 (patch) | |
tree | 41eadbf2c0a53d755091399f192bb2461e4982d8 /scripts | |
parent | ead8b42a1de7b5d36ab7c66b95d5b568a39a5831 (diff) | |
download | build_soong-bd475367c3dcb4478a70409c99b959ebdb117be3.tar.gz build_soong-bd475367c3dcb4478a70409c99b959ebdb117be3.tar.bz2 build_soong-bd475367c3dcb4478a70409c99b959ebdb117be3.zip |
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)
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/strip.sh | 54 |
1 files changed, 39 insertions, 15 deletions
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 <<EOF -Usage: strip.sh [options] -i in-file -o out-file -d deps-file +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 @@ -71,6 +72,20 @@ do_strip_keep_symbols() { fi } +do_strip_keep_symbol_list() { + if [ -z "${use_gnu_strip}" ]; then + echo "do_strip_keep_symbol_list does not work with llvm-objcopy" + echo "http://b/131631155" + usage + fi + + echo "${symbols_to_keep}" | tr ',' '\n' > "${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 |