This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Fix DT_REL{,A}COUNT handling


Hi!

This works for me just fine (just finished make check with libc.so built by
hand with -z combreloc).
As elf_dynamic_do_rel* can be called twice with lazy == 0, I moved
DT_REL{,A}COUNT checking into dynamic-link.h and just use a different
function which does the internal loop.

2001-08-24  Jakub Jelinek  <jakub@redhat.com>

	* elf/do-rel.h (elf_dynamic_do_rel_relative): New.
	(elf_dynamic_do_rel): Backout recent changes.
	* elf/dynamic-link.h (_ELF_DYNAMIC_DO_RELOC): Call
	elf_dynamic_do_rel*_relative and adjust rel region.
	Add Reloc argument.
	(ELF_DYNAMIC_DO_REL, ELF_DYNAMIC_DO_RELA): Adjust callers.
	* sysdeps/hppa/dl-machine.h (elf_machine_rela_relative):
	Rename from elf_machine_rel_relative.
	* sysdeps/cris/dl-machine.h (elf_machine_rela_relative): Likewise.
	* sysdeps/m68k/dl-machine.h (elf_machine_rela_relative): Likewise.
	* sysdeps/powerpc/dl-machine.h (elf_machine_rela_relative): Likewise.
	* sysdeps/ia64/dl-machine.h (elf_machine_rela_relative): Likewise.
	Fix argument types.
	* sysdeps/alpha/dl-machine.h (elf_machine_rela_relative): Likewise.
	Fix argument types.
	* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela_relative):
	Likewise. Fix argument types.
	* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela_relative):
	Likewise. Fix argument types.
	* sysdeps/sh/dl-machine.h (elf_machine_rela_relative): Likewise.
	Fix argument types.
	* sysdeps/mips/dl-machine.h (elf_machine_rel_relative): Use
	ElfW(Rel) in argument.
	* sysdeps/mips/mips64/dl-machine.h (elf_machine_rel_relative): New.

