libstdc++: Implement P2918R0 "Runtime format strings II" for C++26
[official-gcc.git] / contrib / compare-lto
blob996f08a4a98cccbbd383e7f366c75ad7f3bd23c1
1 #! /bin/sh
3 # Compare copies of two given object files.
5 # Copyright (C) 2007-2024 Free Software Foundation, Inc.
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
14 # version.
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/>.
25 rm='rm -f'
27 case $1 in
28 -p | --preserve)
29 rm='echo preserving'
30 shift
32 esac
34 if test $# != 2; then
35 echo 'usage: compare-lto file1 file2' >&2
36 exit 1
39 if test ! -f "$1"; then
40 echo "$1" does not exist >&2
41 exit 1
44 if test ! -f "$2"; then
45 echo "$2" does not exist >&2
46 exit 1
49 suf1=stripped
50 while test -f "$1.$suf1"; do
51 suf1=$suf1.
52 done
54 suf2=stripped
55 while test -f "$2.$suf2"; do
56 suf2=$suf2.
57 done
59 trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
61 if cmp "$1" "$2"; then
62 status=0
63 else
64 status=1
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
72 done
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
88 cp "$1" "$1.$suf1"
89 strip $rsopts "$1.$suf1"
91 cp "$2" "$2.$suf2"
92 strip $rsopts "$2.$suf2"
93 else
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
100 status=0
101 else
102 status=1
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
116 if test -f "$1.exe" && cmp -i 256 "$1.exe" "$2.exe"; then
117 status=0
118 else
119 status=1
122 esac
126 $rm "$1.$suf1" "$2.$suf2"
128 trap "exit $status; exit" 0 1 2 15
130 exit $status