Files
bpfire/src/stripper
Michael Tremer 25d5058974 stripper: Strip all unneeded relocation information
Libraries were treated differently and therfore it could
happen that they were not stripped from any unnecessary
relocation information at all.

This patch changes that and strips everything from
libraries that we do not need.

The ISO was 3MB smaller.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
2019-12-29 19:20:44 +00:00

60 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
dirs=""
excludes="/dev /proc /sys /run"
while [ $# -gt 0 ]; do
case "${1}" in
--exclude=*)
excludes="${excludes} ${1#*=}"
;;
*)
dirs="${dirs} ${1}"
;;
esac
shift
done
function _strip() {
local file=${1}
local strip="${STRIP-strip}"
local exclude l
for exclude in ${excludes}; do
l=${#exclude}
if [ "${file:0:${l}}" = "${exclude}" ]; then
return 0
fi
done
local cmd=( "${strip}" )
case "$(file -bi ${file})" in
application/x-archive*)
cmd+=( "--strip-debug" "--remove-section=.comment" "--remove-section=.note" )
;;
*)
cmd+=( "--strip-all" )
;;
esac
echo "Stripping ${file}..."
${cmd[*]} ${file}
}
for dir in ${dirs}; do
# Strip shared objects.
find ${dir} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
| file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' |
while read file; do
_strip ${file} || exit $?
done || exit $?
# Strip static archives.
find ${dir} -name \*.a -a -exec file {} \; \
| grep 'current ar archive' | sed -n -e 's/^\(.*\):[ ]*current ar archive/\1/p' |
while read file; do
_strip ${file} || exit $?
done || exit $?
done