PR ld/20784
* emultempl/elf32.em (search_needed): Fix infinite loop when
unable to process a token. Add support for curly braced enclosed
tokens.
* ld.texinfo (--rpath-link): Document supprot for $ORIGIN and
$LIB.
+2016-11-07 Nick Clifton <nickc@redhat.com>
+
+ PR ld/20784
+ * emultempl/elf32.em (search_needed): Fix infinite loop when
+ unable to process a token. Add support for curly braced enclosed
+ tokens.
+ * ld.texinfo (--rpath-link): Document supprot for $ORIGIN and
+ $LIB.
+
2016-11-07 Nick Clifton <nickc@redhat.com>
* ld.texinfo (--compress-debug-sections): Expand documentation of
2016-11-07 Nick Clifton <nickc@redhat.com>
* ld.texinfo (--compress-debug-sections): Expand documentation of
len = strlen (name);
while (1)
{
len = strlen (name);
while (1)
{
char * var;
char *filename, *sset;
char * var;
char *filename, *sset;
/* PR 20535: Support the same pseudo-environment variables that
are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
Since there can be more than one occurrence of these tokens in
/* PR 20535: Support the same pseudo-environment variables that
are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
Since there can be more than one occurrence of these tokens in
- the path we loop until no more are found. */
- while ((var = strchr (filename, '$')) != NULL)
+ the path we loop until no more are found. Since we might not
+ be able to substitute some of the tokens we maintain an offset
+ into the filename for where we should begin our scan. */
+ while ((var = strchr (filename + offset, '$')) != NULL)
{
/* The ld.so manual page does not say, but I am going to assume that
these tokens are terminated by a directory seperator character
{
/* The ld.so manual page does not say, but I am going to assume that
these tokens are terminated by a directory seperator character
$ORIGIN should only be used at the start of a path, but that is
not enforced here.
$ORIGIN should only be used at the start of a path, but that is
not enforced here.
- FIXME: The ld.so manual page also states that it allows ${ORIGIN}
- ${LIB} and ${PLATFORM}. We should support these variants too.
+ The ld.so manual page also states that it allows ${ORIGIN},
+ ${LIB} and ${PLATFORM}, so these are supported as well.
FIXME: The code could be a lot cleverer about allocating space
for the processed string. */
char * end = strchr (var, '/');
char * replacement = NULL;
FIXME: The code could be a lot cleverer about allocating space
for the processed string. */
char * end = strchr (var, '/');
char * replacement = NULL;
char * freeme = NULL;
unsigned flen = strlen (filename);
char * freeme = NULL;
unsigned flen = strlen (filename);
/* Temporarily terminate the filename at the end of the token. */
* end = 0;
/* Temporarily terminate the filename at the end of the token. */
* end = 0;
+ if (*v == '{')
+ ++ v;
+ switch (*v++)
- if (strcmp (var + 2, "RIGIN") == 0)
+ if (strcmp (v, "RIGIN") == 0 || strcmp (v, "RIGIN}") == 0)
{
/* ORIGIN - replace with the full path to the directory
containing the program or shared object. */
if (needed.by == NULL)
{
/* ORIGIN - replace with the full path to the directory
containing the program or shared object. */
if (needed.by == NULL)
- break;
- replacement = bfd_get_filename (needed.by);
+ {
+ if (link_info.output_bfd == NULL)
+ {
+ break;
+ }
+ else
+ replacement = bfd_get_filename (link_info.output_bfd);
+ }
+ else
+ replacement = bfd_get_filename (needed.by);
+
if (replacement)
{
char * slash;
if (replacement)
{
char * slash;
- if (strcmp (var + 2, "IB") == 0)
+ if (strcmp (v, "IB") == 0 || strcmp (v, "IB}") == 0)
{
/* LIB - replace with "lib" in 32-bit environments
and "lib64" in 64-bit environments. */
{
/* LIB - replace with "lib" in 32-bit environments
and "lib64" in 64-bit environments. */
- if (strcmp (var + 2, "LATFORM") == 0)
- {
- /* Supporting $PLATFORM in a cross-hosted environment is not
- possible. Supporting it in a native environment involves
- loading the <sys/auxv.h> header file which loads the
- system <elf.h> header file, which conflicts with the
- "include/elf/mips.h" header file. */
- replacement = NULL;
- }
- break;
-
+ /* Supporting $PLATFORM in a cross-hosted environment is not
+ possible. Supporting it in a native environment involves
+ loading the <sys/auxv.h> header file which loads the
+ system <elf.h> header file, which conflicts with the
+ "include/elf/mips.h" header file. */
+ /* Fall through. */
char * filename2 = xmalloc (flen + strlen (replacement));
if (end)
char * filename2 = xmalloc (flen + strlen (replacement));
if (end)
- sprintf (filename2, "%.*s%s/%s",
- (int)(var - filename), filename,
- replacement, end + 1);
+ {
+ sprintf (filename2, "%.*s%s/%s",
+ (int)(var - filename), filename,
+ replacement, end + 1);
+ offset = (var - filename) + 1 + strlen (replacement);
+ }
- sprintf (filename2, "%.*s%s",
- (int)(var - filename), filename,
- replacement);
-
+ {
+ sprintf (filename2, "%.*s%s",
+ (int)(var - filename), filename,
+ replacement);
+ offset = var - filename + strlen (replacement);
+ }
+
free (filename);
filename = filename2;
/* There is no need to restore the path separator (when
free (filename);
filename = filename2;
/* There is no need to restore the path separator (when
if (end)
/* Restore the path separator. */
* end = '/';
if (end)
/* Restore the path separator. */
* end = '/';
+
+ /* PR 20784: Make sure that we resume the scan
+ *after* the token that we could not replace. */
+ offset = (var + 1) - filename;
}
free (freeme);
}
needed.name = filename;
}
free (freeme);
}
needed.name = filename;
if (gld${EMULATION_NAME}_try_needed (&needed, force))
return TRUE;
if (gld${EMULATION_NAME}_try_needed (&needed, force))
return TRUE;
either by specifying a list of names separated by colons, or by
appearing multiple times.
either by specifying a list of names separated by colons, or by
appearing multiple times.
+The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
+directories. They will be replaced by the full path to the directory
+containing the program or shared object in the case of @var{$ORIGIN}
+and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
+64-bit binaries - in the case of @var{$LIB}.
+
+The alternative form of these tokens - @var{$@{ORIGIN@}} and
+@var{$@{LIB@}} can also be used. The token @var{$PLATFORM} is not
+supported.
+
This option should be used with caution as it overrides the search path
that may have been hard compiled into a shared library. In such a case it
is possible to use unintentionally a different search path than the
This option should be used with caution as it overrides the search path
that may have been hard compiled into a shared library. In such a case it
is possible to use unintentionally a different search path than the