mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-27 13:54:19 +08:00
1dedc12d18
This patch simplifies (!!!) the logic governing the naming of dump files and auxiliary output files in the driver, in the compiler, and in the LTO wrapper. No changes are made to the naming of primary outputs, there are often ways to restore past behavior, and a number of inconsistencies are fixed. Some internal options are removed (-auxbase and -auxbase-strip), sensible existing uses of -dumpdir and -dumpbase options remain unchanged, additional useful cases are added, making for what is still admittedly quite complex. Extensive documentation and testcases provide numerous examples, from normal to corner cases. The most visible changes are: - aux and dump files now always go in the same directory, that defaults to the directory of the primary output, but that can be overridden with -dumpdir, -save-temps=*, or, preserving past behavior, with a -dumpbase with a directory component. - driver and compiler now have the same notion of naming of auxiliary outputs, e.g. .dwo files will no longer be in one location while the debug info suggests they are elsewhere, and -save-temps and .dwo auxiliary outputs now go in the same location as .su, .ci and coverage data, with consistent naming. - explicitly-specified primary output names guide not only the location of aux and dump outputs: the output base name is also used in their base name, as a prefix when also linking (e.g. foo.c bar.c -o foobar creates foobar-foo.dwo and foobar-bar.dwo with -gsplit-dwarf), or as the base name instead of the input name (foo.c -c -o whatever.o creates whatever.su rather than foo.su with -fstack-usage). The preference for the input file base name, quite useful for our testsuite, can be restored with -dumpbase "". When compiling and linking tests in the testsuite with additional inputs, we now use this flag. Files named in dejagnu board ldflags, libs, and ldscripts are now quoted in the gcc testsuite with -Wl, so that they are not counted as additional inputs by the compiler driver. - naming a -dumpbase when compiling multiple sources used to cause dumps from later compiles to overwrite those of earlier ones; it is now used as a prefix when compiling multiple sources, like an executable name above. - the dumpbase, explicitly specified or computed from output or input names, now also governs the naming of aux outputs; since aux outputs usually replaced the suffix from the input name, while dump outputs append their own additional suffixes, a -dumpbase-ext option is introduced to enable a chosen suffix to be dropped from dumpbase to form aux output names. - LTO dump and aux outputs were quite a mess, sometimes leaking temporary output names into -save-temps output names, sometimes conversely generating desirable aux outputs in temporary locations. They now obey the same logic of compiler aux and dump outputs, landing in the expected location and taking the linker output name or an explicit dumpbase overrider into account. - Naming of -fdump-final-insns outputs now follows the dump file naming logic for the .gkd files, and the .gk dump files generated in the second -fcompare-debug compilation get the .gk inserted before the suffix that -dumpbase-ext drops in aux outputs. gcc/ChangeLog: * common.opt (aux_base_name): Define. (dumpbase, dumpdir): Mark as Driver options. (-dumpbase, -dumpdir): Likewise. (dumpbase-ext, -dumpbase-ext): New. (auxbase, auxbase-strip): Drop. * doc/invoke.texi (-dumpbase, -dumpbase-ext, -dumpdir): Document. (-o): Introduce the notion of primary output, mention it influences auxiliary and dump output names as well, add examples. (-save-temps): Adjust, move examples into -dump*. (-save-temps=cwd, -save-temps=obj): Likewise. (-fdump-final-insns): Adjust. * dwarf2out.c (gen_producer_string): Drop auxbase and auxbase_strip; add dumpbase_ext. * gcc.c (enum save_temps): Add SAVE_TEMPS_DUMP. (save_temps_prefix, save_temps_length): Drop. (save_temps_overrides_dumpdir): New. (dumpdir, dumpbase, dumpbase_ext): New. (dumpdir_length, dumpdir_trailing_dash_added): New. (outbase, outbase_length): New. (The Specs Language): Introduce %". Adjust %b and %B. (ASM_FINAL_SPEC): Use %b.dwo for an aux output name always. Precede object file with %w when it's the primary output. (cpp_debug_options): Do not pass on incoming -dumpdir, -dumpbase and -dumpbase-ext options; recompute them with %:dumps. (cc1_options): Drop auxbase with and without compare-debug; use cpp_debug_options instead of dumpbase. Mark asm output with %w when it's the primary output. (static_spec_functions): Drop %:compare-debug-auxbase-opt and %:replace-exception. Add %:dumps. (driver_handle_option): Implement -save-temps=*/-dumpdir mutual overriding logic. Save dumpdir, dumpbase and dumpbase-ext options. Do not save output_file in save_temps_prefix. (adds_single_suffix_p): New. (single_input_file_index): New. (process_command): Combine output dir, output base name, and dumpbase into dumpdir and outbase. (set_collect_gcc_options): Pass a possibly-adjusted -dumpdir. (do_spec_1): Optionally dumpdir instead of save_temps_prefix, and outbase instead of input_basename in %b, %B and in -save-temps aux files. Handle empty argument %". (driver::maybe_run_linker): Adjust dumpdir and auxbase. (compare_debug_dump_opt_spec_function): Adjust gkd dump file naming. Spec-quote the computed -fdump-final-insns file name. (debug_auxbase_opt): Drop. (compare_debug_self_opt_spec_function): Drop auxbase-strip computation. (compare_debug_auxbase_opt_spec_function): Drop. (not_actual_file_p): New. (replace_extension_spec_func): Drop. (dumps_spec_func): New. (convert_white_space): Split-out parts into... (quote_string, whitespace_to_convert_p): ... these. New. (quote_spec_char_p, quote_spec, quote_spec_arg): New. (driver::finalize): Release and reset new variables; drop removed ones. * lto-wrapper.c (HAVE_TARGET_EXECUTABLE_SUFFIX): Define if... (TARGET_EXECUTABLE_SUFFIX): ... is defined; define this to the empty string otherwise. (DUMPBASE_SUFFIX): Drop leading period. (debug_objcopy): Use concat. (run_gcc): Recognize -save-temps=* as -save-temps too. Obey -dumpdir. Pass on empty dumpdir and dumpbase with a directory component. Simplify temp file names. * opts.c (finish_options): Drop aux base name handling. (common_handle_option): Drop auxbase-strip handling. * toplev.c (print_switch_values): Drop auxbase, add dumpbase-ext. (process_options): Derive aux_base_name from dump_base_name and dump_base_ext. (lang_dependent_init): Compute dump_base_ext along with dump_base_name. Disable stack usage and callgraph-info during lto generation and compare-debug recompilation. gcc/fortran/ChangeLog: * options.c (gfc_get_option_string): Drop auxbase, add dumpbase_ext. gcc/ada/ChangeLog: * gcc-interface/lang-specs.h: Drop auxbase and auxbase-strip. Use %:dumps instead of -dumpbase. Add %w for implicit .s primary output. * switch.adb (Is_Internal_GCC_Switch): Recognize dumpdir and dumpbase-ext. Drop auxbase and auxbase-strip. lto-plugin/ChangeLog: * lto-plugin.c (skip_in_suffix): New. (exec_lto_wrapper): Use skip_in_suffix and concat to build non-temporary output names. (onload): Look for -dumpdir in COLLECT_GCC_OPTIONS, and override link_output_name with it. contrib/ChangeLog: * compare-debug: Adjust for .gkd files named as dump files, with the source suffix rather than the object suffix. gcc/testsuite/ChangeLog: * gcc.misc-tests/outputs.exp: New. * gcc.misc-tests/outputs-0.c: New. * gcc.misc-tests/outputs-1.c: New. * gcc.misc-tests/outputs-2.c: New. * lib/gcc-defs.exp (gcc_adjusted_linker_flags): New. (gcc_adjust_linker_flags): New. (dg-additional-files-options): Call it. Pass -dumpbase "" when there are additional sources. * lib/profopt.exp (profopt-execute): Pass the executable suffix with -dumpbase-ext. * lib/scandump.exp (dump-base): Mention -dumpbase "" use. * lib/scanltranstree.exp: Adjust dump suffix expectation. * lib/scanwpaipa.exp: Likewise.
215 lines
5.1 KiB
Bash
Executable File
215 lines
5.1 KiB
Bash
Executable File
#! /bin/sh
|
|
|
|
# Compare stripped copies of two given object files.
|
|
|
|
# Copyright (C) 2007, 2008, 2009, 2010, 2012, 2020 Free Software Foundation
|
|
# Originally by Alexandre Oliva <aoliva@redhat.com>
|
|
|
|
# This file is part of GCC.
|
|
|
|
# GCC is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free
|
|
# Software Foundation; either version 3, or (at your option) any later
|
|
# version.
|
|
|
|
# GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
# License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with GCC; see the file COPYING3. If not see
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
rm='rm -f'
|
|
|
|
case $1 in
|
|
-p | --preserve)
|
|
rm='echo preserving'
|
|
shift
|
|
;;
|
|
esac
|
|
|
|
if test $# != 2; then
|
|
echo 'usage: compare-debug file1.o file2.o' >&2
|
|
exit 1
|
|
fi
|
|
|
|
if test ! -f "$1"; then
|
|
echo "$1" does not exist >&2
|
|
exit 1
|
|
fi
|
|
|
|
if test ! -f "$2"; then
|
|
echo "$2" does not exist >&2
|
|
exit 1
|
|
fi
|
|
|
|
suf1=stripped
|
|
while test -f "$1.$suf1"; do
|
|
suf1=$suf1.
|
|
done
|
|
|
|
suf2=stripped
|
|
while test -f "$2.$suf2"; do
|
|
suf2=$suf2.
|
|
done
|
|
|
|
trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
|
|
|
|
case `uname -s` in
|
|
Darwin)
|
|
# The strip command on darwin does not remove all debug info.
|
|
# Fortunately, we can use ld to do it instead.
|
|
ld -S -r -no_uuid "$1" -o "$1.$suf1"
|
|
ld -S -r -no_uuid "$2" -o "$2.$suf2"
|
|
;;
|
|
*)
|
|
cp "$1" "$1.$suf1"
|
|
strip "$1.$suf1"
|
|
|
|
cp "$2" "$2.$suf2"
|
|
strip "$2.$suf2"
|
|
;;
|
|
esac
|
|
|
|
remove_comment ()
|
|
{
|
|
file=$1
|
|
opts=
|
|
for s in `objdump --section-headers "$file" | awk '{ print $2 }'`; do
|
|
case "$s" in
|
|
.comment*)
|
|
opts="$opts --remove-section $s"
|
|
;;
|
|
esac
|
|
done
|
|
[ -n "$opts" ] && objcopy $opts $file
|
|
}
|
|
|
|
if cmp "$1.$suf1" "$2.$suf2"; then
|
|
status=0
|
|
else
|
|
status=1
|
|
|
|
# Remove any .comment sections.
|
|
if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null \
|
|
&& (objdump --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then
|
|
remove_comment "$1.$suf1"
|
|
remove_comment "$2.$suf2"
|
|
if cmp "$1.$suf1" "$2.$suf2"; then
|
|
status=0
|
|
fi
|
|
fi
|
|
|
|
# Assembler-generated CFI will add an .eh_frame section for -g not
|
|
# present in -g0. Try to cope with it by checking that an .eh_frame
|
|
# section is present in either object file, and then stripping it
|
|
# off before re-comparing.
|
|
|
|
cmd=
|
|
cmp1=
|
|
cmp2=
|
|
|
|
for t in objdump readelf eu-readelf; do
|
|
if ($t --help) 2>&1 | grep ' --\[*section-\]*headers' > /dev/null; then
|
|
cmd=$t
|
|
|
|
$cmd --section-headers "$1.$suf1" | grep '\.eh_frame' > /dev/null
|
|
cmp1=$?
|
|
|
|
$cmd --section-headers "$2.$suf2" | grep '\.eh_frame' > /dev/null
|
|
cmp2=$?
|
|
|
|
break
|
|
fi
|
|
done
|
|
|
|
# If we found .eh_frame in one but not the other, or if we could not
|
|
# find a command to tell, or if there are LTO sections, try to strip
|
|
# off the .eh_frame and LTO sections from both.
|
|
if test "x$cmp1" != "x$cmp2" || test "x$cmd" = "x" ||
|
|
$cmd --section-headers "$1.$suf1" | grep '.gnu.lto_' > /dev/null ||
|
|
$cmd --section-headers "$2.$suf2" | grep '.gnu.lto_' > /dev/null ; then
|
|
suf3=$suf1.
|
|
while test -f "$1.$suf3"; do
|
|
suf3=$suf3.
|
|
done
|
|
|
|
suf4=$suf2.
|
|
while test -f "$2.$suf4"; do
|
|
suf4=$suf4.
|
|
done
|
|
|
|
trap 'rm -f "$1.$suf1" "$2.$suf2" "$1.$suf3" "$2.$suf4"' 0 1 2 15
|
|
|
|
echo stripping off .eh_frame and LTO sections, then retrying >&2
|
|
|
|
seclist=".eh_frame .rel.eh_frame .rela.eh_frame"
|
|
if test "x$cmd" != "x"; then
|
|
seclist="$seclist "`{ $cmd --section-headers "$1.$suf1"; $cmd --section-headers "$2.$suf2"; } | sed -n 's,.* \(\.gnu\.lto_[^ ]*\).*,\1,p' | sort -u`
|
|
fi
|
|
rsopts=`for sec in $seclist; do echo " --remove-section $sec"; done`
|
|
|
|
if (objcopy -v) 2>&1 | grep ' --remove-section' > /dev/null; then
|
|
objcopy $rsopts "$1.$suf1" "$1.$suf3"
|
|
mv "$1.$suf3" "$1.$suf1"
|
|
|
|
objcopy $rsopts "$2.$suf2" "$2.$suf4"
|
|
mv "$2.$suf4" "$2.$suf2"
|
|
elif (strip --help) 2>&1 | grep ' --remove-section' > /dev/null; then
|
|
cp "$1.$suf1" "$1.$suf3"
|
|
strip $rsopts "$1.$suf3"
|
|
mv "$1.$suf3" "$1.$suf1"
|
|
|
|
cp "$2.$suf2" "$2.$suf4"
|
|
strip $rsopts "$2.$suf4"
|
|
mv "$2.$suf4" "$2.$suf2"
|
|
else
|
|
echo failed to strip off .eh_frame >&2
|
|
fi
|
|
|
|
trap 'rm -f "$1.$suf1" "$2.$suf2"' 0 1 2 15
|
|
|
|
if cmp "$1.$suf1" "$2.$suf2"; then
|
|
status=0
|
|
else
|
|
status=1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
$rm "$1.$suf1" "$2.$suf2"
|
|
|
|
trap "exit $status; exit" 0 1 2 15
|
|
|
|
# Replace the suffix in $1 and $2 with .*.gkd, compare them if a
|
|
# single file is found by the globbing.
|
|
base1=`echo "$1" | sed '$s,\.[^.]*$,,'` gkd1=
|
|
for f in "$base1".*.gkd; do
|
|
if test "x$gkd1" != x; then
|
|
gkd1=
|
|
break
|
|
elif test -f "$f"; then
|
|
gkd1=$f
|
|
fi
|
|
done
|
|
base2=`echo "$2" | sed '$s,\.[^.]*$,,'` gkd2=
|
|
for f in "$base2".*.gkd; do
|
|
if test "x$gkd2" != x; then
|
|
gkd2=
|
|
break
|
|
elif test -f "$f"; then
|
|
gkd2=$f
|
|
fi
|
|
done
|
|
if test "x$gkd1" != x || test "x$gkd2" != x; then
|
|
if cmp "${gkd1-/dev/null}" "${gkd2-/dev/null}"; then
|
|
:
|
|
else
|
|
status=$?
|
|
fi
|
|
fi
|
|
|
|
exit $status
|