-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathstrip-symbols.sh
executable file
·54 lines (40 loc) · 1.27 KB
/
strip-symbols.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
# Move symbols from the binary to a separate file
# Based on https://stackoverflow.com/a/866731
scriptdir=`dirname ${0}`
scriptdir=`(cd ${scriptdir}; pwd)`
scriptname=`basename ${0}`
objcopy=$2
if [ -z "$objcopy" ]; then
objcopy="objcopy"
fi
set -e
tostripdir=`dirname "$1"`
tostripfile=`basename "$1"`
if [ -z ${tostripfile} ] ; then
echo "USAGE ${scriptname} <tostrip> [<objcopy cmd>]"
exit 1
fi
cd "${tostripdir}"
debugdir=.debug
debugfile="${tostripfile}.debug"
debugpath="${debugdir}/${debugfile}"
debugpathtmp="${debugpath}.tmp"
if [ ! -d "${debugdir}" ] ; then
echo "creating dir ${tostripdir}/${debugdir}"
mkdir -p "${debugdir}"
fi
echo "stripping ${tostripfile}, putting debug info into ${debugfile}"
"${objcopy}" --only-keep-debug "${tostripfile}" "${debugpathtmp}"
# Check the size of the output file to avoid packing invalid debug information
FILESIZE=$(stat -c%s "${debugpathtmp}")
if [ "$FILESIZE" -le 200000 ] ;then
echo "No debug information was found from the executable, not overwriting existing symbols"
rm "${debugpathtmp}"
exit 0
else
mv "${debugpathtmp}" "${debugpath}"
fi
"${objcopy}" --strip-debug --strip-unneeded "${tostripfile}"
"${objcopy}" --add-gnu-debuglink="${debugpath}" "${tostripfile}"
chmod -x "${debugdir}/${debugfile}"