[PATCH] ld fails when ld.so is an executable

Aurelien Jarno aurelien@aurel32.net
Mon Jun 27 14:13:00 GMT 2005


[Please Cc me on reply as I am not subscribed to the mailing list.]

Hi!

On GNU/k*BSD, the dynamic loader "ld.so*" is declared as an executable
so that the kernel can exec it). When turned as an executable, it fails
to link anything. Note that the problems also appears when using Linux
emulation on FreeBSD.

The patch that follows, written by Guillem Jover <guillem@hadrons.org>,
determines whether ld.so is an executable or a shared object, so that
binutils conforms to the ELF standard (section 2-6 in book III), which
says that the dynamic linker can be a shared object or an executable.

Bye,
Aurelien


2005-06-22  Aurelien Jarno  <aurel32@debian.org>

	* bfd/elfcode.h: Allow ld.so to be an executable.


Index: bfd/elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.71
diff -u -d -p -r1.71 elfcode.h
--- bfd/elfcode.h	10 Jun 2005 20:22:23 -0000	1.71
+++ bfd/elfcode.h	27 Jun 2005 04:06:28 -0000
@@ -592,8 +592,22 @@ elf_object_p (bfd *abfd)
 	}
     }
 
+  /* Determine whether the file is an executable or a shared object.
+     It can even be both: The dynamic loader "ld.so*" is declared as an
+     executable (so the kernel can exec it) but at the same time we
+     treat it as a shared object (for symbol versioning purposes).  */
   if (i_ehdrp->e_type == ET_EXEC)
-    abfd->flags |= EXEC_P;
+    {
+      const char *file_name = abfd->filename;
+      const char *last_slash = strrchr (file_name, '/');
+      const char *base_name = (last_slash ? last_slash + 1 : file_name);
+      if (strncmp (base_name, "ld.so", 5) == 0)
+	/* The dynamic loader.  */
+	abfd->flags |= DYNAMIC;
+      else
+	/* Normal executable.  */
+	abfd->flags |= EXEC_P;
+    }
   else if (i_ehdrp->e_type == ET_DYN)
     abfd->flags |= DYNAMIC;
 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian GNU/Linux developer | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net



More information about the Binutils mailing list