mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
make.sh: Refactor stripper
This should *actually* exclude everything we want to exclude and *actually* strip everything to the maximum. Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Peter Müller
parent
f35f213850
commit
19054331c5
21
lfs/strip
21
lfs/strip
@@ -29,16 +29,6 @@ VER = ipfire
|
||||
THISAPP = strip
|
||||
TARGET = $(DIR_INFO)/$(THISAPP)
|
||||
|
||||
ifeq "$(TOOLCHAIN)" "1"
|
||||
SHELL = /bin/bash
|
||||
STRIP = /usr/bin/strip
|
||||
ROOT = $(TOOLS_DIR)
|
||||
else
|
||||
SHELL = $(TOOLS_DIR)/bin/bash
|
||||
STRIP = $(TOOLS_DIR)/bin/strip
|
||||
ROOT = /
|
||||
endif
|
||||
|
||||
###############################################################################
|
||||
# Top-level Rules
|
||||
###############################################################################
|
||||
@@ -56,18 +46,19 @@ md5 :
|
||||
###############################################################################
|
||||
|
||||
$(TARGET) :
|
||||
ifeq "$(TOOLCHAIN)" "1"
|
||||
# Strip everything in the toolchain
|
||||
$(DIR_SRC)/src/stripper $(TOOLS_DIR)
|
||||
else
|
||||
# Don't strip VDR binaries, because they use a weird plugin system
|
||||
# which does not work when unneeded symbols get stripped from
|
||||
# /usr/sbin/vdr.
|
||||
STRIP=$(STRIP) $(SHELL) $(DIR_SRC)/src/stripper \
|
||||
$(ROOT) \
|
||||
$(DIR_SRC)/src/stripper / \
|
||||
--exclude=$(TOOLS_DIR) \
|
||||
--exclude=/dev \
|
||||
--exclude=/proc \
|
||||
--exclude=/sys \
|
||||
--exclude=/tmp \
|
||||
--exclude=/usr/src \
|
||||
--exclude=/usr/lib/vdr \
|
||||
--exclude=/usr/sbin/vdr \
|
||||
--exclude=/var/tmp \
|
||||
--exclude=/usr/lib/go
|
||||
endif
|
||||
|
||||
9
make.sh
9
make.sh
@@ -556,6 +556,11 @@ enterchroot() {
|
||||
|
||||
local PATH="${TOOLS_DIR}/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:${TOOLS_DIR}/bin"
|
||||
|
||||
# Prepend any custom changes to PATH
|
||||
if [ -n "${CUSTOM_PATH}" ]; then
|
||||
PATH="${CUSTOM_PATH}:${PATH}"
|
||||
fi
|
||||
|
||||
PATH="${PATH}" chroot ${LFS} env -i \
|
||||
HOME="/root" \
|
||||
TERM="${TERM}" \
|
||||
@@ -695,7 +700,7 @@ lfsmake2() {
|
||||
local PS1='\u:\w$ '
|
||||
|
||||
enterchroot \
|
||||
${EXTRA_PATH}bash -x -c "cd /usr/src/lfs && \
|
||||
bash -x -c "cd /usr/src/lfs && \
|
||||
make -f $* \
|
||||
LFS_BASEDIR=/usr/src install" \
|
||||
>> ${LOGFILE} 2>&1 &
|
||||
@@ -1693,7 +1698,7 @@ buildinstaller() {
|
||||
lfsmake2 memtest
|
||||
lfsmake2 installer
|
||||
# use toolchain bash for chroot to strip
|
||||
EXTRA_PATH=${TOOLS_DIR}/bin/ lfsmake2 strip
|
||||
CUSTOM_PATH="${TOOLS_DIR}/bin" lfsmake2 strip
|
||||
}
|
||||
|
||||
buildpackages() {
|
||||
|
||||
75
src/stripper
75
src/stripper
@@ -1,49 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
dirs=""
|
||||
excludes="/dev /proc /sys /run"
|
||||
paths=()
|
||||
excludes=()
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--exclude=*)
|
||||
excludes="${excludes} ${1#*=}"
|
||||
excludes+=( "!" "-path" "${1#*=}/*" )
|
||||
;;
|
||||
*)
|
||||
dirs="${dirs} ${1}"
|
||||
paths+=( "${1}" )
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
function _strip() {
|
||||
local file=${1}
|
||||
local strip="${STRIP-strip}"
|
||||
local file="${1}"
|
||||
local args=()
|
||||
|
||||
local exclude l
|
||||
for exclude in ${excludes}; do
|
||||
l=${#exclude}
|
||||
if [ "${file:0:${l}}" = "${exclude}" ]; then
|
||||
# Fetch the filetype
|
||||
local type="$(readelf -h "${file}" 2>/dev/null)"
|
||||
|
||||
case "${type}" in
|
||||
# Libraries and Relocatable binaries
|
||||
*Type:*"DYN (Shared object file)"*)
|
||||
args+=( "--strip-all" )
|
||||
;;
|
||||
|
||||
# Binaries
|
||||
*Type:*"EXEC (Executable file)"*)
|
||||
args+=( "--strip-all" )
|
||||
;;
|
||||
|
||||
# Static libraries
|
||||
*Type:*"REL (Relocatable file)"*)
|
||||
args+=( "--strip-debug" "--remove-section=.comment" "--remove-section=.note" )
|
||||
;;
|
||||
|
||||
# Skip any unrecognised files
|
||||
*)
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
# Fetch any capabilities
|
||||
local capabilities="$(getfattr --no-dereference --name="security.capability" \
|
||||
--absolute-names --dump "${file}" 2>/dev/null)"
|
||||
|
||||
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}
|
||||
if ! strip "${args[@]}" "${file}"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# Restore capabilities
|
||||
if [ -n "${capabilities}" ]; then
|
||||
@@ -51,18 +60,8 @@ function _strip() {
|
||||
fi
|
||||
}
|
||||
|
||||
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 $?
|
||||
for path in ${paths[@]}; do
|
||||
for file in $(find / -xdev "${excludes[@]}" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) 2>/dev/null); do
|
||||
_strip "${file}" || exit $?
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user