--- libc/elf/do-rel.h.jj	Fri Aug 24 11:09:24 2001
+++ libc/elf/do-rel.h	Fri Aug 24 14:59:01 2001
@@ -21,18 +21,40 @@
    `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.  */
 
 #ifdef DO_RELA
-# define elf_dynamic_do_rel	elf_dynamic_do_rela
-# define RELCOUNT_IDX		VERSYMIDX (DT_RELACOUNT)
-# define Rel			Rela
-# define elf_machine_rel	elf_machine_rela
-#else
-# define RELCOUNT_IDX		VERSYMIDX (DT_RELCOUNT)
+# define elf_dynamic_do_rel		elf_dynamic_do_rela
+# define elf_dynamic_do_rel_relative	elf_dynamic_do_rela_relative
+# define Rel				Rela
+# define elf_machine_rel		elf_machine_rela
+# define elf_machine_rel_relative	elf_machine_rela_relative
 #endif
 
 #ifndef VERSYMIDX
 # define VERSYMIDX(sym)	(DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym))
 #endif
 
+static inline void
+elf_dynamic_do_rel_relative (struct link_map *map, ElfW(Addr) reladdr,
+			     ElfW(Addr) relsize)
+{
+  const ElfW(Rel) *r = (const void *) reladdr;
+  const ElfW(Rel) *end = (const void *) (reladdr + relsize);
+  ElfW(Addr) l_addr = map->l_addr;
+
+#ifndef RTLD_BOOTSTRAP
+  /* This is defined in rtld.c, but nowhere in the static libc.a; make
+     the reference weak so static programs can still link.  This
+     declaration cannot be done when compiling rtld.c (i.e. #ifdef
+     RTLD_BOOTSTRAP) because rtld.c contains the common defn for
+     _dl_rtld_map, which is incompatible with a weak decl in the same
+     file.  */
+  weak_extern (_dl_rtld_map);
+  if (map != &_dl_rtld_map) /* Already done in rtld itself.  */
+#endif
+    for (; r < end; ++r)
+      elf_machine_rel_relative (l_addr, r,
+				(void *) (l_addr + r->r_offset));
+}
+
 /* Perform the relocations in MAP on the running program image as specified
    by RELTAG, SZTAG.  If LAZY is nonzero, this is the first pass on PLT
    relocations; they should be set up to call _dl_runtime_resolve, rather
@@ -57,10 +79,6 @@ elf_dynamic_do_rel (struct link_map *map
     {
       const ElfW(Sym) *const symtab =
 	(const void *) D_PTR (map, l_info[DT_SYMTAB]);
-      ElfW(Word) nrelative = (map->l_info[RELCOUNT_IDX] == NULL
-			      ? 0 : map->l_info[RELCOUNT_IDX]->d_un.d_val);
-      const ElfW(Rel) *endrel = end;
-      end -= nrelative;
 
       if (map->l_info[VERSYMIDX (DT_VERSYM)])
 	{
@@ -79,23 +97,11 @@ elf_dynamic_do_rel (struct link_map *map
 	for (; r < end; ++r)
 	  elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
 			   (void *) (l_addr + r->r_offset));
-
-#ifndef RTLD_BOOTSTRAP
-      /* This is defined in rtld.c, but nowhere in the static libc.a; make
-	 the reference weak so static programs can still link.  This
-	 declaration cannot be done when compiling rtld.c (i.e. #ifdef
-	 RTLD_BOOTSTRAP) because rtld.c contains the common defn for
-	 _dl_rtld_map, which is incompatible with a weak decl in the same
-	 file.  */
-      weak_extern (_dl_rtld_map);
-      if (map != &_dl_rtld_map) /* Already done in rtld itself.  */
-#endif
-	for (; r < endrel; ++r)
-	  elf_machine_rel_relative (l_addr, r,
-				    (void *) (l_addr + r->r_offset));
     }
 }
 
 #undef elf_dynamic_do_rel
+#undef elf_dynamic_do_rel_relative
 #undef Rel
 #undef elf_machine_rel
+#undef elf_machine_rel_relative
--- libc/elf/dynamic-link.h.jj	Thu Aug 23 18:56:20 2001
+++ libc/elf/dynamic-link.h	Fri Aug 24 14:22:51 2001
@@ -1,5 +1,5 @@
 /* Inline functions for dynamic linking.
-   Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
+   Copyright (C) 1995-2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -134,7 +134,7 @@ elf_get_dynamic_info (struct link_map *l
    not happen we do something more optimal.  */
 
 # ifdef ELF_MACHINE_PLTREL_OVERLAP
-#  define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, do_lazy, test_rel) \
+#  define _ELF_DYNAMIC_DO_RELOC(RELOC, Reloc, reloc, map, do_lazy, test_rel) \
   do {									      \
     struct { ElfW(Addr) start, size; int lazy; } ranges[3];		      \
     int ranges_index;							      \
@@ -147,6 +147,15 @@ elf_get_dynamic_info (struct link_map *l
       {									      \
 	ranges[0].start = D_PTR ((map), l_info[DT_##RELOC]);		      \
 	ranges[0].size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val;	      \
+	if ((map)->l_info[VERSYMIDX (DT_##RELOC##COUNT)])		      \
+	  {								      \
+	    ElfW(Addr) size;						      \
+	    size = (map)->l_info[VERSYMIDX (DT_##RELOC##COUNT)]->d_un.d_val   \
+		   * sizeof (Reloc);					      \
+	    elf_dynamic_do_##reloc##_relative ((map), ranges[0].start, size); \
+	    ranges[0].start += size;					      \
+	    ranges[0].size -= size;					      \
+	  }								      \
       }									      \
 									      \
      if ((do_lazy)							      \
@@ -167,7 +176,7 @@ elf_get_dynamic_info (struct link_map *l
 			      ranges[ranges_index].lazy);		      \
   } while (0)
 # else
-#  define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, do_lazy, test_rel) \
+#  define _ELF_DYNAMIC_DO_RELOC(RELOC, Reloc, reloc, map, do_lazy, test_rel) \
   do {									      \
     struct { ElfW(Addr) start, size; int lazy; } ranges[2];		      \
     int ranges_index;							      \
@@ -179,6 +188,15 @@ elf_get_dynamic_info (struct link_map *l
       {									      \
         ranges[0].start = D_PTR ((map), l_info[DT_##RELOC]);		      \
         ranges[0].size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val;	      \
+	if ((map)->l_info[VERSYMIDX (DT_##RELOC##COUNT)])		      \
+	  {								      \
+	    ElfW(Addr) size;						      \
+	    size = (map)->l_info[VERSYMIDX (DT_##RELOC##COUNT)]->d_un.d_val   \
+		   * sizeof (Reloc);					      \
+	    elf_dynamic_do_##reloc##_relative ((map), ranges[0].start, size); \
+	    ranges[0].start += size;					      \
+	    ranges[0].size -= size;					      \
+	  }								      \
       }									      \
     if ((map)->l_info[DT_PLTREL]					      \
 	&& (!test_rel || (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC)) \
@@ -217,7 +235,7 @@ elf_get_dynamic_info (struct link_map *l
 # if ! ELF_MACHINE_NO_REL
 #  include "do-rel.h"
 #  define ELF_DYNAMIC_DO_REL(map, lazy) \
-  _ELF_DYNAMIC_DO_RELOC (REL, rel, map, lazy, _ELF_CHECK_REL)
+  _ELF_DYNAMIC_DO_RELOC (REL, ElfW(Rel), rel, map, lazy, _ELF_CHECK_REL)
 # else
 #  define ELF_DYNAMIC_DO_REL(map, lazy) /* Nothing to do.  */
 # endif
@@ -226,7 +244,7 @@ elf_get_dynamic_info (struct link_map *l
 #  define DO_RELA
 #  include "do-rel.h"
 #  define ELF_DYNAMIC_DO_RELA(map, lazy) \
-  _ELF_DYNAMIC_DO_RELOC (RELA, rela, map, lazy, _ELF_CHECK_REL)
+  _ELF_DYNAMIC_DO_RELOC (RELA, ElfW(Rela), rela, map, lazy, _ELF_CHECK_REL)
 # else
 #  define ELF_DYNAMIC_DO_RELA(map, lazy) /* Nothing to do.  */
 # endif
--- libc/sysdeps/alpha/dl-machine.h.jj	Fri Aug 24 11:09:51 2001
+++ libc/sysdeps/alpha/dl-machine.h	Fri Aug 24 14:28:08 2001
@@ -548,8 +548,8 @@ elf_machine_rela (struct link_map *map,
 }
 
 static inline void
-elf_machine_rel_relative (Elf64_Addr l_addr, const Elf64_Rel *reloc,
-			  Elf64_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
+			   Elf64_Addr *const reloc_addr)
 {
   /* XXX Make some timings.  Maybe it's preverable to test for
      unaligned access and only do it the complex way if necessary.  */
--- libc/sysdeps/hppa/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/hppa/dl-machine.h	Fri Aug 24 14:29:46 2001
@@ -629,8 +629,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   /* XXX Nothing to do.  There is no relative relocation, right?  */
 }
--- libc/sysdeps/cris/dl-machine.h.jj	Fri Aug 24 11:09:51 2001
+++ libc/sysdeps/cris/dl-machine.h	Fri Aug 24 14:30:32 2001
@@ -366,8 +366,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }
--- libc/sysdeps/ia64/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/ia64/dl-machine.h	Fri Aug 24 14:34:28 2001
@@ -580,8 +580,8 @@ elf_machine_rela (struct link_map *map,
 }
 
 static inline void
-elf_machine_rel_relative (Elf64_Addr l_addr, const Elf64_Rel *reloc,
-			  Elf64_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
+			   Elf64_Addr *const reloc_addr)
 {
   /* ??? Ignore MSB and Instruction format for now.  */
   assert (ELF64_R_TYPE (reloc->r_info) == R_IA64_REL64LSB);
--- libc/sysdeps/m68k/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/m68k/dl-machine.h	Fri Aug 24 14:34:52 2001
@@ -299,8 +299,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }
--- libc/sysdeps/mips/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/mips/dl-machine.h	Fri Aug 24 14:35:57 2001
@@ -536,8 +536,8 @@ elf_machine_rel (struct link_map *map, c
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rel_relative (ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
+			  ElfW(Addr) *const reloc_addr)
 {
   /* XXX Nothing to do.  There is no relative relocation, right?  */
 }
--- libc/sysdeps/mips/mips64/dl-machine.h.jj	Thu Aug 23 18:50:11 2001
+++ libc/sysdeps/mips/mips64/dl-machine.h	Fri Aug 24 14:45:12 2001
@@ -574,6 +574,13 @@ elf_machine_rel (struct link_map *map, c
 }
 
 static inline void
+elf_machine_rel_relative (ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
+			  ElfW(Addr) *const reloc_addr)
+{
+  /* XXX Nothing to do.  There is no relative relocation, right?  */
+}
+
+static inline void
 elf_machine_lazy_rel (struct link_map *map, ElfW(Addr) l_addr,
 		      const ElfW(Rel) *reloc)
 {
--- libc/sysdeps/powerpc/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/powerpc/dl-machine.h	Fri Aug 24 14:39:28 2001
@@ -394,8 +394,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }
--- libc/sysdeps/sparc/sparc32/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/sparc/sparc32/dl-machine.h	Fri Aug 24 14:39:58 2001
@@ -459,8 +459,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   *reloc_addr += l_addr + reloc->r_addend;
 }
--- libc/sysdeps/sparc/sparc64/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/sparc/sparc64/dl-machine.h	Fri Aug 24 14:41:14 2001
@@ -368,8 +368,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf64_Addr l_addr, const Elf64_Rel *reloc,
-			  Elf64_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
+			   Elf64_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }
--- libc/sysdeps/sh/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/sh/dl-machine.h	Fri Aug 24 14:42:26 2001
@@ -558,8 +558,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   if (reloc->r_addend)
     value = l_addr + reloc->r_addend;
--- libc/sysdeps/s390/s390-32/dl-machine.h.jj	Fri Aug 24 11:10:54 2001
+++ libc/sysdeps/s390/s390-32/dl-machine.h	Fri Aug 24 14:43:12 2001
@@ -440,8 +440,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
-			  Elf32_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
+			   Elf32_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }
--- libc/sysdeps/s390/s390-64/dl-machine.h.jj	Fri Aug 24 13:52:08 2001
+++ libc/sysdeps/s390/s390-64/dl-machine.h	Fri Aug 24 14:43:43 2001
@@ -420,8 +420,8 @@ elf_machine_rela (struct link_map *map, 
 }
 
 static inline void
-elf_machine_rel_relative (Elf64_Addr l_addr, const Elf64_Rel *reloc,
-			  Elf64_Addr *const reloc_addr)
+elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
+			   Elf64_Addr *const reloc_addr)
 {
   *reloc_addr = l_addr + reloc->r_addend;
 }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]