public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Add support for ld-elf.so.hints on FreeBSD - Third try
@ 2006-02-27 16:06 Diego 'Flameeyes' Pettenò
  2006-03-06 16:11 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Diego 'Flameeyes' Pettenò @ 2006-02-27 16:06 UTC (permalink / raw)
  To: binutils


[-- Attachment #1.1: Type: text/plain, Size: 752 bytes --]

New version of the two patches to add support for ld hints on FreeBSD (and 
DragonFly). It corrects the grammatical error Jan-Benedict Glaw pointed, and 
it minimize the changes, by dropping part of the patch that seemed to touch 
ld's sources only to add support for FreeBSD's aout format (I'm not sure if 
it's worth to submit that patch actually); it also checks for either freebsd 
or dragonfly when enabling ld-elf.so.hints support, as also DragonFly uses 
the same hints (although the modified binutils in DragonFly enables them only 
when it's using native compiler, hacking the emultempl script more).

-- 
Diego "Flameeyes" Pettenò - http://dev.gentoo.org/~flameeyes/
Gentoo/ALT lead, Gentoo/FreeBSD, Video, AMD64, Sound, PAM, KDE

[-- Attachment #1.2: binutils-2.16.1-ldhints.patch --]
[-- Type: text/x-diff, Size: 3835 bytes --]

Index: binutils-2.16.1/ld/emultempl/elf32.em
===================================================================
--- binutils-2.16.1.orig/ld/emultempl/elf32.em
+++ binutils-2.16.1/ld/emultempl/elf32.em
@@ -522,6 +522,97 @@ gld${EMULATION_NAME}_add_sysroot (const 
 
 EOF
   case ${target} in
+    *-*-freebsd* | *-*-dragonfly*)
+      cat >>e${EMULATION_NAME}.c <<EOF
+/*
+ * Read the system search path the FreeBSD way rather than like Linux.
+ */
+#ifdef HAVE_ELF_HINTS_H
+#include <elf-hints.h>
+#else
+ /*
+  * Fallback code taken from FreeBSD's libc
+  * Copyright (c) 1997 John D. Polstra.
+  *
+  * This works only if the hints file is generated with a compatible version
+  * of ldconfig (most FreeBSD up to 6.1 and DragonFly at least up to 1.4),
+  * and with the same endianness.
+  */
+
+  struct elfhints_hdr {
+        u_int32_t       magic;          /* Magic number */
+        u_int32_t       version;        /* File version (1) */
+        u_int32_t       strtab;         /* Offset of string table in file */
+        u_int32_t       strsize;        /* Size of string table */
+        u_int32_t       dirlist;        /* Offset of directory list in
+                                           string table */
+        u_int32_t       dirlistlen;     /* strlen(dirlist) */
+        u_int32_t       spare[26];      /* Room for expansion */
+  };
+
+  #define ELFHINTS_MAGIC  0x746e6845
+
+  #define _PATH_ELF_HINTS "/var/run/ld-elf.so.hints"
+#endif
+
+static bfd_boolean
+gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force)
+{
+  static bfd_boolean initialized;
+  static char *ld_elf_hints;
+  struct dt_needed needed;
+
+  if (! initialized)
+    {
+      FILE *f;
+      char *tmppath;
+
+      tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, NULL);
+      f = fopen (tmppath, FOPEN_RB);
+      free (tmppath);
+      if (f != NULL)
+	{
+	  struct elfhints_hdr hdr;
+
+	  if (fread(&hdr, 1, sizeof(hdr), f) == sizeof(hdr) &&
+	      hdr.magic == ELFHINTS_MAGIC &&
+	      hdr.version == 1)
+	    {
+	      if (fseek(f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
+		{
+		  char *b;
+
+		  b = (char *) xmalloc (hdr.dirlistlen + 1);
+		  if (fread(b, 1, hdr.dirlistlen + 1, f) !=
+		      hdr.dirlistlen + 1)
+		    {
+		      free(b);
+		      b = NULL;
+		    }
+		  else
+		    {
+		      ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
+		      free (b);
+		    }
+		}
+	    }
+	  fclose (f);
+	}
+
+      initialized = TRUE;
+    }
+
+  if (ld_elf_hints == NULL)
+    return FALSE;
+
+  needed.by = NULL;
+  needed.name = name;
+  return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
+}
+EOF
+    # FreeBSD
+    ;;
+
     *-*-linux-gnu*)
       cat >>e${EMULATION_NAME}.c <<EOF
 /* For a native linker, check the file /etc/ld.so.conf for directories
@@ -932,6 +1023,14 @@ cat >>e${EMULATION_NAME}.c <<EOF
 EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
   case ${target} in
+    *-*-freebsd* | *-*-dragonfly*)
+      cat >>e${EMULATION_NAME}.c <<EOF
+	  if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
+	    break;
+EOF
+    # FreeBSD
+    ;;
+
     *-*-linux-gnu*)
       cat >>e${EMULATION_NAME}.c <<EOF
 	  if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
Index: binutils-2.16.1/ld/configure.in
===================================================================
--- binutils-2.16.1.orig/ld/configure.in
+++ binutils-2.16.1/ld/configure.in
@@ -118,7 +118,7 @@ AC_SUBST(HOSTING_CRT0)
 AC_SUBST(HOSTING_LIBS)
 AC_SUBST(NATIVE_LIB_DIRS)
 
-AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h)
+AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h elf-hints.h)
 AC_CHECK_FUNCS(sbrk realpath glob)
 AC_HEADER_DIRENT
 

[-- Attachment #1.3: binutils-2.16.91.0.6-ldhints.patch --]
[-- Type: text/x-diff, Size: 3806 bytes --]

Index: binutils-2.16.91.0.6/ld/emultempl/elf32.em
===================================================================
--- binutils-2.16.91.0.6.orig/ld/emultempl/elf32.em
+++ binutils-2.16.91.0.6/ld/emultempl/elf32.em
@@ -529,6 +529,97 @@ gld${EMULATION_NAME}_add_sysroot (const 
 
 EOF
   case ${target} in
+    *-*-freebsd* | *-*-dragonfly*)
+      cat >>e${EMULATION_NAME}.c <<EOF
+/*
+ * Read the system search path the FreeBSD way rather than like Linux.
+ */
+#ifdef HAVE_ELF_HINTS_H
+#include <elf-hints.h>
+#else
+ /*
+  * Fallback code taken from FreeBSD's libc
+  * Copyright (c) 1997 John D. Polstra.
+  *
+  * This works only if the hints file is generated with a compatible version
+  * of ldconfig (most FreeBSD up to 6.1 and DragonFly at least up to 1.4),
+  * and with the same endianness.
+  */
+
+  struct elfhints_hdr {
+        u_int32_t       magic;          /* Magic number */
+        u_int32_t       version;        /* File version (1) */
+        u_int32_t       strtab;         /* Offset of string table in file */
+        u_int32_t       strsize;        /* Size of string table */
+        u_int32_t       dirlist;        /* Offset of directory list in
+                                           string table */
+        u_int32_t       dirlistlen;     /* strlen(dirlist) */
+        u_int32_t       spare[26];      /* Room for expansion */
+  };
+
+  #define ELFHINTS_MAGIC  0x746e6845
+
+  #define _PATH_ELF_HINTS "/var/run/ld-elf.so.hints"
+#endif
+
+static bfd_boolean
+gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force)
+{
+  static bfd_boolean initialized;
+  static char *ld_elf_hints;
+  struct dt_needed needed;
+
+  if (! initialized)
+    {
+      FILE *f;
+      char *tmppath;
+
+      tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, NULL);
+      f = fopen (tmppath, FOPEN_RB);
+      free (tmppath);
+      if (f != NULL)
+	{
+	  struct elfhints_hdr hdr;
+
+	  if (fread(&hdr, 1, sizeof(hdr), f) == sizeof(hdr) &&
+	      hdr.magic == ELFHINTS_MAGIC &&
+	      hdr.version == 1)
+	    {
+	      if (fseek(f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
+		{
+		  char *b;
+
+		  b = (char *) xmalloc (hdr.dirlistlen + 1);
+		  if (fread(b, 1, hdr.dirlistlen + 1, f) !=
+		      hdr.dirlistlen + 1)
+		    {
+		      free(b);
+		      b = NULL;
+		    }
+		  else
+		    {
+		      ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
+		      free (b);
+		    }
+		}
+	    }
+	  fclose (f);
+	}
+
+      initialized = TRUE;
+    }
+
+  if (ld_elf_hints == NULL)
+    return FALSE;
+
+  needed.by = NULL;
+  needed.name = name;
+  return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
+}
+EOF
+    # FreeBSD
+    ;;
+
     *-*-linux-* | *-*-k*bsd*-*)
       cat >>e${EMULATION_NAME}.c <<EOF
 /* For a native linker, check the file /etc/ld.so.conf for directories
@@ -921,6 +1012,14 @@ EOF
 fi
 if [ "x${USE_LIBPATH}" = xyes ] ; then
   case ${target} in
+    *-*-freebsd* | *-*-dragonfly*)
+      cat >>e${EMULATION_NAME}.c <<EOF
+	  if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
+	    break;
+EOF
+    # FreeBSD
+    ;;
+
     *-*-linux-* | *-*-k*bsd*-*)
     # Linux
       cat >>e${EMULATION_NAME}.c <<EOF
Index: binutils-2.16.91.0.6/ld/configure.in
===================================================================
--- binutils-2.16.91.0.6.orig/ld/configure.in
+++ binutils-2.16.91.0.6/ld/configure.in
@@ -99,7 +99,7 @@ AC_SUBST(HOSTING_CRT0)
 AC_SUBST(HOSTING_LIBS)
 AC_SUBST(NATIVE_LIB_DIRS)
 
-AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h)
+AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h elf-hints.h)
 AC_CHECK_FUNCS(sbrk realpath glob)
 AC_HEADER_DIRENT
 

[-- Attachment #2: Type: application/pgp-signature, Size: 191 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add support for ld-elf.so.hints on FreeBSD - Third try
  2006-02-27 16:06 Add support for ld-elf.so.hints on FreeBSD - Third try Diego 'Flameeyes' Pettenò
@ 2006-03-06 16:11 ` Nick Clifton
  2006-03-07  5:35   ` Hans-Peter Nilsson
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2006-03-06 16:11 UTC (permalink / raw)
  To: Diego 'Flameeyes' Pettenò; +Cc: binutils

Hi Diego,

> New version of the two patches to add support for ld hints on FreeBSD (and 
> DragonFly). 


The patch is basically OK, but...

   1. It is missing a ChangeLog entry.

   2. Formatting - please follow the GNU Coding Convention:

> +/*
> + * Read the system search path the FreeBSD way rather than like Linux.
> + */

   should be:

   /* Read the system search path the FreeBSD way rather then like 
Linux.  */


> +	  if (fread(&hdr, 1, sizeof(hdr), f) == sizeof(hdr) &&

   should be:


    if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
        && .....


   3. License information:

> +  * Fallback code taken from FreeBSD's libc
> +  * Copyright (c) 1997 John D. Polstra.

      Under what form(s) of license is this code distributed ?  Is 
it/are they compatible with the GPL ?  Why have they not been included 
here ?


   4. What is this elf-hints.h file ?  Shouldn't it be provided with the 
patch ?

Cheers
   Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add support for ld-elf.so.hints on FreeBSD - Third try
  2006-03-06 16:11 ` Nick Clifton
@ 2006-03-07  5:35   ` Hans-Peter Nilsson
  2006-03-07  7:50     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Hans-Peter Nilsson @ 2006-03-07  5:35 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Diego 'Flameeyes' Pettenò, binutils

On Mon, 6 Mar 2006, Nick Clifton wrote:
> > + * Read the system search path the FreeBSD way rather than like Linux.
> > + */
>
>    should be:
>
>    /* Read the system search path the FreeBSD way rather then like
> Linux.  */

No, it shouldn't: it's if-then but rather-than.

brgds, H-P
"No error is too small for me to point out"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add support for ld-elf.so.hints on FreeBSD - Third try
  2006-03-07  5:35   ` Hans-Peter Nilsson
@ 2006-03-07  7:50     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2006-03-07  7:50 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: Diego 'Flameeyes' Pettenò, binutils

Hi Guys,

Hans-Peter Nilsson wrote:

>>>+ * Read the system search path the FreeBSD way rather than like Linux.
>>>+ */
>>
>>   should be:
>>
>>   /* Read the system search path the FreeBSD way rather then like
>>Linux.  */

> No, it shouldn't: it's if-then but rather-than.


Doh!!

Cheers
   Nick


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-07  7:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-27 16:06 Add support for ld-elf.so.hints on FreeBSD - Third try Diego 'Flameeyes' Pettenò
2006-03-06 16:11 ` Nick Clifton
2006-03-07  5:35   ` Hans-Peter Nilsson
2006-03-07  7:50     ` Nick Clifton

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).