Fix x86 ld testsuite fails with glibc < 2.28

Alan Modra amodra@gmail.com
Wed Jun 10 05:35:45 GMT 2020


Hi HJ,
This fixes the following fails on my Ubuntu 18.04 box.
x86_64-linux  -FAIL: Run pr25749-1bb (-no-pie -fno-PIE)
x86_64-linux  -FAIL: Run pr25749-1bb (-pie -fPIE)
x86_64-linux  -FAIL: Run pr25749-2ab (-no-pie -fno-PIE)
x86_64-linux  -FAIL: Run pr25749-2ab (-pie -fPIE)

In addition, at least try to build the linux-x86 tests when
non-native.  run_cc_link_tests and run_ld_link_exec_tests won't error
if cross-compilers are unavailable, and run_ld_link_exec_tests won't
try to run binaries if non-native.

Do you have any objections to me applying the patch?

	* testsuite/ld-elf/linux-x86.exp: Don't exclude building tests
	when non-native.
	(check_pr25749b): Add optional args.  Set expected pass file
	from args.  Run -1b and -2a tests with passall.out.
	* testsuite/ld-elf/passall.out: New file.
	* testsuite/ld-elf/pr25749-1.c: Adjust to pass with older glibc.
	* testsuite/ld-elf/pr25749-2.c: Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use
	regexp_diff to compare expected output from running binary.

diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
index eeaf4590e3..aae75d443f 100644
--- a/ld/testsuite/ld-elf/linux-x86.exp
+++ b/ld/testsuite/ld-elf/linux-x86.exp
@@ -48,10 +48,6 @@ run_ld_link_tests [list \
 ]
 
 # Test very simple native Linux/x86 programs with linux-x86.S.
-if { ![isnative] || ![check_compiler_available] } {
-    return
-}
-
 run_ld_link_exec_tests [list \
     [list \
 	"Run PR ld/23428 test" \
@@ -215,7 +211,7 @@ if { [istarget "i?86-*-linux*"] } {
     }
 }
 
-proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
+proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags args} {
     global objcopy
     global srcdir
     global subdir
@@ -253,6 +249,12 @@ proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
 	    "lib${testname}.so" \
 	] \
     ]
+
+    set pass "pass.out"
+    if { [llength $args] > 0 } {
+	set pass [lindex $args 0]
+    }
+
     run_ld_link_exec_tests [list \
 	[list \
 	    "Run ${testname}b ($ldflags $cflags)" \
@@ -260,7 +262,7 @@ proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
 	    "" \
 	    [list $srcfilea]\
 	    "${testname}b" \
-	    "pass.out" \
+	    "$pass" \
 	    "$cflags -I../bfd" \
 	] \
     ]
@@ -269,13 +271,13 @@ proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
-check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
-check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
+check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
+check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "" "passall.out"
 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
-check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
-check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
+check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
+check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" "" "passall.out"
 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
diff --git a/ld/testsuite/ld-elf/passall.out b/ld/testsuite/ld-elf/passall.out
new file mode 100644
index 0000000000..beec04bc6b
--- /dev/null
+++ b/ld/testsuite/ld-elf/passall.out
@@ -0,0 +1 @@
+PASS.*
diff --git a/ld/testsuite/ld-elf/pr25749-1.c b/ld/testsuite/ld-elf/pr25749-1.c
index 5b37af08c6..12d0574a01 100644
--- a/ld/testsuite/ld-elf/pr25749-1.c
+++ b/ld/testsuite/ld-elf/pr25749-1.c
@@ -6,7 +6,13 @@ extern intptr_t size (void);
 int
 main ()
 {
-  if (size () == 147)
+  if (size () == 303 /* size of this file */)
     printf ("PASS\n");
+#ifdef __GLIBC_PREREQ
+# if !__GLIBC_PREREQ (2, 28)
+  else
+    printf ("PASS (incorrect result due to glibc bug)\n");
+# endif
+#endif
   return 0;
 }
diff --git a/ld/testsuite/ld-elf/pr25749-2.c b/ld/testsuite/ld-elf/pr25749-2.c
index 820bebc167..3ef6f0c6a7 100644
--- a/ld/testsuite/ld-elf/pr25749-2.c
+++ b/ld/testsuite/ld-elf/pr25749-2.c
@@ -6,7 +6,13 @@ extern intptr_t size;
 int
 main ()
 {
-  if (size == 137)
+  if (size == 293 /* size of this file */)
     printf ("PASS\n");
+#ifdef __GLIBC_PREREQ
+# if !__GLIBC_PREREQ (2, 28)
+  else
+    printf ("PASS (incorrect result due to glibc bug)\n");
+# endif
+#endif
   return 0;
 }
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 6535881dd1..a949437cea 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -773,14 +773,9 @@ proc run_ld_link_exec_tests { ldtests args } {
 		verbose "$exec_output" 1
 		set failed 1
 	    } else {
-		send_log "diff $binfile.out $srcdir/$subdir/$expfile\n"
-		verbose "diff $binfile.out $srcdir/$subdir/$expfile"
-		catch "exec diff $binfile.out $srcdir/$subdir/$expfile" exec_output
-		set exec_output [prune_warnings $exec_output]
-
-		if ![string match "" $exec_output] then {
-		    send_log "$exec_output\n"
-		    verbose "$exec_output" 1
+		send_log [file_contents $binfile.out]
+		verbose [file_contents $binfile.out] 2
+		if [regexp_diff "$binfile.out" "$srcdir/$subdir/$expfile"] {
 		    set failed 1
 		}
 	    }

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list