--- ./i386/boot1.c.~1~	Sat Dec  3 00:54:14 1994
+++ ./i386/boot1.c	Sat Dec  3 23:09:36 1994
@@ -204,6 +204,12 @@
     _dl_close(zfileno);
   };
 
+  if (malloc_buffer == -1) {
+    SEND_STDERR("Mmap of /dev/zero failed\n");
+    _dl_exit(1);
+  }
+
+
   tpnt = DL_MALLOC(sizeof(struct elf_resolve));
   _dl_memset (tpnt, 0, sizeof (*tpnt));
   app_tpnt = DL_MALLOC(sizeof(struct elf_resolve));
@@ -286,6 +292,7 @@
   /* OK, now do the relocations.  We do not do a lazy binding here, so
    that once we are done, we have considerably more flexibility. */
 
+  goof = 0;
   for(indx=0; indx < 2; indx++)
     {
       int i;
@@ -354,8 +361,12 @@
 	    if(symbol_addr) break;
 	  };
 	  if(!symbol_addr) symbol_addr = weak_result;
-	  if(!symbol_addr)
-	    continue;
+	  if(!symbol_addr) {
+	    SEND_STDERR("ELF dynamic loader - unable to self-bootstrap - symbol ");
+	    SEND_STDERR(strtab + symtab[symtab_index].st_name);
+	    SEND_STDERR(" undefined.\n");
+	    goof++;
+	  }
 	};
 	switch(reloc_type){
 	case R_386_32:
@@ -381,6 +392,8 @@
       };
     }; 
 
+  if (goof)    _dl_exit(1);
+
   /* OK, at this point we have a crude malloc capability.  Start to build
      the tables of the modules that are required for this beast to run.
      We start with the basic executable, and then go from there.  Eventually
@@ -517,6 +530,7 @@
 		ttmp = _dl_loaded_modules;
 		while(ttmp->next) ttmp = ttmp->next;
 		ttmp->next = tpnt;
+		tpnt->prev = ttmp;
 		tpnt->next = NULL;
 		rpnt->next = 
 		   (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
@@ -601,6 +615,7 @@
    * Now we go through and look for REL and RELA records that indicate fixups
    * to the GOT tables.  We need to do this in reverse order so that COPY
    * directives work correctly */
+
   goof = _dl_fixup(_dl_loaded_modules);
 
   /* Some flavors of SVr4 do not generate the R_386_COPY directive,
--- ./libdl/dlib.c.~1~	Wed Nov 23 12:58:01 1994
+++ ./libdl/dlib.c	Sat Dec  3 22:55:10 1994
@@ -287,6 +287,7 @@
 }
 
 /* Generate the correct symbols that we need. */
+#ifndef IBCS_COMPATIBLE
 #if 1
 #pragma weak dlopen = _dlopen
 #pragma weak dlerror = _dlerror
@@ -298,6 +299,7 @@
 __asm__(".weak dlclose;dlclose=_dlclose");
 __asm__(".weak dlsym;dlsym=_dlsym");
 #endif
+#endif
 
 /* This is a real hack.  We need access to the dynamic linker, but we
 also need to make it possible to link against this library without any
@@ -312,6 +314,7 @@
 
 static int foobar1 = 0; /* Use as pointer */
 
+#ifndef IBCS_COMPATIBLE
 #if 1
 #pragma weak _dl_find_hash = foobar
 #pragma weak _dl_symbol_tables = foobar1
@@ -330,6 +333,7 @@
 __asm__(".weak _dl_malloc_function; _dl_malloc_function = foobar1");
 __asm__(".weak _dl_parse_relocation_information; _dl_parse_relocation_information = foobar");
 __asm__(".weak _dl_parse_lazy_relocation_information; _dl_parse_lazy_relocation_information = foobar");
