This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA:] ld run_dump_test: Handle linker asserts and inspection-program errors


For a run_dump_test test-case for PR11458, I started out with a
.d-file containing only the linker arguments and "objdump" for
an inspection program.  The linker emitted an assert and exited
with 1 (oops, that's a local patch, so let's pretend the bug
caused the linker to SEGV).  Unexpectedly, the test passed.
It did because of two bugs in run_dump_test.

The first bug is just wrong logic when testing whether to expect
a message; when ld returns an error and a message and you're
expecting success without any message,
[regexp "" "assert-message"] will yield true as does the
expression '($cmdret == 0) == ($opts(warning) != "")' causing
run_dump_test to continue down to apply any objcopy_linked_file
and/or inspection-program (nm, objdump, readelf, objcopy).

There's the second bug: the return-value of the
inspection-program isn't checked.  Objdump applied to an empty
file (after exit (1) or linker SEGV) just exits with error code
but without any output, which run_dump_test (together with the
empty .d-file in this case) interpreted as success.  A maintainer
probably won't pay attention to ld.log showing that the
inspection-program was run after ld SEGV'd/exited-with-error, as
ld.log has the essential assert- or SEGV message and anyway a
FAIL from the expected-inspection-output mismatch.  (I recall
having noticed, but also recall ignoring that as a non-essential
observation.)

Both bugs are fixed below.  I must confess I'm not completely
happy with the fancy logic that I just made a tiny bit fancier;
maybe better for readability to replace it with enumerating all
cases.  Still, we'll notice if it goes wrong, won't we?

Tested with some other patches using 'make check-ld' on native
i686-pc-linux-gnu and crosses to cris-axis-elf
cris-axis-linux-gnu arm-linux arm-elf bfin-uclinux dlx-elf
mmix-knuth-mmixware vax-linux m68k-linux mips-linux sh-elf
sh64-elf and x86_64-linux.

Ok to commit?

ld/testsuite:
	* lib/ld-lib.exp (run_dump_test): When checking linker message and
	return code, when success with no message is expected, don't
	continue if we have an abnormal and output.  Check the output of
	the inspection program and fail if it had output or an abnormal
	exit code.

Index: ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.69
diff -p -u -r1.69 ld-lib.exp
--- ld-lib.exp	19 Mar 2010 14:49:46 -0000	1.69
+++ ld-lib.exp	31 Mar 2010 00:42:28 -0000
@@ -925,8 +927,9 @@ proc run_dump_test { name } {
 	    send_log "$comp_output\n"
 	    verbose "$comp_output" 3
 
-	    if { [regexp $expmsg $comp_output] \
-		    && (($cmdret == 0) == ($opts(warning) != "")) } {
+	    if { ($expmsg == "") == ($comp_output == "") \
+		    && [regexp $expmsg $comp_output] \
+		    && (($cmdret == 0) == ($opts(error) == "")) } {
 		# We have the expected output from ld.
 		if { $opts(error) != "" || $program == "" } {
 		    pass $testname
@@ -974,6 +977,7 @@ proc run_dump_test { name } {
     set env(LC_ALL) "C"
     send_log "$cmd\n"
     set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
+    set cmdret [lindex $cmdret 0]
     remote_upload host "ld.tmp"
     set comp_output [prune_warnings [file_contents "ld.tmp"]]
     remote_file host delete "ld.tmp"
@@ -983,8 +987,8 @@ proc run_dump_test { name } {
     } else {
 	unset env(LC_ALL)
     }
-    if ![string match "" $comp_output] then {
-	send_log "$comp_output\n"
+    if { $cmdret != 0 || $comp_output != "" } {
+	send_log "exited abnormally with $cmdret, output:$comp_output\n"
 	fail $testname
 	return
     }

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]