A patch for bug in rpath/rpath-link
H . J . Lu
hjl@lucon.org
Mon Apr 30 22:04:00 GMT 2001
The problem with -rpath is when you pass -rpath,./ to ld, the linker
records set
Version References:
required from .//lib-a.so:
^^^^^^^
0x0d696910 0x00 03 GLIBC_2.0
in the binary. It won't match the runtime linker which loads
./lib-a.so. As the result, we get a core dump. Here is a patch. I am
also enclosing a testcase here.
H.J.
----
2001-04-30 H.J. Lu <hjl@gnu.org>
* lexsup.c (strip_slash): New. A function to strip slash from
rpath.
(parse_args): Call strip_slash () for OPTION_RPATH and
OPTION_RPATH_LINK.
Index: lexsup.c
===================================================================
RCS file: /work/cvs/gnu/binutils/ld/lexsup.c,v
retrieving revision 1.29
diff -u -p -r1.29 lexsup.c
--- lexsup.c 2001/04/13 18:47:36 1.29
+++ lexsup.c 2001/05/01 04:55:47
@@ -61,6 +61,7 @@ static int is_num PARAMS ((const char *,
static void set_default_dirlist PARAMS ((char *dirlist_ptr));
static void set_section_start PARAMS ((char *sect, char *valstr));
static void help PARAMS ((void));
+static char *strip_slash PARAMS ((char *));
/* Non-zero if we are processing a --defsym from the command line. */
int parsing_defsym = 0;
@@ -435,6 +436,64 @@ is_num (string, min, max, err)
return result;
}
+static char *
+strip_slash (path)
+ char *path;
+{
+ char *s, *t;
+ boolean found;
+ size_t len = strlen (slash);
+
+ t = path;
+ s = t;
+ found = (strncmp (s, slash, len) == 0);
+ if (found)
+ {
+ t += len;
+ s += len;
+ }
+ else
+ {
+ t++;
+ s++;
+ }
+ while (*s)
+ {
+ if (strncmp (s, slash, len) == 0)
+ {
+ if (found)
+ {
+ s += len;
+ break;
+ }
+ found = true;
+ }
+ else
+ found = false;
+ if (found)
+ {
+ memmove (t, s, len);
+ t += len;
+ s += len;
+ }
+ else
+ {
+ *t = *s;
+ t++;
+ s++;
+ }
+ }
+
+ while ((t - len) > path && strncmp (t - len, slash, len) == 0)
+ {
+ t -= len;
+ *t = '\0';
+ }
+ *t = '\0';
+
+ return path;
+}
+
void
parse_args (argc, argv)
unsigned argc;
@@ -818,11 +877,12 @@ parse_args (argc, argv)
/* Fall through. */
case OPTION_RPATH:
if (command_line.rpath == NULL)
- command_line.rpath = buystring (optarg);
+ command_line.rpath = strip_slash (buystring (optarg));
else
{
+ char *rpath = strip_slash (buystring (optarg));
size_t rpath_len = strlen (command_line.rpath);
- size_t optarg_len = strlen (optarg);
+ size_t optarg_len = strlen (rpath);
char *buf;
char *cp = command_line.rpath;
@@ -830,9 +890,9 @@ parse_args (argc, argv)
do
{
size_t idx = 0;
- while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
+ while (rpath[idx] != '\0' && rpath[idx] == cp[idx])
++idx;
- if (optarg[idx] == '\0'
+ if (rpath[idx] == '\0'
&& (cp[idx] == '\0' || cp[idx] == ':'))
/* We found it. */
break;
@@ -847,24 +907,27 @@ parse_args (argc, argv)
if (cp == NULL)
{
buf = xmalloc (rpath_len + optarg_len + 2);
- sprintf (buf, "%s:%s", command_line.rpath, optarg);
+ sprintf (buf, "%s:%s", command_line.rpath, rpath);
free (command_line.rpath);
+ free (rpath);
command_line.rpath = buf;
}
}
break;
case OPTION_RPATH_LINK:
if (command_line.rpath_link == NULL)
- command_line.rpath_link = buystring (optarg);
+ command_line.rpath_link = strip_slash (buystring (optarg));
else
{
+ char *rpath = strip_slash (buystring (optarg));
char *buf;
buf = xmalloc (strlen (command_line.rpath_link)
- + strlen (optarg)
+ + strlen (rpath)
+ 2);
- sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
+ sprintf (buf, "%s:%s", command_line.rpath_link, rpath);
free (command_line.rpath_link);
+ free (rpath);
command_line.rpath_link = buf;
}
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: needed.3.tar.gz
Type: application/x-gzip
Size: 605 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20010430/df2eca45/attachment.bin>
More information about the Libc-alpha
mailing list