This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[5/8] Make collect2 honour --sysroot
- From: Richard Sandiford <richards at transitive dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 02 Jun 2009 13:20:55 +0100
- Subject: [5/8] Make collect2 honour --sysroot
- References: <g44ouyhmgm.fsf@richards-desktop.transitives.com>
This patch adds --sysroot support to collect2. Specifically, it makes
sure that ignore_library strips the sysroot directory from the start
of a library path before comparing it against aix_std_libs.
I haven't tried to cope with cases where there are two "/"s after
the sysroot path, or where the sysroot path ends in more "/"s than
the paths themselves. These situations would not occur in the
automatically-generated paths we care about, and I think allowing
slash variations is conceptually a separate change. (Slash variations
would also allow native toolchains to treat "///unix" as "/unix",
for example.)
Tested on powerpc-ibm-aix6.1 and x86_64-linux-gnu. OK to install?
Richard
gcc/
* collect2.c (target_system_root): New variable.
(main): Handle --sysroot=.
(ignore_library): Strip the sysroot from the library path.
Index: gcc/collect2.c
===================================================================
--- gcc/collect2.c 2009-06-02 13:06:05.000000000 +0100
+++ gcc/collect2.c 2009-06-02 13:06:07.000000000 +0100
@@ -217,6 +217,14 @@ static const char *ldd_file_name; /* pat
struct obstack temporary_obstack;
char * temporary_firstobj;
+/* A string that must be prepended to a target OS path in order to find
+ it on the host system. */
+#ifdef TARGET_SYSTEM_ROOT
+static const char *target_system_root = TARGET_SYSTEM_ROOT;
+#else
+static const char *target_system_root = "";
+#endif
+
/* Structure to hold all the directories in which to search for files to
execute. */
@@ -1220,6 +1228,8 @@ main (int argc, char **argv)
ld1--;
ld2--;
}
+ else if (strncmp (arg, "--sysroot=", 10) == 0)
+ target_system_root = arg + 10;
break;
}
}
@@ -2449,6 +2459,15 @@ static int ignore_library (const char *)
ignore_library (const char *name)
{
const char *const *p = &aix_std_libs[0];
+ size_t length;
+
+ if (target_system_root[0] != '\0')
+ {
+ length = strlen (target_system_root);
+ if (strncmp (name, target_system_root, length) != 0)
+ return 0;
+ name += length;
+ }
while (*p)
if (! strcmp (name, *p++))
return 1;