Revert "Modify eu-strip option to perform strip in post script of rpm package & add...
[platform/upstream/rpm.git] / scripts / find-debuginfo.sh
index 9925626..efcc72e 100644 (file)
@@ -95,13 +95,18 @@ debugdir="${RPM_BUILD_ROOT}/usr/lib/debug"
 
 strip_to_debug()
 {
-  local g=
   local r=
   $strip_r && r=--reloc-debug-sections
-  $strip_g && case "$(file -bi "$2")" in
-  application/x-sharedlib*) g=-g ;;
+  case $2 in
+      *.ko)
+         # don't attempt to create a minimal backtrace binary for
+         # kernel modules as this just causes the stripping process
+         # to be skipped entirely
+         eu-strip --remove-comment $r -f "$1" "$2" || exit
+         ;;
+      *)
+         eu-strip --remove-comment -g -f "$1" "$2" || exit
   esac
-  eu-strip --remove-comment $r $g -f "$1" "$2" || exit
   chmod 444 "$1" || exit
 }
 
@@ -149,6 +154,11 @@ debug_link()
 # Provide .2, .3, ... symlinks to all filename instances of this build-id.
 make_id_dup_link()
 {
+  # See https://bugzilla.redhat.com/show_bug.cgi?id=641377 for the reasoning, 
+  # but it has seveal drawbacks as we would need to split the .1 suffixes into 
+  # different subpackages and it's about impossible to predict the number
+  # -> perhaps later
+  return
   local id="$1" file="$2" idfile
 
   local n=1
@@ -214,7 +224,8 @@ make_id_link()
 get_debugfn()
 {
   dn=$(dirname "${1#$RPM_BUILD_ROOT}")
-  bn=$(basename "$1" .debug).debug
+# Do not strip existing .debug suffixes
+  bn=$(basename "$1").debug
 
   debugdn=${debugdir}${dn}
   debugfn=${debugdn}/${bn}
@@ -226,7 +237,7 @@ strict_error=ERROR
 $strict || strict_error=WARNING
 
 # Strip ELF binaries (and no static libraries)
-find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm +111 -or -name "*.so*" -or -name "*.ko" \) ! -name "*.a" -print0 | sort -z |
+find $RPM_BUILD_ROOT ! -path "${debugdir}/*.debug" -type f \( -perm /111 -or -name "*.so*" -or -name "*.ko" \) ! -name "*.a" -print0 | 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
@@ -261,8 +272,6 @@ while read nlinks inum f; do
   fi
 
   echo "extracting debug info from $f"
-  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
@@ -285,25 +294,37 @@ while read nlinks inum f; do
   esac
 
   mkdir -p "${debugdn}"
-  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
-  ) || :
+  if [ -e "${BUILDDIR}/Kconfig" ] ; then
+      mode=$(stat -c %a "$f")
+      chmod +w "$f"
+      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
+      ) || :
+  else
+      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
+  fi
 
   if [ -n "$id" ]; then
     make_id_link "$id" "$dn/$(basename $f)"
@@ -311,19 +332,11 @@ while read nlinks inum f; do
   fi
 done || exit
 
-# For each symlink whose target has a .debug file,
-# make a .debug symlink to that file.
-find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*" -type l -print |
-while read f
-do
-  t=$(readlink -m "$f").debug
-  f=${f#$RPM_BUILD_ROOT}
-  t=${t#$RPM_BUILD_ROOT}
-  if [ -f "$debugdir$t" ]; then
-    echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
-    debug_link "/usr/lib/debug$t" "${f}.debug"
-  fi
-done
+# We used to make a .debug symlink for each symlink whose target
+# has a .debug file to that file.  This is not necessary because
+# the debuglink section contains only the destination of those links.
+# Creating those links anyway results in debuginfo packages for
+# devel packages just because of the .so symlinks in them.
 
 if [ -s "$SOURCEFILE" ]; then
   mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug"