]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - contrib/compare-debug
Remove an invalid defintion [PR101568].
[thirdparty/gcc.git] / contrib / compare-debug
index 820721cd9719d930e98d462e62eea21a23757144..cf80ae32695f6ea646cd8f4b6539d1a85ff66e63 100755 (executable)
@@ -2,7 +2,7 @@
 
 # Compare stripped copies of two given object files.
 
-# Copyright (C) 2007, 2008, 2009 Free Software Foundation
+# Copyright (C) 2007, 2008, 2009, 2010, 2012, 2020 Free Software Foundation
 # Originally by Alexandre Oliva <aoliva@redhat.com>
 
 # This file is part of GCC.
@@ -59,8 +59,10 @@ trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
 
 case `uname -s` in
 Darwin)
-  ld -S -x -r -no_uuid "$1" -o "$1.$suf1"
-  ld -S -x -r -no_uuid "$2" -o "$2.$suf2"
+  # The strip command on darwin does not remove all debug info.
+  # Fortunately, we can use ld to do it instead.
+  ld -S -r -no_uuid "$1" -o "$1.$suf1"
+  ld -S -r -no_uuid "$2" -o "$2.$suf2"
   ;;
 *)
   cp "$1" "$1.$suf1"
@@ -71,11 +73,35 @@ Darwin)
   ;;
 esac
 
+remove_comment ()
+{
+  file=$1
+  opts=
+  for s in `objdump --section-headers "$file" | awk '{ print $2 }'`; do
+    case "$s" in
+    .comment*)
+      opts="$opts --remove-section $s"
+      ;;
+    esac
+  done
+  [ -n "$opts" ] && objcopy $opts $file
+}
+
 if cmp "$1.$suf1" "$2.$suf2"; then
   status=0
 else
   status=1
 
+  # Remove any .comment sections.
+  if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null \
+     && (objdump --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then
+    remove_comment "$1.$suf1"
+    remove_comment "$2.$suf2"
+    if cmp "$1.$suf1" "$2.$suf2"; then
+      status=0
+    fi
+  fi
+
   # Assembler-generated CFI will add an .eh_frame section for -g not
   # present in -g0.  Try to cope with it by checking that an .eh_frame
   # section is present in either object file, and then stripping it
@@ -157,8 +183,28 @@ $rm "$1.$suf1" "$2.$suf2"
 
 trap "exit $status; exit" 0 1 2 15
 
-if test -f "$1".gkd || test -f "$2".gkd; then
-  if cmp "$1".gkd "$2".gkd; then
+# Replace the suffix in $1 and $2 with .*.gkd, compare them if a
+# single file is found by the globbing.
+base1=`echo "$1" | sed '$s,\.[^.]*$,,'` gkd1=
+for f in "$base1".*.gkd; do
+  if test "x$gkd1" != x; then
+    gkd1=
+    break
+  elif test -f "$f"; then
+    gkd1=$f
+  fi
+done
+base2=`echo "$2" | sed '$s,\.[^.]*$,,'` gkd2=
+for f in "$base2".*.gkd; do
+  if test "x$gkd2" != x; then
+    gkd2=
+    break
+  elif test -f "$f"; then
+    gkd2=$f
+  fi
+done
+if test "x$gkd1" != x || test "x$gkd2" != x; then
+  if cmp "${gkd1-/dev/null}" "${gkd2-/dev/null}"; then
     :
   else
     status=$?