about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--malloc/Makefile3
-rw-r--r--stdio-common/Makefile2
-rw-r--r--sysdeps/mips/dl-machine.h64
-rw-r--r--sysdeps/mips/mips64/dl-machine.h61
5 files changed, 92 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index b161507f0e..a11b723a07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2000-07-10  Andreas Jaeger  <aj@suse.de>
 
+	* malloc/Makefile: Run tst-mtrace only with shared libs.
+
+	* stdio-common/Makefile: Run unbputc and tst-printf tests only
+	with shared libs.
+
+2000-07-10  Maciej W. Rozycki  <macro@ds2.pg.gda.pl>
+
+	* sysdeps/mips/dl-machine.h (elf_machine_runtime_link_map): Verify
+	that gpreg really points to the GOT section of the calling object.
+	Scan all PT_LOAD segments of objects for stub_pc, instead of only
+	checking a start address of first one.
+	Fix typos.
+	* sysdeps/mips/mips64/dl-machine.h (elf_machine_runtime_link_map):
+	Likewise.
+
+	* sysdeps/mips/dl-machine.h (__dl_runtime_resolve): Fix a typo.
+
+2000-07-10  Andreas Jaeger  <aj@suse.de>
+
 	* sysdeps/unix/sysv/linux/sigaction.c: Fix typo
 	(string_alias->strong_alias).
 
diff --git a/malloc/Makefile b/malloc/Makefile
index 26b9fedc51..7831240e3c 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -91,11 +91,12 @@ $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
 
 lib: $(objpfx)libmcheck.a
 
-
+ifeq (yes,$(build-shared))
 .PHONY: do-tst-mtrace
 tests: do-tst-mtrace
 do-tst-mtrace: tst-mtrace.sh $(objpfx)tst-mtrace
 	$(SHELL) -e $< $(common-objpfx)
+endif
 
 # Uncomment this for test releases.  For public releases it is too expensive.
 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 8c914c17a5..cef34f42f8 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -60,6 +60,7 @@ test-srcs = tst-unbputc tst-printf
 
 include ../Rules
 
+ifeq (yes,$(build-shared))
 .PHONY: do-tst-unbputc do-tst-printf
 tests: do-tst-unbputc do-tst-printf
 
@@ -70,6 +71,7 @@ $(objpfx)tst-unbputc.out: $(objpfx)tst-unbputc tst-unbputc.sh
 do-tst-printf: $(objpfx)tst-printf.out
 $(objpfx)tst-printf.out: $(objpfx)tst-printf tst-printf.sh
 	$(SHELL) -e tst-printf.sh $(common-objpfx)
+endif
 
 CFLAGS-vfprintf.c = -Wno-uninitialized
 CFLAGS-tst-printf.c = -Wno-format
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index f08afa9c7f..e1b9163526 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -141,9 +141,9 @@ elf_machine_runtime_link_map (ElfW(Addr) gpreg, ElfW(Addr) stub_pc)
   extern int _dl_mips_gnu_objects;
 
   /* got[1] is reserved to keep its link map address for the shared
-     object generated by gnu linker. If all are such object, we can
-     find link map from current GPREG simply. If not so, get link map
-     for callers object containing STUB_PC.  */
+     object generated by the gnu linker.  If all are such objects, we
+     can find the link map from current GPREG simply.  If not so, get
+     the link map for caller's object containing STUB_PC.  */
 
   if (_dl_mips_gnu_objects)
     {
@@ -153,45 +153,51 @@ elf_machine_runtime_link_map (ElfW(Addr) gpreg, ElfW(Addr) stub_pc)
       g1 = ((ElfW(Word) *) got)[1];
 
       if ((g1 & ELF_MIPS_GNU_GOT1_MASK) != 0)
-	return (struct link_map *) (g1 & ~ELF_MIPS_GNU_GOT1_MASK);
+	{
+	  struct link_map *l =
+	    (struct link_map *) (g1 & ~ELF_MIPS_GNU_GOT1_MASK);
+	  ElfW(Addr) base, limit;
+	  const ElfW(Phdr) *p = l->l_phdr;
+	  ElfW(Half) this, nent = l->l_phnum;
+
+	  /* For the common case of a stub being called from the containing
+	     object, STUB_PC will point to somewhere within the object that
+	     is described by the link map fetched via got[1].  Otherwise we
+	     have to scan all maps.  */
+	  for (this = 0; this < nent; this++)
+	    {
+	      if (p[this].p_type == PT_LOAD)
+		{
+		  base = p[this].p_vaddr + l->l_addr;
+		  limit = base + p[this].p_memsz;
+		  if (stub_pc >= base && stub_pc < limit)
+		    return l;
+		}
+	    }
+	}
     }
 
     {
       struct link_map *l = _dl_loaded;
-      struct link_map *ret = 0;
-      ElfW(Addr) candidate = 0;
 
       while (l)
 	{
-	  ElfW(Addr) base = 0;
+	  ElfW(Addr) base, limit;
 	  const ElfW(Phdr) *p = l->l_phdr;
 	  ElfW(Half) this, nent = l->l_phnum;
 
-	  /* Get the base. */
-	  for (this = 0; this < nent; this++)
-	    if (p[this].p_type == PT_LOAD)
-	      {
-		base = p[this].p_vaddr + l->l_addr;
-		break;
-	      }
-	  if (! base)
-	    {
-	      l = l->l_next;
-	      continue;
-	    }
-
-	  /* Find closest link base addr. */
-	  if ((base < stub_pc) && (candidate < base))
+	  for (this = 0; this < nent; ++this)
 	    {
-	      candidate = base;
-	      ret = l;
+	      if (p[this].p_type == PT_LOAD)
+		{
+		  base = p[this].p_vaddr + l->l_addr;
+		  limit = base + p[this].p_memsz;
+		  if (stub_pc >= base && stub_pc < limit)
+		    return l;
+		}
 	    }
 	  l = l->l_next;
 	}
-      if (candidate && ret && (candidate < stub_pc))
-	return ret;
-      else if (!candidate)
-	return _dl_loaded;
     }
 
   _dl_signal_error (0, NULL, "cannot find runtime link map");
