rpm/finddebuginfo.diff
Richard Biener 22321f4dde Accepting request 512652 from home:rguenther:branches:Base:System
- Amend finddebuginfo.diff to adjust readelf -Wn pattern matching
  to account for fixed readelf no longer emitting spurious newlines
  with -W.

OBS-URL: https://build.opensuse.org/request/show/512652
OBS-URL: https://build.opensuse.org/package/show/Base:System/rpm?expand=0&rev=399
2017-07-26 12:48:33 +00:00

130 lines
4.6 KiB
Diff

Index: scripts/find-debuginfo.sh
===================================================================
--- scripts/find-debuginfo.sh.orig 2017-02-16 10:54:14.779025209 +0100
+++ scripts/find-debuginfo.sh 2017-07-26 14:39:24.338122534 +0200
@@ -224,6 +224,20 @@ make_id_dup_link()
debug_link "$file" "/$idfile"
}
+# Compare two binaries but ignore the .note.gnu.build-id section
+elfcmp()
+{
+ local tmp1=$(mktemp -t ${1##*/}.XXXXXX)
+ local tmp2=$(mktemp -t ${2##*/}.XXXXXX)
+
+ objcopy -R .note.gnu.build-id -R .gnu_debuglink $1 $tmp1
+ objcopy -R .note.gnu.build-id -R .gnu_debuglink $2 $tmp2
+ cmp -s $tmp1 $tmp2
+ local res=$?
+ rm -f $tmp1 $tmp2
+ return $res
+}
+
# Make a build-id symlink for id $1 with suffix $3 to file $2.
make_id_link()
{
@@ -244,7 +258,7 @@ make_id_link()
local other=$(readlink -m "$root_idfile")
other=${other#$RPM_BUILD_ROOT}
if cmp -s "$root_idfile" "$RPM_BUILD_ROOT$file" ||
- eu-elfcmp -q "$root_idfile" "$RPM_BUILD_ROOT$file" 2> /dev/null; then
+ elfcmp "$root_idfile" "$RPM_BUILD_ROOT$file" ; then
# Two copies. Maybe one has to be setuid or something.
echo >&2 "*** WARNING: identical binaries are copied, not linked:"
echo >&2 " $file"
@@ -273,12 +287,18 @@ strict_error=ERROR
$strict || strict_error=WARNING
# Strip ELF binaries
-find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
- \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
- -print |
-file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' |
-xargs --no-run-if-empty stat -c '%h %D_%i %n' |
+find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm /111 -or -name "*.so*" -or -name "*.ko" \) -print 0 | sort -z |
+xargs --no-run-if-empty -0 stat -c '%h %D_%i %n' |
while read nlinks inum f; do
+ case $(objdump -h $f 2>/dev/null | egrep -o '(debug[\.a-z_]*|gnu.version)') in
+ *debuglink*) continue ;;
+ *debug*) ;;
+ *gnu.version*)
+ echo "WARNING: "`echo $f | sed -e "s,^$RPM_BUILD_ROOT/*,/,"`" is already stripped!"
+ continue
+ ;;
+ *) continue ;;
+ esac
get_debugfn "$f"
[ -f "${debugfn}" ] && continue
@@ -302,7 +322,11 @@ while read nlinks inum f; do
fi
echo "extracting debug info from $f"
- id=$(${lib_rpm_dir}/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \
+ mode=$(stat -c %a "$f")
+ chmod +w "$f"
+ id=$($(DEBUGEDIT=$(which debugedit 2>/dev/null); \
+ echo ${DEBUGEDIT:-/usr/lib/rpm/debugedit}) \
+ -b "$RPM_BUILD_DIR" -d /usr/src/debug \
-i -l "$SOURCEFILE" "$f") || exit
if [ $nlinks -gt 1 ]; then
eval linkedid_$inum=\$id
@@ -323,13 +347,25 @@ while read nlinks inum f; do
esac
mkdir -p "${debugdn}"
- if test -w "$f"; then
- strip_to_debug "${debugfn}" "$f"
- else
- chmod u+w "$f"
- strip_to_debug "${debugfn}" "$f"
- chmod u-w "$f"
- fi
+ objcopy --only-keep-debug $f $debugfn || :
+ (
+ shopt -s extglob
+ strip_option="--strip-all"
+ case "$f" in
+ *.ko)
+ strip_option="--strip-debug" ;;
+ *$STRIP_KEEP_SYMTAB*)
+ if test -n "$STRIP_KEEP_SYMTAB"; then
+ strip_option="--strip-debug"
+ fi
+ ;;
+ esac
+ if test "$NO_DEBUGINFO_STRIP_DEBUG" = true ; then
+ strip_option=
+ fi
+ objcopy --add-gnu-debuglink=$debugfn -R .comment -R .GCC.command.line $strip_option $f
+ chmod $mode $f
+ ) || :
# strip -g implies we have full symtab, don't add mini symtab in that case.
$strip_g || ($include_minidebug && add_minidebug "${debugfn}" "$f")
@@ -366,7 +402,7 @@ if $run_dwz && type dwz >/dev/null 2>&1
rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null
if [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" ]; then
id="`readelf -Wn "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" \
- 2>/dev/null | sed -n 's/^ Build ID: \([0-9a-f]\+\)/\1/p'`"
+ 2>/dev/null | sed -n 's/^.* Build ID: \([0-9a-f]\+\)/\1/p'`"
[ -n "$id" ] \
&& make_id_link "$id" "/usr/lib/debug/.dwz/${dwz_multifile_name}" .debug
fi
@@ -399,12 +435,14 @@ if [ -s "$SOURCEFILE" ]; then
# stupid cpio creates new directories in mode 0700, fixup
find "${RPM_BUILD_ROOT}/usr/src/debug" -type d -print0 |
xargs --no-run-if-empty -0 chmod a+rx
+ find "${RPM_BUILD_ROOT}/usr/src/debug" -type f -print0 |
+ xargs --no-run-if-empty -0 chmod a+r
fi
if [ -d "${RPM_BUILD_ROOT}/usr/lib" -o -d "${RPM_BUILD_ROOT}/usr/src" ]; then
((nout > 0)) ||
test ! -d "${RPM_BUILD_ROOT}/usr/lib" ||
- (cd "${RPM_BUILD_ROOT}/usr/lib"; find debug -type d) |
+ (cd "${RPM_BUILD_ROOT}/usr/lib"; test ! -d debug || find debug -type d) |
sed 's,^,%dir /usr/lib/,' >> "$LISTFILE"
(cd "${RPM_BUILD_ROOT}/usr"