https://gcc.gnu.org/g:76a851318dd54b9e6a26be157733d98fdac2a63a

commit r17-6335-g76a851318dd54b9e6a26be157733d98fdac2a63a
Author: Hans-Peter Nilsson <[email protected]>
Date:   Mon Oct 19 03:55:19 2026 +0000

    testsuite: Avoid throwing error in scan-symbol-common
    
    Commit r17-5210-g3d0eda79500695 introduced a test-case wherein
    scan-symbol is applied on a (no-fat) LTO object file.  That requires a
    plugin (commonly liblto_plugin.so).
    
    It used to be that for some reason, that plugin was not found for some
    setups, likely including all cross builds.  Unfortunately, that causes
    a Tcl error to be thrown.  This must not happen, because we can't tell
    that from an error in an .exp file or an error in test-case dejagnu
    markup.  With r17-5796-gcfb45bb1e58aed, the not-finding-plugin bug was
    fixed, and the issue this patch handles went back to being dormant.
    In other words, for the affected cross-targets, we no longer see
    error messages like:
    
    Running /gccsrc/gcc/testsuite/gcc.dg/dg.exp ...
    ERROR: gcc.dg/builtin-pi-linkage.c: error executing dg-final:\
     /pre/cris-elf/bin/nm: builtin-pi-linkage.o: plugin needed to handle lto 
object
    
    But, without this patch, "close" can still throw an error if the tool
    exits with an error, alternatively writes a message to stderr (cf. Tcl
    documentation for exec as referenced by open), regardless of exit
    value.  The problem with throwing an error is that if there is no-one
    "catching" it at the per-test-case call side of the loop, the
    exception will abort part of the test-suite run, breaking
    testsuite-result integrity.
    
    For this reason, it is recommended to grep the toplevel output for
    "^ERROR:" to catch such problems when editing test-cases.  Note that
    in the situation inspiring this patch, the "$nm_cmd failed" message
    indeed was not output, because the command exited with a 0 status.
    The exception happened because the message was written to stderr.
    
    For the instance demonstrated here, expect catches the error but
    aborts the test-case (the other scan-symbol tests in the test-case)
    and also ERROR: is emitted.  Observe by replacing gcc-nm with a script
    that does "exit 1" or exit 0 with output to stderr.
    
    Rather than wrapping the call to close in "catch", or use the switch
    -ignorestderr when calling open, use remote_exec as elsewhere in the
    testsuite library, when reading the output of binutils programs.
    
    By not throwing an exception, there's now a new execution path, where
    scan-symbol-not calling scan-symbol-common will now yield "pass" when
    $nm_cmd fails, but which I consider to be a pre-existing flaw and to
    be handled in a future commit.  There are also theoretically
    pre-existing early exits that return without a return-value,
    considered out of scope for this patch.
    
    gcc/testsuite:
    
            * lib/gcc-dg.exp (scan-symbol-common): To catch the output of nm,
            use remote_exec host, not open/read/close.

Diff:
---
 gcc/testsuite/lib/gcc-dg.exp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index bdd74d132c13..6f8068586d1f 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -1430,9 +1430,13 @@ proc scan-symbol-common { scan_directive args } {
        return
     }
 
-    set fd [open "| $nm_cmd $output_file" r]
-    set text [read $fd]
-    close $fd
+    set output [remote_exec host "$nm_cmd" "$output_file"]
+    set status [lindex $output 0]
+    if { $status != 0 } {
+       verbose -log "$scan_directive $args: $nm_cmd failed"
+       return 0
+    }
+    set text [lindex $output 1]
 
     if [regexp -- [lindex $args 0] $text] {
        return 1

Reply via email to