about summary refs log tree commit diff
path: root/sysdeps/mips
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@mips.com>2018-04-04 23:09:37 +0100
committerMaciej W. Rozycki <macro@mips.com>2018-04-04 23:09:37 +0100
commit10a446ddcc1100d6d76c6aa0c6d4775209388152 (patch)
tree4e12e65abcc8f27e911598681e29d91d9838595e /sysdeps/mips
parent9185f86d8ffb37defdbea6ef616338106de6c2c8 (diff)
downloadglibc-10a446ddcc1100d6d76c6aa0c6d4775209388152.tar.gz
glibc-10a446ddcc1100d6d76c6aa0c6d4775209388152.tar.xz
glibc-10a446ddcc1100d6d76c6aa0c6d4775209388152.zip
elf: Unify symbol address run-time calculation [BZ #19818]
Wrap symbol address run-time calculation into a macro and use it
throughout, replacing inline calculations.

There are a couple of variants, most of them different in a functionally
insignificant way.  Most calculations are right following RESOLVE_MAP,
at which point either the map or the symbol returned can be checked for
validity as the macro sets either both or neither.  In some places both
the symbol and the map has to be checked however.

My initial implementation therefore always checked both, however that
resulted in code larger by as much as 0.3%, as many places know from
elsewhere that no check is needed.  I have decided the size growth was
unacceptable.

Having looked closer I realized that it's the map that is the culprit.
Therefore I have modified LOOKUP_VALUE_ADDRESS to accept an additional
boolean argument telling it to access the map without checking it for
validity.  This in turn has brought quite nice results, with new code
actually being smaller for i686, and MIPS o32, n32 and little-endian n64
targets, unchanged in size for x86-64 and, unusually, marginally larger
for big-endian MIPS n64, as follows:

i686:
   text    data     bss     dec     hex filename
 152255    4052     192  156499   26353 ld-2.27.9000-base.so
 152159    4052     192  156403   262f3 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/el:
   text    data     bss     dec     hex filename
 142906    4396     260  147562   2406a ld-2.27.9000-base.so
 142890    4396     260  147546   2405a ld-2.27.9000-elf-symbol-value.so
MIPS/n32/el:
   text    data     bss     dec     hex filename
 142267    4404     260  146931   23df3 ld-2.27.9000-base.so
 142171    4404     260  146835   23d93 ld-2.27.9000-elf-symbol-value.so
MIPS/n64/el:
   text    data     bss     dec     hex filename
 149835    7376     408  157619   267b3 ld-2.27.9000-base.so
 149787    7376     408  157571   26783 ld-2.27.9000-elf-symbol-value.so
MIPS/o32/eb:
   text    data     bss     dec     hex filename
 142870    4396     260  147526   24046 ld-2.27.9000-base.so
 142854    4396     260  147510   24036 ld-2.27.9000-elf-symbol-value.so
MIPS/n32/eb:
   text    data     bss     dec     hex filename
 142019    4404     260  146683   23cfb ld-2.27.9000-base.so
 141923    4404     260  146587   23c9b ld-2.27.9000-elf-symbol-value.so
MIPS/n64/eb:
   text    data     bss     dec     hex filename
 149763    7376     408  157547   2676b ld-2.27.9000-base.so
 149779    7376     408  157563   2677b ld-2.27.9000-elf-symbol-value.so
x86-64:
   text    data     bss     dec     hex filename
 148462    6452     400  155314   25eb2 ld-2.27.9000-base.so
 148462    6452     400  155314   25eb2 ld-2.27.9000-elf-symbol-value.so

	[BZ #19818]
	* sysdeps/generic/ldsodefs.h (LOOKUP_VALUE_ADDRESS): Add `set'
	parameter.
	(SYMBOL_ADDRESS): New macro.
	[!ELF_FUNCTION_PTR_IS_SPECIAL] (DL_SYMBOL_ADDRESS): Use
	SYMBOL_ADDRESS for symbol address calculation.
	* elf/dl-runtime.c (_dl_fixup): Likewise.
	(_dl_profile_fixup): Likewise.
	* elf/dl-symaddr.c (_dl_symbol_address): Likewise.
	* elf/rtld.c (dl_main): Likewise.
	* sysdeps/aarch64/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/arm/dl-machine.h (elf_machine_rel): Likewise.
	(elf_machine_rela): Likewise.
	* sysdeps/hppa/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/hppa/dl-symaddr.c (_dl_symbol_address): Likewise.
	* sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise.
	(elf_machine_rela): Likewise.
	* sysdeps/ia64/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/m68k/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/microblaze/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/mips/dl-machine.h (ELF_MACHINE_BEFORE_RTLD_RELOC):
	Likewise.
	(elf_machine_reloc): Likewise.
	(elf_machine_got_rel): Likewise.
	* sysdeps/mips/dl-trampoline.c (__dl_runtime_resolve): Likewise.
	* sysdeps/nios2/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/riscv/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela):
	Likewise.
	* sysdeps/tile/dl-machine.h (elf_machine_rela): Likewise.
	* sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/mips')
-rw-r--r--sysdeps/mips/dl-machine.h14
-rw-r--r--sysdeps/mips/dl-trampoline.c4
2 files changed, 9 insertions, 9 deletions
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index 72165722d4..91fc640388 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -220,7 +220,7 @@ do {									\
   while (i--)								\
     {									\
       if (sym->st_shndx == SHN_UNDEF || sym->st_shndx == SHN_COMMON)	\
-	*got = map->l_addr + sym->st_value;				\
+	*got = SYMBOL_ADDRESS (map, sym, true);				\
       else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC			\
 	       && *got != sym->st_value)				\
 	*got += map->l_addr;						\
@@ -230,7 +230,7 @@ do {									\
 	    *got += map->l_addr;					\
 	}								\
       else								\
-	*got = map->l_addr + sym->st_value;				\
+	*got = SYMBOL_ADDRESS (map, sym, true);				\
 									\
       got++;								\
       sym++;								\
@@ -598,7 +598,7 @@ elf_machine_reloc (struct link_map *map, ElfW(Addr) r_info,
 #ifndef RTLD_BOOTSTRAP
 		if (map != &GL(dl_rtld_map))
 #endif
-		  reloc_value += sym->st_value + map->l_addr;
+		  reloc_value += SYMBOL_ADDRESS (map, sym, true);
 	      }
 	    else
 	      {
@@ -663,7 +663,7 @@ elf_machine_reloc (struct link_map *map, ElfW(Addr) r_info,
 			    "found jump slot relocation with non-zero addend");
 
 	sym_map = RESOLVE_MAP (&sym, version, r_type);
-	value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
+	value = SYMBOL_ADDRESS (sym_map, sym, true);
 	*addr_field = value;
 
 	break;
@@ -677,7 +677,7 @@ elf_machine_reloc (struct link_map *map, ElfW(Addr) r_info,
 
 	/* Calculate the address of the symbol.  */
 	sym_map = RESOLVE_MAP (&sym, version, r_type);
-	value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
+	value = SYMBOL_ADDRESS (sym_map, sym, true);
 
 	if (__builtin_expect (sym == NULL, 0))
 	  /* This can happen in trace mode if an object could not be
@@ -798,7 +798,7 @@ elf_machine_got_rel (struct link_map *map, int lazy)
 	= vernum ? &map->l_versions[vernum[sym_index] & 0x7fff] : NULL;	  \
       struct link_map *sym_map;						  \
       sym_map = RESOLVE_MAP (&ref, version, reloc);			  \
-      ref ? sym_map->l_addr + ref->st_value : 0;			  \
+      SYMBOL_ADDRESS (sym_map, ref, true);				  \
     })
 
   if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
@@ -842,7 +842,7 @@ elf_machine_got_rel (struct link_map *map, int lazy)
 	      && !(sym->st_other & STO_MIPS_PLT))
 	    {
 	      if (lazy)
-		*got = sym->st_value + map->l_addr;
+		*got = SYMBOL_ADDRESS (map, sym, true);
 	      else
 		/* This is a lazy-binding stub, so we don't need the
 		   canonical address.  */
diff --git a/sysdeps/mips/dl-trampoline.c b/sysdeps/mips/dl-trampoline.c
index 4546d07272..35b6b93a89 100644
--- a/sysdeps/mips/dl-trampoline.c
+++ b/sysdeps/mips/dl-trampoline.c
@@ -192,12 +192,12 @@ __dl_runtime_resolve (ElfW(Word) sym_index,
 
       /* Currently value contains the base load address of the object
 	 that defines sym.  Now add in the symbol offset.  */
-      value = (sym ? sym_map->l_addr + sym->st_value : 0);
+      value = SYMBOL_ADDRESS (sym_map, sym, true);
     }
   else
     /* We already found the symbol.  The module (and therefore its load
        address) is also known.  */
-    value = l->l_addr + sym->st_value;
+    value = SYMBOL_ADDRESS (l, sym, true);
 
   /* Apply the relocation with that value.  */
   *(got + local_gotno + sym_index - gotsym) = value;