[58/59] ld, testsuite: only run CTF tests when ld and GCC support CTF

Message ID 20200630233146.338613-59-nick.alcock@oracle.com
State New
Headers show
Series
  • Deduplicating CTF linker
Related show

Commit Message

H.J. Lu via Binutils June 30, 2020, 11:31 p.m.
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/Makefile.am              |  7 +++--
 ld/Makefile.in              |  8 ++++--
 ld/configure                |  6 +++--
 ld/configure.ac             |  1 +
 ld/testsuite/ld-ctf/ctf.exp |  5 ++++
 ld/testsuite/lib/ld-lib.exp | 52 +++++++++++++++++++++++++++++++++++++
 6 files changed, 73 insertions(+), 6 deletions(-)

-- 
2.27.0.247.g3dff7de930

Comments

H.J. Lu via Binutils July 22, 2020, 9:32 a.m. | #1
Require ELF support for diags tests, too.  (This is possibly not
restrictive enough.)
---
 ld/testsuite/ld-ctf/ctf.exp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
index 3e44de7aaab..5d177afef0d 100644
--- a/ld/testsuite/ld-ctf/ctf.exp
+++ b/ld/testsuite/ld-ctf/ctf.exp
@@ -26,6 +26,11 @@ if [skip_ctf_tests] {
 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" } }
 }
-- 
2.27.0.247.g3dff7de930

Patch

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 02c4fc16395..bf19f98f1f9 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -978,6 +978,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.
@@ -1024,7 +1027,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
@@ -1071,7 +1074,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
 
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 2fe12e14f63..27350415b30 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -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@
@@ -1019,7 +1020,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
 
@@ -1030,7 +1031,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
 
@@ -2555,6 +2556,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.
diff --git a/ld/configure b/ld/configure
index 11c69bec7b9..9ff13c3c72b 100755
--- a/ld/configure
+++ b/ld/configure
@@ -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
 
diff --git a/ld/configure.ac b/ld/configure.ac
index 5a4938afdb0..5ef25e3eb88 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -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
 
diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
index 9a248f90ec4..3e44de7aaab 100644
--- a/ld/testsuite/ld-ctf/ctf.exp
+++ b/ld/testsuite/ld-ctf/ctf.exp
@@ -18,6 +18,11 @@ 
 # 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 {
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 8d851a94b71..8d476ca48f3 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -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
+}