]>
Commit | Line | Data |
---|---|---|
5b542315 | 1 | #! /bin/sh |
2 | ||
3 | # Compare stripped copies of two given object files. | |
4 | ||
71e45bc2 | 5 | # Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation |
5b542315 | 6 | # Originally by Alexandre Oliva <aoliva@redhat.com> |
7 | ||
8 | # This file is part of GCC. | |
9 | ||
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 | |
13 | # version. | |
14 | ||
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. | |
19 | ||
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/>. | |
23 | ||
8b96682a | 24 | rm='rm -f' |
25 | ||
26 | case $1 in | |
27 | -p | --preserve) | |
28 | rm='echo preserving' | |
29 | shift | |
30 | ;; | |
31 | esac | |
32 | ||
5b542315 | 33 | if test $# != 2; then |
34 | echo 'usage: compare-debug file1.o file2.o' >&2 | |
35 | exit 1 | |
36 | fi | |
37 | ||
38 | if test ! -f "$1"; then | |
39 | echo "$1" does not exist >&2 | |
40 | exit 1 | |
41 | fi | |
42 | ||
43 | if test ! -f "$2"; then | |
44 | echo "$2" does not exist >&2 | |
45 | exit 1 | |
46 | fi | |
47 | ||
800c7017 | 48 | suf1=stripped |
49 | while test -f "$1.$suf1"; do | |
50 | suf1=$suf1. | |
51 | done | |
5b542315 | 52 | |
800c7017 | 53 | suf2=stripped |
54 | while test -f "$2.$suf2"; do | |
55 | suf2=$suf2. | |
56 | done | |
5b542315 | 57 | |
800c7017 | 58 | trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15 |
5b542315 | 59 | |
077917c7 | 60 | case `uname -s` in |
61 | Darwin) | |
3d6b3bc9 | 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" | |
077917c7 | 66 | ;; |
67 | *) | |
68 | cp "$1" "$1.$suf1" | |
69 | strip "$1.$suf1" | |
5b542315 | 70 | |
077917c7 | 71 | cp "$2" "$2.$suf2" |
72 | strip "$2.$suf2" | |
73 | ;; | |
74 | esac | |
5b542315 | 75 | |
bb9d88f1 | 76 | remove_comment () |
77 | { | |
78 | file=$1 | |
79 | opts= | |
80 | for s in `objdump --section-headers "$file" | awk '{ print $2 }'`; do | |
81 | case "$s" in | |
82 | .comment*) | |
83 | opts="$opts --remove-section $s" | |
84 | ;; | |
85 | esac | |
86 | done | |
87 | [ -n "$opts" ] && objcopy $opts $file | |
88 | } | |
89 | ||
800c7017 | 90 | if cmp "$1.$suf1" "$2.$suf2"; then |
5b542315 | 91 | status=0 |
92 | else | |
93 | status=1 | |
e1f3b609 | 94 | |
bb9d88f1 | 95 | # Remove any .comment sections. |
96 | if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null \ | |
97 | && (objdump --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then | |
98 | remove_comment "$1.$suf1" | |
99 | remove_comment "$2.$suf2" | |
100 | if cmp "$1.$suf1" "$2.$suf2"; then | |
101 | status=0 | |
102 | fi | |
103 | fi | |
104 | ||
e1f3b609 | 105 | # Assembler-generated CFI will add an .eh_frame section for -g not |
106 | # present in -g0. Try to cope with it by checking that an .eh_frame | |
107 | # section is present in either object file, and then stripping it | |
108 | # off before re-comparing. | |
109 | ||
110 | cmd= | |
111 | cmp1= | |
112 | cmp2= | |
113 | ||
114 | for t in objdump readelf eu-readelf; do | |
1261663e | 115 | if ($t --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then |
e1f3b609 | 116 | cmd=$t |
117 | ||
118 | $cmd --section-headers "$1.$suf1" | grep '\.eh_frame' > /dev/null | |
119 | cmp1=$? | |
120 | ||
121 | $cmd --section-headers "$2.$suf2" | grep '\.eh_frame' > /dev/null | |
122 | cmp2=$? | |
123 | ||
124 | break | |
125 | fi | |
126 | done | |
127 | ||
128 | # If we found .eh_frame in one but not the other, or if we could not | |
f3255772 | 129 | # find a command to tell, or if there are LTO sections, try to strip |
130 | # off the .eh_frame and LTO sections from both. | |
131 | if test "x$cmp1" != "x$cmp2" || test "x$cmd" = "x" || | |
132 | $cmd --section-headers "$1.$suf1" | grep '.gnu.lto_' > /dev/null || | |
133 | $cmd --section-headers "$2.$suf2" | grep '.gnu.lto_' > /dev/null ; then | |
e1f3b609 | 134 | suf3=$suf1. |
135 | while test -f "$1.$suf3"; do | |
136 | suf3=$suf3. | |
137 | done | |
138 | ||
139 | suf4=$suf2. | |
140 | while test -f "$2.$suf4"; do | |
141 | suf4=$suf4. | |
142 | done | |
143 | ||
144 | trap 'rm -f "$1.$suf1" "$2.$suf2" "$1.$suf3" "$2.$suf4"' 0 1 2 15 | |
145 | ||
f3255772 | 146 | echo stripping off .eh_frame and LTO sections, then retrying >&2 |
147 | ||
148 | seclist=".eh_frame .rel.eh_frame .rela.eh_frame" | |
149 | if test "x$cmd" != "x"; then | |
150 | seclist="$seclist "`{ $cmd --section-headers "$1.$suf1"; $cmd --section-headers "$2.$suf2"; } | sed -n 's,.* \(\.gnu\.lto_[^ ]*\).*,\1,p' | sort -u` | |
151 | fi | |
152 | rsopts=`for sec in $seclist; do echo " --remove-section $sec"; done` | |
e1f3b609 | 153 | |
1261663e | 154 | if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null; then |
f3255772 | 155 | objcopy $rsopts "$1.$suf1" "$1.$suf3" |
e1f3b609 | 156 | mv "$1.$suf3" "$1.$suf1" |
dfd3ea34 | 157 | |
f3255772 | 158 | objcopy $rsopts "$2.$suf2" "$2.$suf4" |
e1f3b609 | 159 | mv "$2.$suf4" "$2.$suf2" |
1261663e | 160 | elif (strip --help) 2>&1 | grep ' --remove-section' > /dev/null; then |
e1f3b609 | 161 | cp "$1.$suf1" "$1.$suf3" |
f3255772 | 162 | strip $rsopts "$1.$suf3" |
dfd3ea34 | 163 | mv "$1.$suf3" "$1.$suf1" |
e1f3b609 | 164 | |
165 | cp "$2.$suf2" "$2.$suf4" | |
f3255772 | 166 | strip $rsopts "$2.$suf4" |
e1f3b609 | 167 | mv "$2.$suf4" "$2.$suf2" |
dfd3ea34 | 168 | else |
169 | echo failed to strip off .eh_frame >&2 | |
e1f3b609 | 170 | fi |
171 | ||
172 | trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15 | |
e1f3b609 | 173 | |
dfd3ea34 | 174 | if cmp "$1.$suf1" "$2.$suf2"; then |
175 | status=0 | |
176 | else | |
177 | status=1 | |
178 | fi | |
e1f3b609 | 179 | fi |
5b542315 | 180 | fi |
181 | ||
8b96682a | 182 | $rm "$1.$suf1" "$2.$suf2" |
5b542315 | 183 | |
184 | trap "exit $status; exit" 0 1 2 15 | |
185 | ||
9845d120 | 186 | if test -f "$1".gkd || test -f "$2".gkd; then |
187 | if cmp "$1".gkd "$2".gkd; then | |
188 | : | |
189 | else | |
190 | status=$? | |
191 | fi | |
192 | fi | |
193 | ||
5b542315 | 194 | exit $status |