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,6 +137,44 @@ safe_strip_lto() {
|
||||||
rm -f "$tempfile"
|
rm -f "$tempfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_file_stripping() {
|
||||||
|
local binary="$1"
|
||||||
|
local strip_flags
|
||||||
|
|
||||||
|
# skip filepaths that cause stripping issues - ideally these should be temporary
|
||||||
|
# guile-2.2
|
||||||
|
[[ "$binary" =~ .*/guile/.*\.go$ ]] && return
|
||||||
|
|
||||||
|
local STATICOBJ=0
|
||||||
|
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
|
||||||
|
*Type:*'DYN (Shared object file)'*) # Libraries (.so) or Relocatable binaries
|
||||||
|
strip_flags="$STRIP_SHARED";;
|
||||||
|
*Type:*'DYN (Position-Independent Executable file)'*) # Relocatable binaries
|
||||||
|
strip_flags="$STRIP_SHARED";;
|
||||||
|
*Type:*'EXEC (Executable file)'*) # Binaries
|
||||||
|
if [[ "$(readelf -x .dynamic "$binary" 2>/dev/null)" ]]; then
|
||||||
|
strip_flags="$STRIP_BINARIES"
|
||||||
|
else
|
||||||
|
strip_flags="$STRIP_STATIC"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects
|
||||||
|
if [[ $binary = *'.o' ]] || ar t "$binary" &>/dev/null; then
|
||||||
|
strip_flags="$STRIP_STATIC"
|
||||||
|
STATICOBJ=1
|
||||||
|
elif [[ $binary = *'.ko' ]]; then # Kernel modules
|
||||||
|
strip_flags="$STRIP_SHARED"
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return ;;
|
||||||
|
esac
|
||||||
|
(( ! STATICOBJ )) && collect_debug_symbols "$binary"
|
||||||
|
safe_strip_file "$binary" ${strip_flags}
|
||||||
|
(( STATICOBJ )) && safe_strip_lto "$binary"
|
||||||
|
}
|
||||||
|
|
||||||
tidy_strip() {
|
tidy_strip() {
|
||||||
if check_option "strip" "y"; then
|
if check_option "strip" "y"; then
|
||||||
|
@ -160,42 +190,29 @@ tidy_strip() {
|
||||||
mkdir -p "$dbgdir" "$dbgsrc"
|
mkdir -p "$dbgdir" "$dbgsrc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local binary strip_flags
|
while IFS= read -rd '' binary ; do
|
||||||
find . -type f -perm -u+w -print0 2>/dev/null | LC_ALL=C sort -z | while IFS= read -rd '' binary ; do
|
process_file_stripping "$binary"
|
||||||
# skip filepaths that cause stripping issues - ideally these should be temporary
|
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
|
||||||
# guile-2.2
|
|
||||||
[[ "$binary" =~ .*/guile/.*\.go$ ]] && continue
|
|
||||||
|
|
||||||
local STATICOBJ=0
|
# hardlinks only need processed once, but need additional links in debug packages
|
||||||
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
|
declare -A hardlinks
|
||||||
*Type:*'DYN (Shared object file)'*) # Libraries (.so) or Relocatable binaries
|
while IFS= read -rd '' binary ; do
|
||||||
strip_flags="$STRIP_SHARED";;
|
if check_option "debug" "y"; then
|
||||||
*Type:*'DYN (Position-Independent Executable file)'*) # Relocatable binaries
|
local inode="$(@INODECMD@ -- "$binary")"
|
||||||
strip_flags="$STRIP_SHARED";;
|
inode=${inode%% *}
|
||||||
*Type:*'EXEC (Executable file)'*) # Binaries
|
if [[ -z "${hardlinks[$inode]}" ]]; then
|
||||||
if [[ "$(readelf -x .dynamic "$binary" 2>/dev/null)" ]]; then
|
hardlinks[$inode]="$binary"
|
||||||
strip_flags="$STRIP_BINARIES"
|
else
|
||||||
else
|
if [[ -f "$dbgdir/${hardlinks[$inode]}.debug" ]]; then
|
||||||
strip_flags="$STRIP_STATIC"
|
mkdir -p "$dbgdir/${binary%/*}"
|
||||||
fi
|
ln "$dbgdir/${hardlinks[$inode]}.debug" "$dbgdir/${binary}.debug"
|
||||||
;;
|
|
||||||
*Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects
|
|
||||||
if [[ $binary = *'.o' ]] || ar t "$binary" &>/dev/null; then
|
|
||||||
strip_flags="$STRIP_STATIC"
|
|
||||||
STATICOBJ=1
|
|
||||||
elif [[ $binary = *'.ko' ]]; then # Kernel modules
|
|
||||||
strip_flags="$STRIP_SHARED"
|
|
||||||
else
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
;;
|
fi
|
||||||
*)
|
fi
|
||||||
continue ;;
|
process_file_stripping "$binary"
|
||||||
esac
|
done < <(find . -type f -perm -u+w -links +1 -print0 2>/dev/null | LC_ALL=C sort -z)
|
||||||
(( ! STATICOBJ )) && collect_debug_symbols "$binary"
|
|
||||||
safe_strip_file "$binary" ${strip_flags}
|
|
||||||
(( STATICOBJ )) && safe_strip_lto "$binary"
|
|
||||||
done
|
|
||||||
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