3 # Compare stripped copies of two given object files.
5 # Copyright (C) 2007, 2008, 2009 Free Software Foundation
6 # Originally by Alexandre Oliva <aoliva@redhat.com>
8 # This file is part of GCC.
10 # GCC is free software; you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License as published by the Free
12 # Software Foundation; either version 3, or (at your option) any later
15 # GCC is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 # License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with GCC; see the file COPYING3. If not see
22 # <http://www.gnu.org/licenses/>.
34 echo 'usage: compare-debug file1.o file2.o' >&2
38 if test ! -f "$1"; then
39 echo "$1" does not exist
>&2
43 if test ! -f "$2"; then
44 echo "$2" does not exist
>&2
49 while test -f "$1.$suf1"; do
54 while test -f "$2.$suf2"; do
58 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
62 # The strip command on darwin does not remove all debug info.
63 # Fortunately, we can use ld to do it instead.
64 ld
-S -r -no_uuid "$1" -o "$1.$suf1"
65 ld
-S -r -no_uuid "$2" -o "$2.$suf2"
76 if cmp "$1.$suf1" "$2.$suf2"; then
81 # Assembler-generated CFI will add an .eh_frame section for -g not
82 # present in -g0. Try to cope with it by checking that an .eh_frame
83 # section is present in either object file, and then stripping it
84 # off before re-comparing.
90 for t
in objdump readelf eu-readelf
; do
91 if ($t --help) 2>&1 |
grep ' --\[*section-\]*headers' > /dev
/null
; then
94 $cmd --section-headers "$1.$suf1" |
grep '\.eh_frame' > /dev
/null
97 $cmd --section-headers "$2.$suf2" |
grep '\.eh_frame' > /dev
/null
104 # If we found .eh_frame in one but not the other, or if we could not
105 # find a command to tell, or if there are LTO sections, try to strip
106 # off the .eh_frame and LTO sections from both.
107 if test "x$cmp1" != "x$cmp2" ||
test "x$cmd" = "x" ||
108 $cmd --section-headers "$1.$suf1" |
grep '.gnu.lto_' > /dev
/null ||
109 $cmd --section-headers "$2.$suf2" |
grep '.gnu.lto_' > /dev
/null
; then
111 while test -f "$1.$suf3"; do
116 while test -f "$2.$suf4"; do
120 trap 'rm -f "$1.$suf1" "$2.$suf2" "$1.$suf3" "$2.$suf4"' 0 1 2 15
122 echo stripping off .eh_frame and LTO sections
, then retrying
>&2
124 seclist
=".eh_frame .rel.eh_frame .rela.eh_frame"
125 if test "x$cmd" != "x"; then
126 seclist
="$seclist "`{ $cmd --section-headers "$1.$suf1"; $cmd --section-headers "$2.$suf2"; } | sed -n 's,.* \(\.gnu\.lto_[^ ]*\).*,\1,p' | sort -u`
128 rsopts
=`for sec in $seclist; do echo " --remove-section $sec"; done`
130 if (objcopy
-v) 2>&1 |
grep ' --remove-section' > /dev
/null
; then
131 objcopy
$rsopts "$1.$suf1" "$1.$suf3"
132 mv "$1.$suf3" "$1.$suf1"
134 objcopy
$rsopts "$2.$suf2" "$2.$suf4"
135 mv "$2.$suf4" "$2.$suf2"
136 elif (strip
--help) 2>&1 |
grep ' --remove-section' > /dev
/null
; then
137 cp "$1.$suf1" "$1.$suf3"
138 strip
$rsopts "$1.$suf3"
139 mv "$1.$suf3" "$1.$suf1"
141 cp "$2.$suf2" "$2.$suf4"
142 strip
$rsopts "$2.$suf4"
143 mv "$2.$suf4" "$2.$suf2"
145 echo failed to strip off .eh_frame
>&2
148 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
150 if cmp "$1.$suf1" "$2.$suf2"; then
158 $rm "$1.$suf1" "$2.$suf2"
160 trap "exit $status; exit" 0 1 2 15
162 if test -f "$1".gkd ||
test -f "$2".gkd
; then
163 if cmp "$1".gkd
"$2".gkd
; then