131
|
1 #! /bin/sh
|
|
2
|
|
3 # Compare copies of two given object files.
|
|
4
|
|
5 # Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation
|
|
6 # Originally by Alexandre Oliva <aoliva@redhat.com>
|
|
7 # Modified for LTO bootstrap by Richard Biener <rguenther@suse.de>
|
|
8
|
|
9 # This file is part of GCC.
|
|
10
|
|
11 # GCC is free software; you can redistribute it and/or modify it under
|
|
12 # the terms of the GNU General Public License as published by the Free
|
|
13 # Software Foundation; either version 3, or (at your option) any later
|
|
14 # version.
|
|
15
|
|
16 # GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
18 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
19 # License for more details.
|
|
20
|
|
21 # You should have received a copy of the GNU General Public License
|
|
22 # along with GCC; see the file COPYING3. If not see
|
|
23 # <http://www.gnu.org/licenses/>.
|
|
24
|
|
25 rm='rm -f'
|
|
26
|
|
27 case $1 in
|
|
28 -p | --preserve)
|
|
29 rm='echo preserving'
|
|
30 shift
|
|
31 ;;
|
|
32 esac
|
|
33
|
|
34 if test $# != 2; then
|
|
35 echo 'usage: compare-lto file1.o file2.o' >&2
|
|
36 exit 1
|
|
37 fi
|
|
38
|
|
39 if test ! -f "$1"; then
|
|
40 echo "$1" does not exist >&2
|
|
41 exit 1
|
|
42 fi
|
|
43
|
|
44 if test ! -f "$2"; then
|
|
45 echo "$2" does not exist >&2
|
|
46 exit 1
|
|
47 fi
|
|
48
|
|
49 suf1=stripped
|
|
50 while test -f "$1.$suf1"; do
|
|
51 suf1=$suf1.
|
|
52 done
|
|
53
|
|
54 suf2=stripped
|
|
55 while test -f "$2.$suf2"; do
|
|
56 suf2=$suf2.
|
|
57 done
|
|
58
|
|
59 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
|
|
60
|
|
61 if cmp "$1" "$2"; then
|
|
62 status=0
|
|
63 else
|
|
64 status=1
|
|
65
|
|
66 cmd=
|
|
67 for t in objdump readelf eu-readelf; do
|
|
68 if ($t --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then
|
|
69 cmd=$t
|
|
70 break
|
|
71 fi
|
|
72 done
|
|
73
|
|
74 # If there are LTO option sections, try to strip them off.
|
|
75 if test "x$cmd" = "x" ||
|
|
76 $cmd --section-headers "$1" | grep '.gnu.lto_.opts' > /dev/null ||
|
|
77 $cmd --section-headers "$2" | grep '.gnu.lto_.opts' > /dev/null ; then
|
|
78
|
|
79 echo stripping off LTO option section, then retrying >&2
|
|
80
|
|
81 seclist=".gnu.lto_.opts"
|
|
82 rsopts=`for sec in $seclist; do echo " --remove-section $sec"; done`
|
|
83
|
|
84 if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null; then
|
|
85 objcopy $rsopts "$1" "$1.$suf1"
|
|
86 objcopy $rsopts "$2" "$2.$suf2"
|
|
87 elif (strip --help) 2>&1 | grep ' --remove-section' > /dev/null; then
|
|
88 cp "$1" "$1.$suf1"
|
|
89 strip $rsopts "$1.$suf1"
|
|
90
|
|
91 cp "$2" "$2.$suf2"
|
|
92 strip $rsopts "$2.$suf2"
|
|
93 else
|
|
94 echo failed to strip off LTO option section >&2
|
|
95 fi
|
|
96
|
|
97 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
|
|
98
|
|
99 if cmp "$1.$suf1" "$2.$suf2"; then
|
|
100 status=0
|
|
101 else
|
|
102 status=1
|
|
103 fi
|
|
104 fi
|
|
105 fi
|
|
106
|
|
107 $rm "$1.$suf1" "$2.$suf2"
|
|
108
|
|
109 trap "exit $status; exit" 0 1 2 15
|
|
110
|
|
111 exit $status
|