ld, testsuite: improve CTF-availability test

Message ID 20211117145013.49172-1-nick.alcock@oracle.com
State New
Headers show
Series
  • ld, testsuite: improve CTF-availability test
Related show

Commit Message

H.J. Lu via Binutils Nov. 17, 2021, 2:50 p.m.
The test for -gctf support in the compiler is used to determine when to
run the ld-ctf tests and most of those in libctf.  Unfortunately,
because it uses check_compiler_available and compile_one_cc, it will
fail whenever the compiler emits anything on stderr, even if it
actually does support CTF perfectly well.

So, instead, ask the compiler to emit assembler output and grep it for
references to ".ctf": this is highly unlikely to be present if the
compiler does not support CTF.  (This will need adjusting when CTF grows
support for non-ELF platforms that don't dot-prepend their section
names, but right now the linker doesn't link CTF on any such platforms
in any case.)

With this in place we can do things like run all the libctf tests under
leak sanitizers etc even if those spray warnings on simple CTF
compilations, rather than being blocked from doing so just when we would
most like to.

ld/ChangeLog
2021-11-17  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/lib/ld-lib.exp (check_ctf_available): detect CTF
	even if a CTF-capable compiler emits warnings.
---
 ld/testsuite/lib/ld-lib.exp | 38 +++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)


-- 
2.34.0.258.gc900572c39

Patch

diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index a42e433d6d3..dae3f5fd666 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1628,24 +1628,34 @@  proc compile_one_cc { src output additional_flags } {
     return [run_host_cmd_yesno "$CC_FOR_TARGET" "$flags $CFLAGS_FOR_TARGET $additional_flags $src -o $output"]
 }
 
-# Returns true if the target compiler supports -gctf
+# Returns true if the target compiler supports -gctf.
 proc check_ctf_available { } {
     global ctf_available_saved
 
     if {![info exists ctf_available_saved]} {
-	if { ![check_compiler_available] } {
-	    set ctf_available_saved 0
-	} else {
-	    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 "-gctf -c"]
-	    remote_file host delete $src
-	    remote_file host delete $output
-	    file delete $src
+	set ctf_available_saved 0
+
+	# Don't check for compiler availability, because that FNs if the
+	# compiler is available but emits warnings.  An unavailable
+	# compiler will fail this test anyway.
+
+	set basename "tmpdir/ctf_available[pid]"
+	set src ${basename}.c
+	set output ${basename}.s
+	set f [open $src "w"]
+	puts $f "int main() { return 0; }"
+	close $f
+	compile_one_cc $src $output "-gctf -S -c"
+	remote_file host delete $src
+	if {! [remote_file host exists $output] } {
+		file delete $src
+		return 0
+	}
+	set status [remote_exec host fgrep ".ctf $output"]
+	remote_file host delete $output
+	file delete $src
+	if { [lindex $status 0] == 0 } {
+		set ctf_available_saved 1
 	}
     }
     return $ctf_available_saved