libmakepkg: strip - split handling of hardlinks
Handle singly and muptiply hard-linked files separately. Also collect information on hard linked files to avoid searching the entire package to check for hard links. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
0c136ecc8a
commit
dbde37aafb
1 changed files with 58 additions and 41 deletions
|
@ -103,14 +103,6 @@ collect_debug_symbols() {
|
||||||
safe_objcopy "$binary" --remove-section=.gnu_debuglink
|
safe_objcopy "$binary" --remove-section=.gnu_debuglink
|
||||||
safe_objcopy "$binary" --add-gnu-debuglink="$dbgdir/${binary#/}.debug"
|
safe_objcopy "$binary" --add-gnu-debuglink="$dbgdir/${binary#/}.debug"
|
||||||
|
|
||||||
# create any needed hardlinks
|
|
||||||
while IFS= read -rd '' file ; do
|
|
||||||
if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug" ]]; then
|
|
||||||
mkdir -p "$dbgdir/${file%/*}"
|
|
||||||
ln "$dbgdir/${binary}.debug" "$dbgdir/${file}.debug"
|
|
||||||
fi
|
|
||||||
done < <(find . -type f -perm -u+w -print0 2>/dev/null)
|
|
||||||
|
|
||||||
if [[ -n "$bid" ]]; then
|
if [[ -n "$bid" ]]; then
|
||||||
local target
|
local target
|
||||||
mkdir -p "$dbgdir/.build-id/${bid:0:2}"
|
mkdir -p "$dbgdir/.build-id/${bid:0:2}"
|
||||||
|
@ -145,26 +137,13 @@ safe_strip_lto() {
|
||||||
rm -f "$tempfile"
|
rm -f "$tempfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_file_stripping() {
|
||||||
|
local binary="$1"
|
||||||
|
local strip_flags
|
||||||
|
|
||||||
tidy_strip() {
|
|
||||||
if check_option "strip" "y"; then
|
|
||||||
msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
|
|
||||||
# make sure library stripping variables are defined to prevent excess stripping
|
|
||||||
[[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
|
|
||||||
[[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
|
|
||||||
|
|
||||||
if check_option "debug" "y"; then
|
|
||||||
dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug"
|
|
||||||
dbgsrcdir="${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
|
||||||
dbgsrc="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@$dbgsrcdir"
|
|
||||||
mkdir -p "$dbgdir" "$dbgsrc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local binary strip_flags
|
|
||||||
find . -type f -perm -u+w -print0 2>/dev/null | LC_ALL=C sort -z | while IFS= read -rd '' binary ; do
|
|
||||||
# skip filepaths that cause stripping issues - ideally these should be temporary
|
# skip filepaths that cause stripping issues - ideally these should be temporary
|
||||||
# guile-2.2
|
# guile-2.2
|
||||||
[[ "$binary" =~ .*/guile/.*\.go$ ]] && continue
|
[[ "$binary" =~ .*/guile/.*\.go$ ]] && return
|
||||||
|
|
||||||
local STATICOBJ=0
|
local STATICOBJ=0
|
||||||
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
|
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
|
||||||
|
@ -186,16 +165,54 @@ tidy_strip() {
|
||||||
elif [[ $binary = *'.ko' ]]; then # Kernel modules
|
elif [[ $binary = *'.ko' ]]; then # Kernel modules
|
||||||
strip_flags="$STRIP_SHARED"
|
strip_flags="$STRIP_SHARED"
|
||||||
else
|
else
|
||||||
continue
|
return
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
continue ;;
|
return ;;
|
||||||
esac
|
esac
|
||||||
(( ! STATICOBJ )) && collect_debug_symbols "$binary"
|
(( ! STATICOBJ )) && collect_debug_symbols "$binary"
|
||||||
safe_strip_file "$binary" ${strip_flags}
|
safe_strip_file "$binary" ${strip_flags}
|
||||||
(( STATICOBJ )) && safe_strip_lto "$binary"
|
(( STATICOBJ )) && safe_strip_lto "$binary"
|
||||||
done
|
}
|
||||||
|
|
||||||
|
tidy_strip() {
|
||||||
|
if check_option "strip" "y"; then
|
||||||
|
msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
|
||||||
|
# make sure library stripping variables are defined to prevent excess stripping
|
||||||
|
[[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
|
||||||
|
[[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
|
||||||
|
|
||||||
|
if check_option "debug" "y"; then
|
||||||
|
dbgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@/usr/lib/debug"
|
||||||
|
dbgsrcdir="${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
|
||||||
|
dbgsrc="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@$dbgsrcdir"
|
||||||
|
mkdir -p "$dbgdir" "$dbgsrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -rd '' binary ; do
|
||||||
|
process_file_stripping "$binary"
|
||||||
|
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
|
||||||
|
|
||||||
|
# hardlinks only need processed once, but need additional links in debug packages
|
||||||
|
declare -A hardlinks
|
||||||
|
while IFS= read -rd '' binary ; do
|
||||||
|
if check_option "debug" "y"; then
|
||||||
|
local inode="$(@INODECMD@ -- "$binary")"
|
||||||
|
inode=${inode%% *}
|
||||||
|
if [[ -z "${hardlinks[$inode]}" ]]; then
|
||||||
|
hardlinks[$inode]="$binary"
|
||||||
|
else
|
||||||
|
if [[ -f "$dbgdir/${hardlinks[$inode]}.debug" ]]; then
|
||||||
|
mkdir -p "$dbgdir/${binary%/*}"
|
||||||
|
ln "$dbgdir/${hardlinks[$inode]}.debug" "$dbgdir/${binary}.debug"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
process_file_stripping "$binary"
|
||||||
|
done < <(find . -type f -perm -u+w -links +1 -print0 2>/dev/null | LC_ALL=C sort -z)
|
||||||
|
|
||||||
elif check_option "debug" "y"; then
|
elif check_option "debug" "y"; then
|
||||||
msg2 "$(gettext "Copying source files needed for debug symbols...")"
|
msg2 "$(gettext "Copying source files needed for debug symbols...")"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue