public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H . J . Lu" <hjl@lucon.org>
To: binutils@sourceware.cygnus.com
Cc: GNU C Library <libc-alpha@sourceware.cygnus.com>
Subject: Re: A patch for bug in rpath/rpath-link
Date: Tue, 01 May 2001 09:30:00 -0000	[thread overview]
Message-ID: <20010501093047.A30306@lucon.org> (raw)
In-Reply-To: <20010430220432.A20097@lucon.org>

On Mon, Apr 30, 2001 at 10:04:32PM -0700, H . J . Lu wrote:
> 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.
> 
> 

Well, my patch is incorrect. Here is the new one. The problem is we
should only put the soname in the required file for version references.
This patch should the right thing. I cannot believe we haven't been
bitten by this bug :-(. I also changed elf32.em to use basename. Any
comments?


Thanks.


H.J.
----
Index: bfd/elfcode.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elfcode.h,v
retrieving revision 1.1.1.14
diff -u -p -r1.1.1.14 elfcode.h
--- bfd/elfcode.h	2001/03/09 19:15:58	1.1.1.14
+++ bfd/elfcode.h	2001/05/01 16:21:51
@@ -66,6 +66,7 @@ Foundation, Inc., 59 Temple Place - Suit
 
 #include "bfd.h"
 #include "sysdep.h"
+#include "libiberty.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
Index: bfd/elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.57
diff -u -p -r1.57 elflink.h
--- bfd/elflink.h	2001/04/27 21:05:00	1.57
+++ bfd/elflink.h	2001/05/01 16:21:52
@@ -1334,7 +1334,7 @@ elf_link_add_object_symbols (abfd, info)
       /* Save the SONAME, if there is one, because sometimes the
          linker emulation code will need to know it.  */
       if (*name == '\0')
-	name = bfd_get_filename (abfd);
+	name = basename (bfd_get_filename (abfd));
       elf_dt_name (abfd) = name;
     }
 
@@ -3329,7 +3329,8 @@ NAME(bfd_elf,size_dynamic_sections) (out
 					     true, false);
 		else
 		  indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
-					     t->vn_bfd->filename, true, false);
+					     basename (t->vn_bfd->filename),
+					     true, false);
 		if (indx == (bfd_size_type) -1)
 		  return false;
 		t->vn_file = indx;
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /work/cvs/gnu/binutils/ld/emultempl/elf32.em,v
retrieving revision 1.38
diff -u -p -r1.38 elf32.em
--- ld/emultempl/elf32.em	2001/04/24 23:03:29	1.38
+++ ld/emultempl/elf32.em	2001/05/01 16:21:54
@@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suit
 
 #include "bfd.h"
 #include "sysdep.h"
+#include "libiberty.h"
 
 #include <ctype.h>
 
@@ -130,7 +131,7 @@ static void
 gld${EMULATION_NAME}_vercheck (s)
      lang_input_statement_type *s;
 {
-  const char *soname, *f;
+  const char *soname;
   struct bfd_link_needed_list *l;
 
   if (global_vercheck_failed)
@@ -141,19 +142,13 @@ gld${EMULATION_NAME}_vercheck (s)
 
   soname = bfd_elf_get_dt_soname (s->the_bfd);
   if (soname == NULL)
-    soname = bfd_get_filename (s->the_bfd);
-
-  f = strrchr (soname, '/');
-  if (f != NULL)
-    ++f;
-  else
-    f = soname;
+    soname = basename (bfd_get_filename (s->the_bfd));
 
   for (l = global_vercheck_needed; l != NULL; l = l->next)
     {
       const char *suffix;
 
-      if (strcmp (f, l->name) == 0)
+      if (strcmp (soname, l->name) == 0)
 	{
 	  /* Probably can't happen, but it's an easy check.  */
 	  continue;
@@ -168,7 +163,7 @@ gld${EMULATION_NAME}_vercheck (s)
 
       suffix += sizeof ".so." - 1;
 
-      if (strncmp (f, l->name, suffix - l->name) == 0)
+      if (strncmp (soname, l->name, suffix - l->name) == 0)
 	{
 	  /* Here we know that S is a dynamic object FOO.SO.VER1, and
              the object we are considering needs a dynamic object
@@ -192,7 +187,6 @@ gld${EMULATION_NAME}_stat_needed (s)
   struct stat st;
   const char *suffix;
   const char *soname;
-  const char *f;
 
   if (global_found)
     return;
@@ -230,17 +224,12 @@ gld${EMULATION_NAME}_stat_needed (s)
 
   soname = bfd_elf_get_dt_soname (s->the_bfd);
   if (soname == NULL)
-    soname = s->filename;
+    soname = basename (s->filename);
 
-  f = strrchr (soname, '/');
-  if (f != NULL)
-    ++f;
-  else
-    f = soname;
-
-  if (strncmp (f, global_needed->name, suffix - global_needed->name) == 0)
+  if (strncmp (soname, global_needed->name,
+	       suffix - global_needed->name) == 0)
     einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
-	   global_needed->name, global_needed->by, f);
+	   global_needed->name, global_needed->by, soname);
 }
 
 
@@ -340,11 +329,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
     einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
 
   /* First strip off everything before the last '/'.  */
-  soname = strrchr (abfd->filename, '/');
-  if (soname)
-    soname++;
-  else
-    soname = abfd->filename;
+  soname = basename (abfd->filename);
 
   if (trace_file_tries)
     info_msg (_("found %s at %s\n"), soname, name);
@@ -964,20 +949,13 @@ gld${EMULATION_NAME}_open_dynamic_archiv
   if (bfd_check_format (entry->the_bfd, bfd_object)
       && (entry->the_bfd->flags & DYNAMIC) != 0)
     {
-      char *needed_name;
-
       ASSERT (entry->is_archive && entry->search_dirs_flag);
 
       /* Rather than duplicating the logic above.  Just use the
-	 filename we recorded earlier.
+	 filename we recorded earlier.  */
 
-	 First strip off everything before the last '/'.  */
-      filename = strrchr (entry->filename, '/');
-      filename++;
-
-      needed_name = (char *) xmalloc (strlen (filename) + 1);
-      strcpy (needed_name, filename);
-      bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name);
+      filename = xstrdup (basename (entry->filename));
+      bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
     }
 
   return true;
Index: ld/testsuite/ld-elfvers/vers19.ver
===================================================================
RCS file: /work/cvs/gnu/binutils/ld/testsuite/ld-elfvers/vers19.ver,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 vers19.ver
--- ld/testsuite/ld-elfvers/vers19.ver	1999/07/09 15:21:41	1.1.1.1
+++ ld/testsuite/ld-elfvers/vers19.ver	2001/05/01 16:21:54
@@ -1,3 +1,3 @@
 Version References:
-  required from *tmpdir/vers17.so:
+  required from vers17.so:
     0x0a7922b0 0x00 02 VERS_2.0

      reply	other threads:[~2001-05-01  9:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-30 22:04 H . J . Lu
2001-05-01  9:30 ` H . J . Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010501093047.A30306@lucon.org \
    --to=hjl@lucon.org \
    --cc=binutils@sourceware.cygnus.com \
    --cc=libc-alpha@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).