[PATCH] Adjust testsuites for -flto and without -g
Sam James
sam@gentoo.org
Wed Mar 12 09:55:11 GMT 2025
"H.J. Lu" <hjl.tools@gmail.com> writes:
> Adjust testsuites for binutils built with -flto and without -g:
>
> 1. Pass -fno-lto to objcopy tests which don't work with LTO.
> 2. Update gprof testsuite to avoid LTO and compile with -g for line
> number info checked by tst-gmon-gprof-l.sh.
These look good.
> 3. Append $NOLTO_CFLAGS in ctf.exp.
> 4. For libctf, filter out -flto in CFLAGS for "make check" and also
> prune lto-wrapper warnings.
Apart from the usual wrapper warnings, I assume that it just affects the generated
debug info so the tests break? Nick?
>
> binutils/
>
> PR binutils/32773
> * testsuite/binutils-all/objcopy.exp (no_lto_flags): New.
> (strip_test): Pass $no_lto_flags to target_compile.
> (strip_test_with_saving_a_symbol): Likewise.
> (objcopy_test_without_global_symbol): Likewise.
>
> gprof/
>
> PR binutils/32773
> PR gprof/32779
> * testsuite/Makefile.am (GPROF_FLAGS): Add -g.
> (COMPILE): Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS)".
> (LINK) Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS)
> $(LDFLAGS) -o $@".
> * testsuite/Makefile.in: Regenerated.
>
> ld/
>
> PR binutils/32773
> * testsuite/ld-ctf/ctf.exp (old_CFLAGS): New.
> (CFLAGS_FOR_TARGET): Append $NOLTO_CFLAGS.
>
> libctf/
>
> PR binutils/32773
> * Makefile.am (check-DEJAGNU): Filter out -flto in CFLAGS.
> * Makefile.in: Regenerated.
> * testsuite/lib/ctf-lib.exp (prune_warnings_lto): New.
> (run_lookup_test): Replace prune_warnings with
> prune_warnings_lto.
> (run_lookup_test): Likewise.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
> binutils/testsuite/binutils-all/objcopy.exp | 14 +++++++++++---
> gprof/testsuite/Makefile.am | 10 +++++-----
> gprof/testsuite/Makefile.in | 12 +++++-------
> ld/testsuite/ld-ctf/ctf.exp | 5 +++++
> libctf/Makefile.am | 3 ++-
> libctf/Makefile.in | 3 ++-
> libctf/testsuite/lib/ctf-lib.exp | 14 ++++++++++++--
> 7 files changed, 42 insertions(+), 19 deletions(-)
>
> diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
> index a706efbba18..42a29927a5d 100644
> --- a/binutils/testsuite/binutils-all/objcopy.exp
> +++ b/binutils/testsuite/binutils-all/objcopy.exp
> @@ -36,6 +36,11 @@ if ![is_remote host] {
> set copyfile copy
> }
>
> +set no_lto_flags "additional_flags=-fno-lto"
> +if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object $no_lto_flags] != "" } {
> + set no_lto_flags ""
> +}
> +
> # Test that objcopy does not modify a file when copying it.
> # "object" or "executable" values for type are supported.
>
> @@ -516,10 +521,11 @@ proc strip_test { } {
> global srcdir
> global subdir
> global READELF
> + global no_lto_flags
>
> set test "strip"
>
> - if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
> + if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
> untested $test
> return
> }
> @@ -628,10 +634,11 @@ proc strip_test_with_saving_a_symbol { } {
> global NMFLAGS
> global srcdir
> global subdir
> + global no_lto_flags
>
> set test "strip with saving a symbol"
>
> - if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
> + if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
> untested $test
> return
> }
> @@ -1381,10 +1388,11 @@ proc objcopy_test_without_global_symbol { } {
> global OBJDUMPFLAGS
> global srcdir
> global subdir
> + global no_lto_flags
>
> set test "strip without global symbol "
>
> - if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } {
> + if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object "debug $no_lto_flags"] != "" } {
> untested $test
> return
> }
> diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
> index c4d6c41fcf4..0c80b12e6e4 100644
> --- a/gprof/testsuite/Makefile.am
> +++ b/gprof/testsuite/Makefile.am
> @@ -6,12 +6,12 @@ GPROF = ../gprof$(EXEEXT)
>
> # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph. See
> # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
> -GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
> +# -g is needed for line number info checked by tst-gmon-gprof-l.sh. See
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
> +GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
>
> -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
> - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
> -LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
> - $(AM_LDFLAGS) $(LDFLAGS) -o $@
> +COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
> +LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
>
> # We will add to these later, for each individual test. Note
> # that we add each test under check_SCRIPTS;
> diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
> index 008f6be879e..2ac5f241012 100644
> --- a/gprof/testsuite/Makefile.in
> +++ b/gprof/testsuite/Makefile.in
> @@ -496,13 +496,11 @@ GPROF = ../gprof$(EXEEXT)
>
> # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph. See
> # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
> -GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
> -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
> - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
> -
> -LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
> - $(AM_LDFLAGS) $(LDFLAGS) -o $@
> -
> +# -g is needed for line number info checked by tst-gmon-gprof-l.sh. See
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
> +GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
> +COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
> +LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
>
> # We will add to these later, for each individual test. Note
> # that we add each test under check_SCRIPTS;
> diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
> index c314f2995af..08b47d2db18 100644
> --- a/ld/testsuite/ld-ctf/ctf.exp
> +++ b/ld/testsuite/ld-ctf/ctf.exp
> @@ -33,6 +33,9 @@ if ![check_shared_lib_support] {
> return 0
> }
>
> +set old_CFLAGS "$CFLAGS_FOR_TARGET"
> +append CFLAGS_FOR_TARGET " $NOLTO_CFLAGS"
> +
> if {[info exists env(LC_ALL)]} {
> set old_lc_all $env(LC_ALL)
> }
> @@ -55,3 +58,5 @@ if {[info exists old_lc_all]} {
> } else {
> unset env(LC_ALL)
> }
> +
> +set CFLAGS_FOR_TARGET "$old_CFLAGS"
> diff --git a/libctf/Makefile.am b/libctf/Makefile.am
> index 6e136220497..bf214d8a000 100644
> --- a/libctf/Makefile.am
> +++ b/libctf/Makefile.am
> @@ -102,11 +102,12 @@ check-DEJAGNU: site.exp development.exp
> else \
> TEST_CROSS=yes; \
> fi; \
> + TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
> runtest=$(RUNTEST); \
> if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
> $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
> CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
> - CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
> + CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
> LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
> else echo "WARNING: could not find \`runtest'" 1>&2; :;\
> fi
> diff --git a/libctf/Makefile.in b/libctf/Makefile.in
> index 5d9587766dc..e5bb94c681b 100644
> --- a/libctf/Makefile.in
> +++ b/libctf/Makefile.in
> @@ -1819,11 +1819,12 @@ check-DEJAGNU: site.exp development.exp
> else \
> TEST_CROSS=yes; \
> fi; \
> + TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
> runtest=$(RUNTEST); \
> if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
> $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
> CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
> - CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
> + CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
> LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
> else echo "WARNING: could not find \`runtest'" 1>&2; :;\
> fi
> diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp
> index 64d2a40ad9f..6d3b75e22a2 100644
> --- a/libctf/testsuite/lib/ctf-lib.exp
> +++ b/libctf/testsuite/lib/ctf-lib.exp
> @@ -54,6 +54,16 @@ proc compile_link_one_host_cc { src output additional_args } {
> return [run_native_host_cmd "./libtool --quiet --tag=CC --mode=link $CC $CFLAGS $src -o $output $additional_args" ]
> }
>
> +# Also prune lto-wrapper warnings, like
> +# lto-wrapper: warning: using serial compilation of 16 LTRANS jobs
> +# lto-wrapper: note: see the '-flto' option documentation for more information
> +#
> +proc prune_warnings_lto { msg } {
> + set msgx "lto-wrapper: (?:warning\:\[^\n\r\]+|note\:\[^\n\r\]+)"
> + regsub -all "$msgx\[\n\r\]*" $msg {} msg
> + return [prune_warnings $msg]
> +}
> +
> # run_lookup_test FILE
> #
> # Compile with the host compiler and link a .c file into a "lookup" binary, then
> @@ -208,7 +218,7 @@ proc run_lookup_test { name } {
> set testname $file4log
>
> # Compile and link the lookup program.
> - set comp_output [prune_warnings [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
> + set comp_output [prune_warnings_lto [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
>
> if { $comp_output != ""} {
> send_log "compilation of lookup program $opts(lookup) failed with <$comp_output>"
> @@ -244,7 +254,7 @@ proc run_lookup_test { name } {
> }
> }
>
> - set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
> + set comp_output [prune_warnings_lto [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
>
> if { $comp_output != ""} {
> send_log "compilation of CTF program [concat $src] failed with <$comp_output>"
More information about the Binutils
mailing list