[PATCH] basename usage in `ld' failing again

David O'Brien obrien@FreeBSD.org
Sat Mar 16 10:03:00 GMT 2002


The problem on FreeBSD that I fixed in rev 1.50 is back.

I never got closure on this issue in July 2001 (Subject: [PATCH] basename
buffer gets spammed in `ld'), I would like to get it this time around.

This patch gets rid of the problem once and for all.
W/o this patch we sometimes do not get the proper dependencies on shared
objects in binaries.

I would also like to apply this to the 2.12_branch.  I still applying
known bug fixes there is useful and has merit.


2002-03-16  David O'Brien  <obrien@FreeBSD.org>

	* emultempl/elf32.em: Use lbasename vs. basename to fix problem where
	the contents of the buffer returned from basename function will are
	getting overwritten while still being used.


Index: elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.72
diff -u -r1.72 elf32.em
--- elf32.em	2002/02/15 02:11:05	1.72
+++ elf32.em	2002/03/16 17:45:20
@@ -165,7 +165,7 @@
 
   soname = bfd_elf_get_dt_soname (s->the_bfd);
   if (soname == NULL)
-    soname = basename (bfd_get_filename (s->the_bfd));
+    soname = lbasename (bfd_get_filename (s->the_bfd));
 
   for (l = global_vercheck_needed; l != NULL; l = l->next)
     {
@@ -247,7 +247,7 @@
 
   soname = bfd_elf_get_dt_soname (s->the_bfd);
   if (soname == NULL)
-    soname = basename (s->filename);
+    soname = lbasename (s->filename);
 
   if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
     einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
@@ -351,7 +351,7 @@
     einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
 
   /* First strip off everything before the last '/'.  */
-  soname = basename (abfd->filename);
+  soname = lbasename (abfd->filename);
 
   if (trace_file_tries)
     info_msg (_("found %s at %s\n"), soname, name);
@@ -369,9 +369,6 @@
      DT_NEEDED entry for this file.  */
   bfd_elf_set_dt_needed_name (abfd, "");
 
-  /* Previos basename call was clobbered in lang_for_each_input_file.  */
-  soname = basename (abfd->filename);
-
   /* Tell the ELF backend that the output file needs a DT_NEEDED
      entry for this file if it is used to resolve the reference in
      a regular object.  */
@@ -976,7 +973,7 @@
       /* Rather than duplicating the logic above.  Just use the
 	 filename we recorded earlier.  */
 
-      filename = xstrdup (basename (entry->filename));
+      filename = lbasename (entry->filename);
       bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
     }
 



More information about the Binutils mailing list