DragonFly BSD
DragonFly submit List (threaded) for 2004-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: ld patch


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Thu, 25 Mar 2004 18:31:42 +0100

Slightly modified version attached, give it some testing.

Joerg
? ld.patch
Index: Makefile
===================================================================
RCS file: /cvs/src/gnu/usr.bin/binutils214/ld/Makefile,v
retrieving revision 1.1
diff -u -u -r1.1 Makefile
--- Makefile	1 Feb 2004 08:53:04 -0000	1.1
+++ Makefile	25 Mar 2004 17:31:59 -0000
@@ -11,6 +11,18 @@
 	ldgram.y ldlang.c ldlex.l ldmain.c ldmisc.c \
 	ldver.c ldwrite.c lexsup.c mri.c
 
+CONTRIBDIR=	${SRCDIR}/ld
+CLEANFILES+=	emultempl/elf32.em genscripts.sh
+
+emultempl/elf32.em: ${CONTRIBDIR}/emultempl/elf32.em patches/elf32.em.patch
+	mkdir -p emultempl
+	patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/${.TARGET}
+
+genscripts.sh: ${CONTRIBDIR}/genscripts.sh patches/genscripts.sh.patch
+	patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/${.TARGET}
+
+depend: emultempl/elf32.em genscripts.sh
+
 .if defined(BOOTSTRAPPING) && !exists(/usr/include/elf-hints.h)
 SRCS+=	elf-hints.h
 CLEANFILES+=	elf-hints.h
Index: Makefile.amd64
===================================================================
RCS file: /cvs/src/gnu/usr.bin/binutils214/ld/Makefile.amd64,v
retrieving revision 1.2
diff -u -u -r1.2 Makefile.amd64
--- Makefile.amd64	22 Mar 2004 20:57:42 -0000	1.2
+++ Makefile.amd64	25 Mar 2004 17:31:59 -0000
@@ -18,7 +18,7 @@
 
 e${NATIVE_EMULATION}.c: emulparams/${NATIVE_EMULATION}.sh emultempl/elf32.em \
     scripttempl/elf.sc genscripts.sh stringify.sed
-	sh ${SRCDIR}/ld/genscripts.sh ${SRCDIR}/ld ${_amd64_path} \
+	sh genscripts.sh ${SRCDIR}/ld ${_amd64_path} \
 	    "" ${HOST} ${TARGET_TUPLE} ${TARGET_TUPLE} \
 	    "${NATIVE_EMULATION}" "" no ${NATIVE_EMULATION} "${TARGET_TUPLE}"
 
Index: Makefile.i386
===================================================================
RCS file: /cvs/src/gnu/usr.bin/binutils214/ld/Makefile.i386,v
retrieving revision 1.2
diff -u -u -r1.2 Makefile.i386
--- Makefile.i386	22 Mar 2004 20:57:42 -0000	1.2
+++ Makefile.i386	25 Mar 2004 17:31:59 -0000
@@ -20,7 +20,7 @@
 
 e${NATIVE_EMULATION}.c: emulparams/${NATIVE_EMULATION}.sh emultempl/elf32.em \
     scripttempl/elf.sc genscripts.sh stringify.sed
-	sh ${SRCDIR}/ld/genscripts.sh ${SRCDIR}/ld ${_i386_path} \
+	sh genscripts.sh ${SRCDIR}/ld ${_i386_path} \
 	    "" ${HOST} ${TARGET_TUPLE} ${TARGET_TUPLE} \
 	    "${NATIVE_EMULATION}" "" no ${NATIVE_EMULATION} "${TARGET_TUPLE}"
 #	sh ${.CURDIR}/genscripts.sh ${SRCDIR}/ld ${_i386_path} \
@@ -39,7 +39,7 @@
 
 ei386pe.c: emulparams/i386pe.sh emultempl/pe.em scripttempl/pe.sc \
     genscripts.sh stringify.sed
-	sh ${SRCDIR}/ld/genscripts.sh ${BINUTILSDISTDIR}/ld \
+	sh genscripts.sh ${BINUTILSDISTDIR}/ld \
 	    /usr/cross/winnt/lib "" ${HOST} ${TARGET_TUPLE}winnt \
 	    ${TARGET_TUPLE}winnt i386pe "" no i386pe ${TARGET_TUPLE}winnt
 #	sh ${.CURDIR}/genscripts.sh ${BINUTILSDISTDIR}/ld \
