diff options
author | Yi Kong | 2019-03-29 22:05:14 -0500 |
---|---|---|
committer | Yi Kong | 2019-04-30 12:07:00 -0500 |
commit | acee27cd7236554d0112001c96b9b5790c1c7097 (patch) | |
tree | 7df25e8cbdfcb3b55ebe34c7ca5491d1ac38c5ae /scripts | |
parent | feef2ef4d7cc146885c482899f9a967554dc083d (diff) | |
download | platform-build-soong-acee27cd7236554d0112001c96b9b5790c1c7097.tar.gz platform-build-soong-acee27cd7236554d0112001c96b9b5790c1c7097.tar.xz platform-build-soong-acee27cd7236554d0112001c96b9b5790c1c7097.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: I5b349fa6138e51663bf3b67109b880b4356da8e8
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 @@ | |||
24 | # -i ${file}: input file (required) | 24 | # -i ${file}: input file (required) |
25 | # -o ${file}: output file (required) | 25 | # -o ${file}: output file (required) |
26 | # -d ${file}: deps file (required) | 26 | # -d ${file}: deps file (required) |
27 | # -k symbols: Symbols to keep (optional) | ||
27 | # --add-gnu-debuglink | 28 | # --add-gnu-debuglink |
28 | # --keep-mini-debug-info | 29 | # --keep-mini-debug-info |
29 | # --keep-symbols | 30 | # --keep-symbols |
@@ -32,11 +33,11 @@ | |||
32 | 33 | ||
33 | set -o pipefail | 34 | set -o pipefail |
34 | 35 | ||
35 | OPTSTRING=d:i:o:-: | 36 | OPTSTRING=d:i:o:k:-: |
36 | 37 | ||
37 | usage() { | 38 | usage() { |
38 | cat <<EOF | 39 | cat <<EOF |
39 | Usage: strip.sh [options] -i in-file -o out-file -d deps-file | 40 | Usage: strip.sh [options] -k symbols -i in-file -o out-file -d deps-file |
40 | Options: | 41 | Options: |
41 | --add-gnu-debuglink Add a gnu-debuglink section to out-file | 42 | --add-gnu-debuglink Add a gnu-debuglink section to out-file |
42 | --keep-mini-debug-info Keep compressed debug info in out-file | 43 | --keep-mini-debug-info Keep compressed debug info in out-file |
@@ -71,6 +72,20 @@ do_strip_keep_symbols() { | |||
71 | fi | 72 | fi |
72 | } | 73 | } |
73 | 74 | ||
75 | do_strip_keep_symbol_list() { | ||
76 | if [ -z "${use_gnu_strip}" ]; then | ||
77 | echo "do_strip_keep_symbol_list does not work with llvm-objcopy" | ||
78 | echo "http://b/131631155" | ||
79 | usage | ||
80 | fi | ||
81 | |||
82 | echo "${symbols_to_keep}" | tr ',' '\n' > "${outfile}.symbolList" | ||
83 | KEEP_SYMBOLS="-w --strip-unneeded-symbol=* --keep-symbols=" | ||
84 | KEEP_SYMBOLS+="${outfile}.symbolList" | ||
85 | |||
86 | "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS} | ||
87 | } | ||
88 | |||
74 | do_strip_keep_mini_debug_info() { | 89 | do_strip_keep_mini_debug_info() { |
75 | rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz" | 90 | rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz" |
76 | local fail= | 91 | local fail= |
@@ -124,19 +139,21 @@ do_remove_build_id() { | |||
124 | 139 | ||
125 | while getopts $OPTSTRING opt; do | 140 | while getopts $OPTSTRING opt; do |
126 | case "$opt" in | 141 | case "$opt" in |
127 | d) depsfile="${OPTARG}" ;; | 142 | d) depsfile="${OPTARG}" ;; |
128 | i) infile="${OPTARG}" ;; | 143 | i) infile="${OPTARG}" ;; |
129 | o) outfile="${OPTARG}" ;; | 144 | o) outfile="${OPTARG}" ;; |
130 | -) | 145 | k) symbols_to_keep="${OPTARG}" ;; |
131 | case "${OPTARG}" in | 146 | -) |
132 | add-gnu-debuglink) add_gnu_debuglink=true ;; | 147 | case "${OPTARG}" in |
133 | keep-mini-debug-info) keep_mini_debug_info=true ;; | 148 | add-gnu-debuglink) add_gnu_debuglink=true ;; |
134 | keep-symbols) keep_symbols=true ;; | 149 | keep-mini-debug-info) keep_mini_debug_info=true ;; |
135 | remove-build-id) remove_build_id=true ;; | 150 | keep-symbols) keep_symbols=true ;; |
136 | *) echo "Unknown option --${OPTARG}"; usage ;; | 151 | remove-build-id) remove_build_id=true ;; |
137 | esac;; | 152 | use-gnu-strip) use_gnu_strip=true ;; |
138 | ?) usage ;; | 153 | *) echo "Unknown option --${OPTARG}"; usage ;; |
139 | *) echo "'${opt}' '${OPTARG}'" | 154 | esac;; |
155 | ?) usage ;; | ||
156 | *) echo "'${opt}' '${OPTARG}'" | ||
140 | esac | 157 | esac |
141 | done | 158 | done |
142 | 159 | ||
@@ -160,6 +177,11 @@ if [ ! -z "${keep_symbols}" -a ! -z "${keep_mini_debug_info}" ]; then | |||
160 | usage | 177 | usage |
161 | fi | 178 | fi |
162 | 179 | ||
180 | if [ ! -z "${symbols_to_keep}" -a ! -z "${keep_symbols}" ]; then | ||
181 | echo "--keep-symbols and -k cannot be used together" | ||
182 | usage | ||
183 | fi | ||
184 | |||
163 | if [ ! -z "${add_gnu_debuglink}" -a ! -z "${keep_mini_debug_info}" ]; then | 185 | if [ ! -z "${add_gnu_debuglink}" -a ! -z "${keep_mini_debug_info}" ]; then |
164 | echo "--add-gnu-debuglink cannot be used with --keep-mini-debug-info" | 186 | echo "--add-gnu-debuglink cannot be used with --keep-mini-debug-info" |
165 | usage | 187 | usage |
@@ -169,6 +191,8 @@ rm -f "${outfile}.tmp" | |||
169 | 191 | ||
170 | if [ ! -z "${keep_symbols}" ]; then | 192 | if [ ! -z "${keep_symbols}" ]; then |
171 | do_strip_keep_symbols | 193 | do_strip_keep_symbols |
194 | elif [ ! -z "${symbols_to_keep}" ]; then | ||
195 | do_strip_keep_symbol_list | ||
172 | elif [ ! -z "${keep_mini_debug_info}" ]; then | 196 | elif [ ! -z "${keep_mini_debug_info}" ]; then |
173 | do_strip_keep_mini_debug_info | 197 | do_strip_keep_mini_debug_info |
174 | else | 198 | else |