| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# Compare copies of two given object files. |
| 4 |
|
| 5 |
# Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 6 |
# Originally by Alexandre Oliva <[email protected]> |
| 7 |
# Modified for LTO bootstrap by Richard Biener <[email protected]> |
| 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 file2' >&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 |
|
| 105 |
# PE-COFF executables are timestamped so skip leading bytes for them. |
| 106 |
else |
| 107 |
case "$1" in |
| 108 |
*.exe) |
| 109 |
if cmp -i 256 "$1" "$2"; then |
| 110 |
status=0 |
| 111 |
else |
| 112 |
status=1 |
| 113 |
fi |
| 114 |
;; |
| 115 |
*) |
| 116 |
if test -f "$1.exe" && cmp -i 256 "$1.exe" "$2.exe"; then |
| 117 |
status=0 |
| 118 |
else |
| 119 |
status=1 |
| 120 |
fi |
| 121 |
;; |
| 122 |
esac |
| 123 |
fi |
| 124 |
fi |
| 125 |
|
| 126 |
$rm "$1.$suf1" "$2.$suf2" |
| 127 |
|
| 128 |
trap "exit $status; exit" 0 1 2 15 |
| 129 |
|
| 130 |
exit $status |