3 # Compare copies of two given object files.
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>
9 # This file is part of GCC.
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
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.
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/>.
35 echo 'usage: compare-lto file1 file2' >&2
39 if test ! -f "$1"; then
40 echo "$1" does not exist
>&2
44 if test ! -f "$2"; then
45 echo "$2" does not exist
>&2
50 while test -f "$1.$suf1"; do
55 while test -f "$2.$suf2"; do
59 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
61 if cmp "$1" "$2"; then
67 for t
in objdump readelf eu-readelf
; do
68 if ($t --help) 2>&1 |
grep ' --\[*section-\]*headers' > /dev
/null
; then
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
79 echo stripping off LTO option section
, then retrying
>&2
81 seclist
=".gnu.lto_.opts"
82 rsopts
=`for sec in $seclist; do echo " --remove-section $sec"; done`
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
89 strip
$rsopts "$1.$suf1"
92 strip
$rsopts "$2.$suf2"
94 echo failed to strip off LTO option section
>&2
97 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
99 if cmp "$1.$suf1" "$2.$suf2"; then
105 # PE-COFF executables are timestamped so skip leading bytes for them.
109 if cmp -i 256 "$1" "$2"; then
116 if test -f "$1.exe" && cmp -i 256 "$1.exe" "$2.exe"; then
126 $rm "$1.$suf1" "$2.$suf2"
128 trap "exit $status; exit" 0 1 2 15