[RFA] Fix sysroot-tests, adding --print-sysroot

Hans-Peter Nilsson hans-peter.nilsson@axis.com
Fri Oct 17 04:19:00 GMT 2014


Two bugs.  Wait: three bugs.  Maybe four...

1a: Incidentally noticed: --with-sysroot= is handled as a
sysroot-less configuration.  This means you can't pass --sysroot
to ld.  IMHO that should *maybe* be handled as a sysroot-less
configuration but otherwise effectively as --with-sysroot=/
i.e. you should be able to pass --sysroot to the linker.
1b: Note that --with-sysroot=/ makes absolute paths passed to
the system have a / prepended, like //usr/lib.  Note sure
whether that's entirely benevolent everywhere...
Pre-existing: I won't fix any of that.


2: Some sysroot tests fail on systems configured with --with-sysroot=/:
Running /home/hp/binutils/src/ld/testsuite/ld-scripts/sysroot-prefix.exp...
FAIL: sysroot-prefix common full-path =-prefixed without, quoted
FAIL: sysroot-prefix common full-path =-prefixed without, unquoted

Supposedly this is a useful configuration in native
environments.  Oops...  Looks like I have to find the configured
sysroot and handle that case separately.  (No, removing the
failing tests is just cheating!)  I simply didn't find any
existing way to do that and so though the most useful and
straightforward solution was to implement --print-sysroot and
make it behave exactly as the same gcc option.  (Though gcc
doesn't exit early, it doesn't require additional options
complaining about missing input files etc.)


3: When passing --enable-targets=all --enable-64-bit-bfd (the
latter not required for a "64-bit-host" of course) the ld --help
output got too much to handle for poor tcl (or maybe dejagnu is
to blame) and remote_exec exited with an error, so the
configuration being tested was mishandled as being a
sysroot-less configuration.  Using --version instead of --help
would work too, but the new --print-sysroot option calls for
nominal coverage, so why not use that instead.

Now, the patchset below is hopefully considered pretty simple
and an obvious way forward, but what to do with the 2.25 branch
is a matter of policy.  Some options:

1. Apply the same patch there too, no worries.  (preferable IMHO)
2. Leave it.  People configuring with --enable-targets=all and
--enable-64-bit-bfd will just have to not run the test-suite.
3. Remove the two tests left out of the --with-sysroot=/ tests
and use ld --sysroot=ldxyzzy --version instead of
--sysroot=ldxyzzy --help in check_sysroot_available as some kind
of obvious minimal change.
4. Remove the sysroot tests.

Either way, or another.

ld:
	Implement --print-sysroot in ld.
	* ldlex.h (enum option_values): Add entry OPTION_PRINT_SYSROOT.
	* lexsup.c (ld_options): Add entry for --print-sysroot.
	(parse_args) <OPTION_PRINT_SYSROOT>: Print sysroot and exit early.

ld/testsuite:

	* ld-scripts/sysroot-prefix.exp: Log $ld_sysroot.  Handle sysroot
	== "/" as a separate sysroot-configuration with separable
	test-types.
	(sysroot_prefix_tests): Include all existing sysroot tests in
	sysroot == "/" tests except exclude those where a --sysroot option
	is not specified.
	* lib/ld-lib.exp (check_sysroot_available): Rewrite to use
	--print-sysroot instead of relying on error code from using
	--sysroot=...  Also, set $ld_sysroot.

Ok to commit this to master?
To the 2.25 branch?

diff --git a/ld/ldlex.h b/ld/ldlex.h
index 56cd121..e3e9b24 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -136,6 +136,7 @@ enum option_values
 #endif /* ENABLE_PLUGINS */
   OPTION_DEFAULT_SCRIPT,
   OPTION_PRINT_OUTPUT_FORMAT,
+  OPTION_PRINT_SYSROOT,
   OPTION_IGNORE_UNRESOLVED_SYMBOL,
   OPTION_PUSH_STATE,
   OPTION_POP_STATE,
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 3a1ea9e..4812c97 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -379,6 +379,8 @@ static const struct ld_option ld_options[] =
     EXACTLY_TWO_DASHES },
   { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
     '\0', NULL, N_("Print default output format"), TWO_DASHES },
