if [ "x${USE_LIBPATH}" = xyes ] ; then
fragment <<EOF
-/* Add the sysroot to every entry in a path separated by
- config.rpath_separator. */
+/* Prefix the sysroot to absolute paths in PATH, a string containing
+ paths separated by config.rpath_separator. If running on a DOS
+ file system, paths containing a drive spec won't have the sysroot
+ prefix added, unless the sysroot also specifies the same drive. */
-static char *
+static const char *
gld${EMULATION_NAME}_add_sysroot (const char *path)
{
- int len, colons, i;
- char *ret, *p;
-
- len = strlen (path);
- colons = 0;
- i = 0;
- while (path[i])
- if (path[i++] == config.rpath_separator)
- colons++;
-
- if (path[i])
- colons++;
-
- len = len + (colons + 1) * strlen (ld_sysroot);
- ret = xmalloc (len + 1);
- strcpy (ret, ld_sysroot);
- p = ret + strlen (ret);
- i = 0;
- while (path[i])
- if (path[i] == config.rpath_separator)
- {
- *p++ = path[i++];
- strcpy (p, ld_sysroot);
- p = p + strlen (p);
- }
- else
- *p++ = path[i++];
+ size_t len, extra;
+ const char *p;
+ char *ret, *q;
+ int dos_drive_sysroot = HAS_DRIVE_SPEC (ld_sysroot);
+
+ len = strlen (ld_sysroot);
+ for (extra = 0, p = path; ; )
+ {
+ int dos_drive = HAS_DRIVE_SPEC (p);
+
+ if (dos_drive)
+ p += 2;
+ if (IS_DIR_SEPARATOR (*p)
+ && (!dos_drive
+ || (dos_drive_sysroot
+ && ld_sysroot[0] == p[-2])))
+ {
+ if (dos_drive && dos_drive_sysroot)
+ extra += len - 2;
+ else
+ extra += len;
+ }
+ p = strchr (p, config.rpath_separator);
+ if (!p)
+ break;
+ ++p;
+ }
+
+ ret = xmalloc (strlen (path) + extra + 1);
+
+ for (q = ret, p = path; ; )
+ {
+ const char *end;
+ int dos_drive = HAS_DRIVE_SPEC (p);
+
+ if (dos_drive)
+ {
+ *q++ = *p++;
+ *q++ = *p++;
+ }
+ if (IS_DIR_SEPARATOR (*p)
+ && (!dos_drive
+ || (dos_drive_sysroot
+ && ld_sysroot[0] == p[-2])))
+ {
+ if (dos_drive && dos_drive_sysroot)
+ {
+ strcpy (q, ld_sysroot + 2);
+ q += len - 2;
+ }
+ else
+ {
+ strcpy (q, ld_sysroot);
+ q += len;
+ }
+ }
+ end = strchr (p, config.rpath_separator);
+ if (end)
+ {
+ size_t n = end - p + 1;
+ strncpy (q, p, n);
+ q += n;
+ p += n;
+ }
+ else
+ {
+ strcpy (q, p);
+ break;
+ }
+ }
- *p = 0;
return ret;
}
int force)
{
static bfd_boolean initialized;
- static char *ld_elf_hints;
+ static const char *ld_elf_hints;
struct dt_needed needed;
if (!initialized)
int force)
{
static bfd_boolean initialized;
- static char *ld_so_conf;
+ static const char *ld_so_conf;
struct dt_needed needed;
if (! initialized)
if (info.path)
{
- char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
+ ld_so_conf = gld${EMULATION_NAME}_add_sysroot (info.path);
free (info.path);
- ld_so_conf = d;
}
initialized = TRUE;
}
size_t len;
search_dirs_type *search;
EOF
-if [ "x${NATIVE}" = xyes ] ; then
+if [ "x${NATIVE}" = xyes ] || [ "x${USE_LIBPATH}" = xyes ] ; then
fragment <<EOF
- const char *lib_path;
+ const char *path;
EOF
fi
if [ "x${USE_LIBPATH}" = xyes ] ; then
EOF
if [ "x${USE_LIBPATH}" = xyes ] ; then
fragment <<EOF
- if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
- &n, force))
- break;
+ path = command_line.rpath;
+ if (path)
+ {
+ found = gld${EMULATION_NAME}_search_needed (path, &n, force);
+ if (found)
+ break;
+ }
EOF
fi
if [ "x${NATIVE}" = xyes ] ; then
if (command_line.rpath_link == NULL
&& command_line.rpath == NULL)
{
- lib_path = (const char *) getenv ("LD_RUN_PATH");
- if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
- force))
+ path = (const char *) getenv ("LD_RUN_PATH");
+ if (path
+ && gld${EMULATION_NAME}_search_needed (path, &n, force))
break;
}
- lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
- if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
+ path = (const char *) getenv ("LD_LIBRARY_PATH");
+ if (path
+ && gld${EMULATION_NAME}_search_needed (path, &n, force))
break;
EOF
fi
rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
for (; !found && rp != NULL; rp = rp->next)
{
- const char *tmpname = rp->name;
-
- if (IS_ABSOLUTE_PATH (tmpname))
- tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname);
+ path = gld${EMULATION_NAME}_add_sysroot (rp->name);
found = (rp->by == l->by
- && gld${EMULATION_NAME}_search_needed (tmpname,
- &n,
+ && gld${EMULATION_NAME}_search_needed (path, &n,
force));
- if (tmpname != rp->name)
- free ((char *) tmpname);
+ free ((char *) path);
}
if (found)
break;