@@ -208,7 +214,7 @@ elf_machine_runtime_link_map (ElfW(Addr) gpreg, ElfW(Addr) stub_pc)
    Other architectures call fixup from dl-runtime.c in
    _dl_runtime_resolve.  MIPS instead calls __dl_runtime_resolve.  We
    have to use our own version because of the way the got section is
-   treaded on MIPS (we've also got ELF_MACHINE_PLT defined).  */
+   treated on MIPS (we've also got ELF_MACHINE_PLT defined).  */
 
 #define ELF_MACHINE_RUNTIME_TRAMPOLINE					      \
 /* The flag _dl_mips_gnu_objects is set if all dynamic objects are	      \
diff --git a/sysdeps/mips/mips64/dl-machine.h b/sysdeps/mips/mips64/dl-machine.h
index c2f2f6e939..024476b66b 100644
--- a/sysdeps/mips/mips64/dl-machine.h
+++ b/sysdeps/mips/mips64/dl-machine.h
@@ -252,9 +252,9 @@ elf_machine_runtime_link_map (ElfW(Addr) gpreg, ElfW(Addr) stub_pc)
   extern int _dl_mips_gnu_objects;
 
   /* got[1] is reserved to keep its link map address for the shared
-     object generated by gnu linker. If all are such object, we can
-     find link map from current GPREG simply. If not so, get link map
-     for callers object containing STUB_PC.  */
+     object generated by the gnu linker.  If all are such objects, we
+     can find the link map from current GPREG simply.  If not so, get
+     the link map for caller's object containing STUB_PC.  */
 
   if (_dl_mips_gnu_objects)
     {
@@ -264,45 +264,52 @@ elf_machine_runtime_link_map (ElfW(Addr) gpreg, ElfW(Addr) stub_pc)
       g1 = ((ElfW(Word) *) got)[1];
 
       if ((g1 & ELF_MIPS_GNU_GOT1_MASK) != 0)
-	return (struct link_map *) (g1 & ~ELF_MIPS_GNU_GOT1_MASK);
+	{
+	  struct link_map *l =
+	    (struct link_map *) (g1 & ~ELF_MIPS_GNU_GOT1_MASK);
+	  ElfW(Addr) base, limit;
+	  const ElfW(Phdr) *p = l->l_phdr;
+	  ElfW(Half) this, nent = l->l_phnum;
+
+	  /* For the common case of a stub being called from the containing
+	     object, STUB_PC will point to somewhere within the object that
+	     is described by the link map fetched via got[1].  Otherwise we
+	     have to scan all maps.  */
+	  for (this = 0; this < nent; this++)
+	    {
+	      if (p[this].p_type == PT_LOAD)
+		{
+		  base = p[this].p_vaddr + l->l_addr;
+		  limit = base + p[this].p_memsz;
+		  if (stub_pc >= base && stub_pc < limit)
+		    return l;
+		}
+	      this++;
+	    }
+	}
     }
 
     {
       struct link_map *l = _dl_loaded;
-      struct link_map *ret = 0;
-      ElfW(Addr) candidate = 0;
 
       while (l)
 	{
-	  ElfW(Addr) base = 0;
+	  ElfW(Addr) base, limit;
 	  const ElfW(Phdr) *p = l->l_phdr;
 	  ElfW(Half) this, nent = l->l_phnum;
 
-	  /* Get the base. */
 	  for (this = 0; this < nent; this++)
-	    if (p[this].p_type == PT_LOAD)
-	      {
-		base = p[this].p_vaddr + l->l_addr;
-		break;
-	      }
-	  if (! base)
-	    {
-	      l = l->l_next;
-	      continue;
-	    }
-
-	  /* Find closest link base addr. */
-	  if ((base < stub_pc) && (candidate < base))
 	    {
-	      candidate = base;
-	      ret = l;
+	      if (p[this].p_type == PT_LOAD)
+		{
+		  base = p[this].p_vaddr + l->l_addr;
+		  limit = base + p[this].p_memsz;
+		  if (stub_pc >= base && stub_pc < limit)
+		    return l;
+		}
 	    }
 	  l = l->l_next;
 	}
-      if (candidate && ret && (candidate < stub_pc))
-	return ret;
-      else if (!candidate)
-	return _dl_loaded;
     }
 
   _dl_signal_error (0, NULL, "cannot find runtime link map");