ld, testsuite: only run CTF tests when ld and GCC support CTF
authorNick Alcock <nick.alcock@oracle.com>
Thu, 11 Jun 2020 14:44:48 +0000 (15:44 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 17:05:32 +0000 (18:05 +0100)
The CTF testsuite runs GCC to generate CTF that it knows matches the
input .c files before doing a run_dump_test over it.  So we need a GCC
capable of doing that, and we need to always avoid running those tests
if libctf was disabled because the linker will never be capable of it.

ld/
* configure.ac (enable_libctf): Substitute it.
* Makefile.am (enablings.exp): New.
(EXTRA_DEJAGNU_SITE_CONFIG): Add it.
(DISTCLEANFILES): Likewise.
* Makefile.in: Regenerate.
* configure: Likewise.
* testsuite/lib/ld-lib.exp (compile_one_cc): New.
(check_ctf_available): Likewise.
(skip_ctf_tests): Likewise.
* testsuite/ld-ctf/ctf.exp: Call skip_ctf_tests.

ld/ChangeLog
ld/Makefile.am
ld/Makefile.in
ld/configure
ld/configure.ac
ld/testsuite/ld-ctf/ctf.exp
ld/testsuite/lib/ld-lib.exp

index 0d30533350482ad1def65d56e89bd16e7ca4c6af..bd0c6ccd688693c68d7d6e450bdc8d90f9b057d8 100644 (file)
@@ -1,3 +1,16 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * configure.ac (enable_libctf): Substitute it.
+       * Makefile.am (enablings.exp): New.
+       (EXTRA_DEJAGNU_SITE_CONFIG): Add it.
+       (DISTCLEANFILES): Likewise.
+       * Makefile.in: Regenerate.
+       * configure: Likewise.
+       * testsuite/lib/ld-lib.exp (compile_one_cc): New.
+       (check_ctf_available): Likewise.
+       (skip_ctf_tests): Likewise.
+       * testsuite/ld-ctf/ctf.exp: Call skip_ctf_tests.
+
 2020-07-22  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>
 
        * testsuite/ld-ctf/ctf.exp: New file.
index 38ff2d9bc0a98554bdfe2488e0e8868394757b26..168f65dfe773135ad804e61c39326bcd74ead551 100644 (file)
@@ -974,6 +974,9 @@ check-DEJAGNU: site.exp
 development.exp: $(BFDDIR)/development.sh
        $(EGREP) "[development|experimental]=" $(BFDDIR)/development.sh  \
          | $(AWK) -F= '{ print "set " $$1 " " $$2 }' > $@
+
+enablings.exp:
+       echo "set enable_libctf ${enable_libctf}" >> $@
 #
 #
 # Build a dummy plugin using libtool.
@@ -1020,7 +1023,7 @@ MAINTAINERCLEANFILES = configdoc.texi ld.1
 CONFIG_STATUS_DEPENDENCIES = $(srcdir)/configure.host $(srcdir)/configure.tgt \
        $(BFDDIR)/development.sh
 
-EXTRA_DEJAGNU_SITE_CONFIG = development.exp
+EXTRA_DEJAGNU_SITE_CONFIG = development.exp enablings.exp
 
 MOSTLYCLEANFILES = $(STAGESTUFF) ld1$(EXEEXT) ld2$(EXEEXT) ld3$(EXEEXT) \
        ldemul-list.h crtbegin.@OBJEXT@ crtend.@OBJEXT@ ld.log ld.sum
@@ -1067,7 +1070,7 @@ diststuff: info $(EXTRA_DIST)
 # ld.1 to support parallel build.
 info-recursive: ld.1
 
-DISTCLEANFILES = site.exp development.exp site.bak stringify.sed
+DISTCLEANFILES = site.exp development.exp enablings.exp site.bak stringify.sed
 distclean-local:
        rm -rf ldscripts
 
index aaf322ddf38fa698028df6df1c5dfc458a57091e..0c4dff3615d5a9247858e7f6b48dc2abb58c88a9 100644 (file)
@@ -492,6 +492,7 @@ elf_list_options = @elf_list_options@
 elf_plt_unwind_list_options = @elf_plt_unwind_list_options@
 elf_shlib_list_options = @elf_shlib_list_options@
 enable_initfini_array = @enable_initfini_array@
+enable_libctf = @enable_libctf@
 exec_prefix = @exec_prefix@
 host = @host@
 host_alias = @host_alias@
@@ -1017,7 +1018,7 @@ MAINTAINERCLEANFILES = configdoc.texi ld.1 ld.info
 CONFIG_STATUS_DEPENDENCIES = $(srcdir)/configure.host $(srcdir)/configure.tgt \
        $(BFDDIR)/development.sh
 
-EXTRA_DEJAGNU_SITE_CONFIG = development.exp
+EXTRA_DEJAGNU_SITE_CONFIG = development.exp enablings.exp
 MOSTLYCLEANFILES = $(STAGESTUFF) ld1$(EXEEXT) ld2$(EXEEXT) ld3$(EXEEXT) \
        ldemul-list.h crtbegin.@OBJEXT@ crtend.@OBJEXT@ ld.log ld.sum
 
@@ -1028,7 +1029,7 @@ CLEANFILES = dep.sed DEP DEPA DEP1 DEP2 spu_ovl.s spu_ovl.@OBJEXT@ spu_icache.s
 EXTRA_DIST = ldgram.c ldgram.h ldlex.c emultempl/spu_ovl.@OBJEXT@_c \
             emultempl/spu_icache.@OBJEXT@_c deffilep.c deffilep.h $(man_MANS)
 
-DISTCLEANFILES = site.exp development.exp site.bak stringify.sed
+DISTCLEANFILES = site.exp development.exp enablings.exp site.bak stringify.sed
 all: $(BUILT_SOURCES) config.h
        $(MAKE) $(AM_MAKEFLAGS) all-recursive
 
@@ -2549,6 +2550,9 @@ development.exp: $(BFDDIR)/development.sh
        $(EGREP) "[development|experimental]=" $(BFDDIR)/development.sh  \
          | $(AWK) -F= '{ print "set " $$1 " " $$2 }' > $@
 
+enablings.exp:
+       echo "set enable_libctf ${enable_libctf}" >> $@
+
 # DOCUMENTATION TARGETS
 # Manual configuration file; not usually attached to normal configuration,
 # because almost all configs use "gen" version of manual.
index 8e6dcb76d07b5ef812f4a9f0614a3267b6069159..b63bc88bdfc954d1ff84962920b7df1748116a80 100755 (executable)
@@ -678,6 +678,7 @@ WARN_WRITE_STRINGS
 NO_WERROR
 WARN_CFLAGS_FOR_BUILD
 WARN_CFLAGS
+enable_libctf
 ENABLE_LIBCTF_FALSE
 ENABLE_LIBCTF_TRUE
 installed_linker
@@ -12037,7 +12038,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12040 "configure"
+#line 12041 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12143,7 +12144,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12146 "configure"
+#line 12147 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15958,6 +15959,7 @@ fi
 
 
 
+
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
 
index 5a4938afdb0ec6f48a947cdcc51d41efb78f5143..5ef25e3eb88aba0e55e6cbb60c9789f031063e19 100644 (file)
@@ -226,6 +226,7 @@ if test "${enable_libctf}" = yes; then
     AC_DEFINE(ENABLE_LIBCTF, 1, [Handle .ctf type-info sections])
 fi
 AM_CONDITIONAL(ENABLE_LIBCTF, test "${enable_libctf}" = yes)
+AC_SUBST(enable_libctf)
 
 AM_BINUTILS_WARNINGS
 
index 9a248f90ec49e93c42cff42bf4c6d64d012b56f4..5d177afef0d128daaf06a8da92cd33e6fd93e633 100644 (file)
 # MA 02110-1301, USA.
 #
 
+if [skip_ctf_tests] {
+    unsupported "no CTF format support in the compiler, or CTF disabled"
+    return 0
+}
+
 set ctf_test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
 
 foreach ctf_test $ctf_test_list {
+    if [string equal -length [string length "diag-"] "diag-" [file tail $ctf_test]] {
+       if ![is_elf_format] {
+           continue
+       }
+    }
     verbose [file rootname $ctf_test]
     run_dump_test [file rootname $ctf_test] { { cc "-gt -fPIC" } }
 }
index 69519af25d0db49895d807d7a5cf6c9ae256081f..d1ffab7dc46c904c70c09f2945c83931614df16e 100644 (file)
@@ -1569,3 +1569,55 @@ proc check_gnu2_tls_available { } {
     }
     return $gnu2_tls_available_saved
 }