Index: patches/elf32.em.patch
===================================================================
RCS file: patches/elf32.em.patch
diff -N patches/elf32.em.patch
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/elf32.em.patch	25 Mar 2004 17:31:59 -0000
@@ -0,0 +1,189 @@
+$DragonFly$
+--- emultempl/elf32.em	2 Feb 2004 07:29:28 -0000	1.1
++++ emultempl/elf32.em	25 Mar 2004 23:56:10 -0000
+@@ -440,11 +440,68 @@ gld${EMULATION_NAME}_search_needed (path
+ }
+ 
+ EOF
+-if [ "x${USE_LIBPATH}" = xyes ] ; then
+-  cat >>e${EMULATION_NAME}.c <<EOF
++if [ "x${host}" = "x${target}" ] ; then
++  case " ${EMULATION_LIBPATH} " in
++  *" ${EMULATION_NAME} "*)
++    case ${target} in
++      *-*-freebsd* | *-*-dragonfly*)
++	cat >>e${EMULATION_NAME}.c <<EOF
++/*
++ * Read the system search path the FreeBSD way rather than like Linux.
++ */
++#include <elf-hints.h>
+ 
+-/* Add the sysroot to every entry in a colon-separated path.  */
++static bfd_boolean gld${EMULATION_NAME}_check_ld_elf_hints
++  PARAMS ((const char *, int));
++
++static bfd_boolean
++gld${EMULATION_NAME}_check_ld_elf_hints (name, force)
++     const char *name;
++     int force;
++{
++  static bfd_boolean initialized;
++  static char *ld_elf_hints;
++
++  if (! initialized)
++    {
++      FILE *f;
++
++      f = fopen (_PATH_ELF_HINTS, FOPEN_RB);
++      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);
++		    }
++		  else
++		    {
++		      ld_elf_hints = b;
++		    }
++		}
++	    }
++	  fclose (f);
++	}
++
++      initialized = TRUE;
++    }
++
++  if (ld_elf_hints == NULL)
++    return FALSE;
++
++  return gld${EMULATION_NAME}_search_needed (ld_elf_hints, name, force);
++}
+ static char * gld${EMULATION_NAME}_add_sysroot PARAMS ((const char *));
+ 
+ static char *
+@@ -484,9 +541,12 @@ gld${EMULATION_NAME}_add_sysroot (path)
+ }
+ 
+ EOF
+-  case ${target} in
+-    *-*-linux-gnu*)
+-      cat >>e${EMULATION_NAME}.c <<EOF
++	# DragonFly
++	;;
++
++      *-*-linux-gnu*)
++	cat >>e${EMULATION_NAME}.c <<EOF
++
+ /* For a native linker, check the file /etc/ld.so.conf for directories
+    in which we may find shared libraries.  /etc/ld.so.conf is really
+    only meaningful on Linux.  */
+@@ -581,6 +641,7 @@ gld${EMULATION_NAME}_check_ld_so_conf (n
+ EOF
+     # Linux
+     ;;
++    esac
+   esac
+ fi
+ cat >>e${EMULATION_NAME}.c <<EOF
+@@ -694,12 +755,16 @@ gld${EMULATION_NAME}_after_open ()
+ 	  size_t len;
+ 	  search_dirs_type *search;
+ EOF
+-if [ "x${USE_LIBPATH}" = xyes ] ; then
++if [ "x${host}" = "x${target}" ] ; then
++  case " ${EMULATION_LIBPATH} " in
++  *" ${EMULATION_NAME} "*)
+ cat >>e${EMULATION_NAME}.c <<EOF
+ 	  const char *lib_path;
+ 	  struct bfd_link_needed_list *rp;
+ 	  int found;
+ EOF
++  ;;
++  esac
+ fi
+ cat >>e${EMULATION_NAME}.c <<EOF
+ 
+@@ -707,15 +772,13 @@ cat >>e${EMULATION_NAME}.c <<EOF
+ 						  l->name, force))
+ 	    break;
+ EOF
+-if [ "x${USE_LIBPATH}" = xyes ] ; then
++if [ "x${host}" = "x${target}" ] ; then
++  case " ${EMULATION_LIBPATH} " in
++  *" ${EMULATION_NAME} "*)
+ cat >>e${EMULATION_NAME}.c <<EOF
+ 	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
+ 						  l->name, force))
+ 	    break;
+-EOF
+-fi
+-if [ "x${NATIVE}" = xyes ] ; then
+-cat >>e${EMULATION_NAME}.c <<EOF
+ 	  if (command_line.rpath_link == NULL
+ 	      && command_line.rpath == NULL)
+ 	    {
+@@ -727,10 +790,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
+ 	  lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
+ 	  if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force))
+ 	    break;
+-EOF
+-fi
+-if [ "x${USE_LIBPATH}" = xyes ] ; then
+-cat >>e${EMULATION_NAME}.c <<EOF
++
+ 	  found = 0;
+ 	  rp = bfd_elf_get_runpath_list (output_bfd, &link_info);
+ 	  for (; !found && rp != NULL; rp = rp->next)
+@@ -746,6 +806,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
+ 	    break;
+ 
+ EOF
++  ;;
++  esac
+ fi
+ cat >>e${EMULATION_NAME}.c <<EOF
+ 	  len = strlen (l->name);
+@@ -764,15 +826,25 @@ cat >>e${EMULATION_NAME}.c <<EOF
+ 	  if (search != NULL)
+ 	    break;
+ EOF
+-if [ "x${USE_LIBPATH}" = xyes ] ; then
+-  case ${target} in
+-    *-*-linux-gnu*)
+-      cat >>e${EMULATION_NAME}.c <<EOF
++if [ "x${host}" = "x${target}" ] ; then
++  case " ${EMULATION_LIBPATH} " in
++  *" ${EMULATION_NAME} "*)
++    case ${target} in
++      *-*-freebsd* | *-*-dragonfly*)
++	cat >>e${EMULATION_NAME}.c <<EOF
++	  if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
++	    break;
++EOF
++        ;;
++      *-*-linux-gnu*)
++	cat >>e${EMULATION_NAME}.c <<EOF
+ 	  if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
+ 	    break;
+ EOF
+-    # Linux
+-    ;;
++	# Linux
++        ;;
++    esac
++  ;;
+   esac
+ fi
+ cat >>e${EMULATION_NAME}.c <<EOF
Index: patches/genscripts.sh.patch
===================================================================
RCS file: patches/genscripts.sh.patch
diff -N patches/genscripts.sh.patch
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/genscripts.sh.patch	25 Mar 2004 17:31:59 -0000
@@ -0,0 +1,9 @@
+$DragonFly$
+--- genscripts.sh.old	Thu Mar 25 18:19:45 2004
++++ genscripts.sh	Thu Mar 25 18:21:35 2004
+@@ -234,4 +234,4 @@
+ esac
+ 
+ # Generate e${EMULATION_NAME}.c.
+-. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
++. emultempl/${TEMPLATE_NAME-generic}.em


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]