+  { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
+    '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
   { {"qmagic", no_argument, NULL, OPTION_IGNORE},
     '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
   { {"reduce-memory-overheads", no_argument, NULL,
@@ -960,6 +962,11 @@ parse_args (unsigned argc, char **argv)
 	case OPTION_OFORMAT:
 	  lang_add_output_format (optarg, NULL, NULL, 0);
 	  break;
+	case OPTION_PRINT_SYSROOT:
+	  if (*ld_sysroot)
+	    puts (ld_sysroot);
+	  xexit (0);
+	  break;
 	case OPTION_PRINT_OUTPUT_FORMAT:
 	  command_line.print_output_format = TRUE;
 	  break;

diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index ffdf805..7d2df22 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -1669,16 +1669,14 @@ proc check_plugin_api_available { } {
     return $plugin_api_available_saved
 }
 
-# Returns true if the target ld supports sysroot.
+# Sets ld_sysroot to the current sysroot (empty if not supported) and
+# returns true if the target ld supports sysroot.
 proc check_sysroot_available { } {
-    global ld_sysroot_available_saved
-    global ld
+    global ld_sysroot_available_saved ld ld_sysroot
     if {![info exists ld_sysroot_available_saved]} {
-	# Check if ld supports --sysroot *other* than empty
-	# (non-sysroot linkers don't emit errors for --sysroot="").
-	# The help-text by itself is no indication as it always lists --sysroot.
-	set status [remote_exec host $ld "--sysroot=ldxyzzy --help >/dev/null"]
-	if { [lindex $status 0] != 0 } {
+	# Check if ld supports --sysroot *other* than empty.
+	set ld_sysroot [string trimright [lindex [remote_exec host $ld "--print-sysroot"] 1]]
+	if { $ld_sysroot == "" } {
 	    set ld_sysroot_available_saved 0
 	} else {
 	    set ld_sysroot_available_saved 1

diff --git a/ld/testsuite/ld-scripts/sysroot-prefix.exp b/ld/testsuite/ld-scripts/sysroot-prefix.exp
index cf434df..65c9f70 100644
--- a/ld/testsuite/ld-scripts/sysroot-prefix.exp
+++ b/ld/testsuite/ld-scripts/sysroot-prefix.exp
@@ -27,14 +27,21 @@
 # present or not, with different arguments.
 
 # Find out if the linker supports sysroot; if it was configured
-# "--with-sysroot X".  We ignore that X can actually be set to
-# interfere with the tests, as that's unlikely to be useful, and
-# assume that the build-directory (aka. $base_dir) does not contain X.
+# "--with-sysroot X" where X is a non-empty string.
 set with_sysroot [check_sysroot_available]
-verbose -log "Has (non-empty) sysroot support: $with_sysroot"
+verbose -log "Has (non-empty) sysroot support: $with_sysroot; \"$ld_sysroot\""
+
+# We also need to know if the sysroot is "/" (a common use) as some of
+# the tests prepend sysroot to the current directory and on most
+# common systems "//dir/path" is handled as "/dir/path".
+if {$ld_sysroot == "/"} {
+    # Use a modified test-subset for testing.
+    set with_sysroot 3
+}
 
 # Entries in the array-tables:
-# 0: Testtype (1: only non-sysroot, 2: only sysroot, 3: either).
+# 0: Testtype; an inclusive bitmask indicating that the test should run on a
+# build configured for: 1: non-sysroot, 2: sysroot != "/", 4: sysroot == "/".
 # 1: Description, forming part of the dejagnu test-name.
 # 2: Replacement for @p@.
 # 3: Option to pass to linker (usually something with --sysroot).
@@ -47,16 +54,16 @@ verbose -log "Has (non-empty) sysroot support: $with_sysroot"
 # description contains @cwd@, that will be replaced by "<CWD>".
 
 set sysroot_prefix_tests {
-    {3 "plain -Lpath" "sysroot/" {} ""}
-    {3 "root-anchored but -Lpath" "/sysroot/" {} "cannot find"}
-    {3 "full-path" "@cwd@/sysroot/" {} ""}
-    {3 "root-anchored =-prefixed -Lpath" "=/sysroot/" {} "cannot find"}
-    {3 "full-path =-prefixed with empty" "=@cwd@/sysroot/" "--sysroot=" ""}
-    {3 "plain =-prefixed with empty" "=sysroot/" "--sysroot=" ""}
-    {2 "root-anchored but script outside sysroot" "/" "--sysroot=@cwd@/sysroot" "cannot find"}
-    {2 "root-anchored and script inside sysroot" "/sysroot/" "--sysroot=@cwd@" ""}
-    {2 "root-anchored =-prefixed script outside" "=/" "--sysroot=@cwd@/sysroot" ""}
-    {2 "root-anchored =-prefixed script inside" "=/sysroot/" "--sysroot=@cwd@" ""}
+    {7 "plain -Lpath" "sysroot/" {} ""}
+    {7 "root-anchored but -Lpath" "/sysroot/" {} "cannot find"}
+    {7 "full-path" "@cwd@/sysroot/" {} ""}
+    {7 "root-anchored =-prefixed -Lpath" "=/sysroot/" {} "cannot find"}
+    {7 "full-path =-prefixed with empty" "=@cwd@/sysroot/" "--sysroot=" ""}
+    {7 "plain =-prefixed with empty" "=sysroot/" "--sysroot=" ""}
+    {6 "root-anchored but script outside sysroot" "/" "--sysroot=@cwd@/sysroot" "cannot find"}
+    {6 "root-anchored and script inside sysroot" "/sysroot/" "--sysroot=@cwd@" ""}
+    {6 "root-anchored =-prefixed script outside" "=/" "--sysroot=@cwd@/sysroot" ""}
+    {6 "root-anchored =-prefixed script inside" "=/sysroot/" "--sysroot=@cwd@" ""}
     {2 "plain =-prefixed without but -Lpath" "=sysroot/" {} "cannot find"}
     {2 "full-path =-prefixed without" "=@cwd@/sysroot/" {} "cannot find"}
     {1 "plain =-prefixed -Lpath" "=sysroot/" {} ""}

brgds, H-P



More information about the Binutils mailing list