+
+# Compile a C source file, with the specified additional_flags.
+proc compile_one_cc { src output additional_flags } {
+    global CC
+    global CFLAGS
+
+    set flags ""
+    if [board_info [target_info name] exists cflags] {
+       append flags " [board_info [target_info name] cflags]"
+    }
+    if [board_info [target_info name] exists ldflags] {
+       append flags " [board_info [target_info name] ldflags]"
+    }
+
+    if [is_remote host] {
+       set src [remote_download host $src]
+    }
+    return [run_host_cmd_yesno "$CC" "$flags $CFLAGS $additional_flags $src -o $output"]
+}
+
+# Returns true if the target compiler supports -gt
+proc check_ctf_available { } {
+    global ctf_available_saved
+
+    if {![info exists ctf_available_saved]} {
+       set basename "tmpdir/ctf_available[pid]"
+       set src ${basename}.c
+       set output ${basename}.o
+       set f [open $src "w"]
+       puts $f "int main() { return 0; }"
+       close $f
+       set ctf_available_saved [compile_one_cc $src $output "-gt -c"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+    }
+    return $ctf_available_saved
+}
+
+proc skip_ctf_tests { } {
+    global enable_libctf
+
+    if {$enable_libctf eq "no"} {
+       return 1
+    }
+
+    if [check_ctf_available] {
+       return 0
+    }
+
+    return 1
+}