Discussion:
Simplify --sysroot=/
Alan Modra
2018-10-29 07:51:54 UTC
Permalink
Prepending '/' to absolute paths doesn't gain us much, and results in
the current implementation of --trace emitting silly path-in-sysroot
output, eg.
/lib/ld-linux-x86-64.so.2 (//lib/ld-linux-x86-64.so.2)

* ldmain.c (get_sysroot): Return "" for "--sysroot=/".

diff --git a/ld/ldmain.c b/ld/ldmain.c
index 464192049a..6f3ce6f810 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -584,21 +584,25 @@ static const char *
get_sysroot (int argc, char **argv)
{
int i;
- const char *path;
+ const char *path = NULL;

for (i = 1; i < argc; i++)
if (CONST_STRNEQ (argv[i], "--sysroot="))
- return argv[i] + strlen ("--sysroot=");
+ path = argv[i] + strlen ("--sysroot=");

- path = get_relative_sysroot (BINDIR);
- if (path)
- return path;
+ if (!path)
+ path = get_relative_sysroot (BINDIR);

- path = get_relative_sysroot (TOOLBINDIR);
- if (path)
- return path;
+ if (!path)
+ path = get_relative_sysroot (TOOLBINDIR);
+
+ if (!path)
+ path = TARGET_SYSTEM_ROOT;
+
+ if (IS_DIR_SEPARATOR (*path) && path[1] == 0)
+ path = "";

- return TARGET_SYSTEM_ROOT;
+ return path;
}

/* We need to find any explicitly given emulation in order to initialize the
--
Alan Modra
Australia Development Lab, IBM
Andreas Schwab
2018-10-29 09:22:03 UTC
Permalink
Post by Alan Modra
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 464192049a..6f3ce6f810 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -584,21 +584,25 @@ static const char *
get_sysroot (int argc, char **argv)
{
int i;
- const char *path;
+ const char *path = NULL;
for (i = 1; i < argc; i++)
if (CONST_STRNEQ (argv[i], "--sysroot="))
- return argv[i] + strlen ("--sysroot=");
+ path = argv[i] + strlen ("--sysroot=");
Should this break out?

Andreas.
--
Andreas Schwab, SUSE Labs, ***@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Alan Modra
2018-10-29 09:34:39 UTC
Permalink
Post by Andreas Schwab
Post by Alan Modra
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 464192049a..6f3ce6f810 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -584,21 +584,25 @@ static const char *
get_sysroot (int argc, char **argv)
{
int i;
- const char *path;
+ const char *path = NULL;
for (i = 1; i < argc; i++)
if (CONST_STRNEQ (argv[i], "--sysroot="))
- return argv[i] + strlen ("--sysroot=");
+ path = argv[i] + strlen ("--sysroot=");
Should this break out?
No, that's a bug fix. Pick the last --sysroot. I probably should
have mentioned that in the ChangeLog.
--
Alan Modra
Australia Development Lab, IBM
Loading...