+#endif
 #endif
 
 /*
--- ./Makefile.~1~	Sat Dec  3 12:48:07 1994
+++ ./Makefile	Sat Dec  3 22:48:33 1994
@@ -2,6 +2,10 @@
 include	../Makerules
 include	../Makeconfig
 
+
+XCFLAGS= -DIBCS_COMPATIBLE
+ZCFLAGS=-I. -I./i386
+
 #CFLAGS=-g -Wall -O2 -nostdinc -I/usr/local/lib/gcc-lib/i486-sysv4/2.4.5/include/ -I/home/eric/linux/usr/include/
 #CFLAGS=-g -Wall -O2 -fPIC
 #CC=/usr/local/bin/gcc
@@ -8,8 +12,8 @@
 #
 # For SVr4/ELF systems, libc.so.1 contains both the dynamic linker and libc.
 #
-SRC1S = resolve.S
-SRC2S = hash.c readelflib1.c
+SRC1S = i386/resolve.S
+SRC2S = hash.c readelflib1.c i386/elfinterp.c i386/boot1.c libdl/dlib.c
 
 SRCS	= $(SRC1S) $(SRC2S)
 ASMS	= $(SCR1S:.S=.s) $(SRC2S:.c=.s)
@@ -21,26 +25,15 @@
 	libsysdeps.o   libcvt.o     libmalloc.o   libstdio.o	  libstring.o \
 	libsvr4.o	libdirent.o liblocale.o	  libtime.o	libpwd.o
 
-all: ../libc.so.1 ../ld.so.1 .gdbinit
+all: ../libc.so.1 ../ld.so.1
 
-../libc.so.1: Makefile elfinterp.o hash.o readelflib1.o  resolve.o boot1.o $(LIBSRC)
-	$(LD) -e _dl_boot $(LD_SHLIBFLAG) -o ../libc.so.1 boot1.o elfinterp.o resolve.o hash.o \
-	readelflib1.o $(LIBSRC)
-
-ifdef GNUELF
-.gdbinit: ../libc.so.1
-	$(NM) ../libc.so.1 | grep _dl_boot | sed 's/0000/0x4000/' | \
-	awk '{print "add-symbol-file /usr/lib/libc.so.1 " $$1}' > .gdbinit
-else
-.gdbinit: ../libc.so.1
-	$(NM) -x ../libc.so.1 | grep _dl_boot | sed 's/|0x0/ 0x4/g' | grep FUNC | \
-	awk '{print "add-symbol-file /usr/lib/libc.so.1 " $$2}' > .gdbinit
-endif
-
-
-../ld.so.1: Makefile elfinterp.o hash.o readelflib1.o  resolve.o boot1.o
-	$(LD) -e _dl_boot $(LD_SHLIBFLAG) -o ../ld.so.1 boot1.o elfinterp.o resolve.o \
-	hash.o readelflib1.o
+../libc.so.1: Makefile i386/elfinterp.o hash.o readelflib1.o  i386/resolve.o i386/boot1.o libdl/dlib.o $(LIBSRC)
+	$(LD) -e _dl_boot $(LD_SHLIBFLAG) -o ../libc.so.1 i386/boot1.o i386/elfinterp.o \
+		i386/resolve.o hash.o readelflib1.o libdl/dlib.o $(LIBSRC)
+
+../ld.so.1: Makefile i386/elfinterp.o hash.o readelflib1.o  i386/resolve.o i386/boot1.o
+	$(LD) -e _dl_boot $(LD_SHLIBFLAG) -o ../ld.so.1 i386/boot1.o i386/elfinterp.o \
+		i386/resolve.o hash.o readelflib1.o
 
 test: test.o ../libc.so.1
 	$(LD) -o test -I ../libc.so.1 test.o ../libc.so.1
--- ./linuxelf.h.~1~	Thu Oct 20 00:14:23 1994
+++ ./linuxelf.h	Sat Dec  3 22:30:00 1994
@@ -188,4 +188,6 @@
 /* Use BROKEN_LINKER if the SVr4 linker is being used.  It fails to emit
    COPY relocations in some cases */
 
-/* #define BROKEN_LINKER */
+#ifdef IBCS_COMPATIBLE
+#define BROKEN_LINKER
+#endif
--- ./readelflib1.c.~1~	Tue Nov 15 00:33:22 1994
+++ ./readelflib1.c	Sat Dec  3 23:37:57 1994
@@ -94,9 +94,25 @@
 
   /* Still no luck.  Try one last possibility */
 
-  /* If the filename has any '/', try it straight and leave it at that */
+  /* If the filename has any '/', try it straight and leave it at that.  For
+   IBCS2 compatibility under linux, we substitute the string /usr/i486-sysv4/lib for
+   /usr/lib in library names. */
+
   if(libname != full_libname) {
+#ifdef IBCS_COMPATIBLE
+    if(_dl_strncmp(full_libname, "/usr/lib/", 9) != 0) {
+	tpnt1 = _dl_load_elf_shared_library(full_libname, 0);
+    } else {
+      pnt1 = "/usr/i486-sysv4/lib/";
+      pnt = mylibname;
+      while(*pnt1) *pnt++ = *pnt1++;
+      pnt1 = full_libname + 9;
+      while(*pnt1) *pnt++ = *pnt1++;
+      tpnt1 = _dl_load_elf_shared_library(mylibname, 0);
+    }
+#else
 	tpnt1 = _dl_load_elf_shared_library(full_libname, 0);
+#endif
 	if (!tpnt1) goto goof;
 	return tpnt1;
   }
@@ -114,7 +130,12 @@
   if(tpnt1) return tpnt1;
 #endif
 
+
+#ifdef IBCS_COMPATIBLE
+  pnt1 = "/usr/i486-sysv4/lib/";
+#else
   pnt1 = "/usr/lib/";
+#endif
   pnt = mylibname;
   while(*pnt1) *pnt++ = *pnt1++;
   pnt1 = libname;
@@ -395,7 +416,7 @@
 
       /* OK, we have a candidate.  Now search for the same symbol in other
 	 libraries.  The hash number will be the same. */
-      for(rpnt1 = rpnt->next; rpnt1; rpnt1 = tpnt1->next)
+      for(rpnt1 = rpnt->next; rpnt1; rpnt1 = rpnt1->next)
 	{
 	  tpnt1 = rpnt1->dyn;
 	  hn1 = elf_hash_number % tpnt1->nbucket;
--- ./ChangeLog.~1~	Sat Dec  3 22:50:31 1994
+++ ./ChangeLog	Sat Dec  3 23:40:27 1994
@@ -1,3 +1,11 @@
+Sat Dec  3 23:39:22 1994  Eric Youngdale  (eric@andante)
+
+	* Throughout:  Update dynamic loader to use same source tree as
+	the loader used for native ELF.  Use IBCS_COMPATIBLE defines to
+	differentiate behavior.
+
+	* elfinterp1.c: Search /usr/i486-sysv4/lib instead of /usr/lib.
+
 Sat Aug 20 23:26:55 1994  Eric Youngdale  (eric@esp22)
 
 	* elfinterp.c: Fix bug involving RPATH.
