From 10a446ddcc1100d6d76c6aa0c6d4775209388152 Mon Sep 17 00:00:00 2001 From: "Maciej W. Rozycki" Date: Wed, 4 Apr 2018 23:09:37 +0100 Subject: [PATCH] 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 --- ChangeLog | 46 ++++++++++++++++++++++++++ elf/dl-runtime.c | 11 +++--- elf/dl-symaddr.c | 2 +- elf/rtld.c | 2 +- sysdeps/aarch64/dl-machine.h | 2 +- sysdeps/alpha/dl-machine.h | 2 +- sysdeps/arm/dl-machine.h | 6 ++-- sysdeps/generic/ldsodefs.h | 10 ++++-- sysdeps/hppa/dl-machine.h | 10 +++--- sysdeps/hppa/dl-symaddr.c | 2 +- sysdeps/i386/dl-machine.h | 4 +-- sysdeps/ia64/dl-machine.h | 2 +- sysdeps/m68k/dl-machine.h | 2 +- sysdeps/microblaze/dl-machine.h | 2 +- sysdeps/mips/dl-machine.h | 14 ++++---- sysdeps/mips/dl-trampoline.c | 4 +-- sysdeps/nios2/dl-machine.h | 2 +- sysdeps/powerpc/powerpc32/dl-machine.h | 2 +- sysdeps/powerpc/powerpc64/dl-machine.h | 3 +- sysdeps/riscv/dl-machine.h | 2 +- sysdeps/s390/s390-32/dl-machine.h | 2 +- sysdeps/s390/s390-64/dl-machine.h | 2 +- sysdeps/sh/dl-machine.h | 4 +-- sysdeps/sparc/sparc32/dl-machine.h | 2 +- sysdeps/sparc/sparc64/dl-machine.h | 2 +- sysdeps/tile/dl-machine.h | 2 +- sysdeps/x86_64/dl-machine.h | 3 +- 27 files changed, 97 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43e0d6b95f..74a0f6574d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,49 @@ +2018-04-04 Maciej W. Rozycki + + [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. + 2018-04-04 Zack Weinberg * sysdeps/generic/internal-signals.h: Include signal.h, diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index 61ef6d61ca..63bbc89776 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -124,14 +124,13 @@ _dl_fixup ( of the object that defines sym. Now add in the symbol offset. */ value = DL_FIXUP_MAKE_VALUE (result, - sym ? (LOOKUP_VALUE_ADDRESS (result) - + sym->st_value) : 0); + SYMBOL_ADDRESS (result, sym, false)); } else { /* We already found the symbol. The module (and therefore its load address) is also known. */ - value = DL_FIXUP_MAKE_VALUE (l, l->l_addr + sym->st_value); + value = DL_FIXUP_MAKE_VALUE (l, SYMBOL_ADDRESS (l, sym, true)); result = l; } @@ -241,9 +240,7 @@ _dl_profile_fixup ( of the object that defines sym. Now add in the symbol offset. */ value = DL_FIXUP_MAKE_VALUE (result, - defsym != NULL - ? LOOKUP_VALUE_ADDRESS (result) - + defsym->st_value : 0); + SYMBOL_ADDRESS (result, defsym, false)); if (defsym != NULL && __builtin_expect (ELFW(ST_TYPE) (defsym->st_info) @@ -254,7 +251,7 @@ _dl_profile_fixup ( { /* We already found the symbol. The module (and therefore its load address) is also known. */ - value = DL_FIXUP_MAKE_VALUE (l, l->l_addr + refsym->st_value); + value = DL_FIXUP_MAKE_VALUE (l, SYMBOL_ADDRESS (l, refsym, true)); if (__builtin_expect (ELFW(ST_TYPE) (refsym->st_info) == STT_GNU_IFUNC, 0)) diff --git a/elf/dl-symaddr.c b/elf/dl-symaddr.c index 0f16ab74e6..7f1ccc2516 100644 --- a/elf/dl-symaddr.c +++ b/elf/dl-symaddr.c @@ -22,7 +22,7 @@ void * _dl_symbol_address (struct link_map *map, const ElfW(Sym) *ref) { - ElfW(Addr) value = (map ? map->l_addr : 0) + ref->st_value; + ElfW(Addr) value = SYMBOL_ADDRESS (map, ref, false); /* Return the pointer to function descriptor. */ if (ELFW(ST_TYPE) (ref->st_info) == STT_FUNC) diff --git a/elf/rtld.c b/elf/rtld.c index f8d9597cdd..e7681ebb1f 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1916,7 +1916,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", NULL, ELF_RTYPE_CLASS_PLT, DL_LOOKUP_ADD_DEPENDENCY, NULL); - loadbase = LOOKUP_VALUE_ADDRESS (result); + loadbase = LOOKUP_VALUE_ADDRESS (result, false); _dl_printf ("%s found at 0x%0*Zd in object at 0x%0*Zd\n", _dl_argv[i], diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h index 7ce3c8eb8b..4935aa7c54 100644 --- a/sysdeps/aarch64/dl-machine.h +++ b/sysdeps/aarch64/dl-machine.h @@ -254,7 +254,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, { const ElfW(Sym) *const refsym = sym; struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - ElfW(Addr) value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + ElfW(Addr) value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC) diff --git a/sysdeps/alpha/dl-machine.h b/sysdeps/alpha/dl-machine.h index b9f6c29b05..810ca30fa4 100644 --- a/sysdeps/alpha/dl-machine.h +++ b/sysdeps/alpha/dl-machine.h @@ -419,7 +419,7 @@ elf_machine_rela (struct link_map *map, if (sym_map) { sym_raw_value += sym->st_value; - sym_value = sym_raw_value + sym_map->l_addr; + sym_value += SYMBOL_ADDRESS (sym_map, sym, true); } if (r_type == R_ALPHA_GLOB_DAT) diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h index 8a00eab5e3..1a4fd3f17b 100644 --- a/sysdeps/arm/dl-machine.h +++ b/sysdeps/arm/dl-machine.h @@ -392,7 +392,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc, { const Elf32_Sym *const refsym = sym; struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) @@ -452,7 +452,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc, binding found in the user program or a loaded library rather than the dynamic linker's built-in definitions used while loading those libraries. */ - value -= map->l_addr + refsym->st_value; + value -= SYMBOL_ADDRESS (map, refsym, true); # endif /* Support relocations on mis-aligned offsets. */ ((struct unaligned *) reloc_addr)->x += value; @@ -553,7 +553,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, const Elf32_Sym *const refsym = sym; # endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index e29e9d7ff0..3cac4fa362 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -66,14 +66,20 @@ __BEGIN_DECLS /* Result of the lookup functions and how to retrieve the base address. */ typedef struct link_map *lookup_t; #define LOOKUP_VALUE(map) map -#define LOOKUP_VALUE_ADDRESS(map) ((map) ? (map)->l_addr : 0) +#define LOOKUP_VALUE_ADDRESS(map, set) ((set) || (map) ? (map)->l_addr : 0) + +/* Calculate the address of symbol REF using the base address from map MAP, + if non-NULL. Don't check for NULL map if MAP_SET is TRUE. */ +#define SYMBOL_ADDRESS(map, ref, map_set) \ + ((ref) == NULL ? 0 \ + : LOOKUP_VALUE_ADDRESS (map, map_set) + (ref)->st_value) /* On some architectures a pointer to a function is not just a pointer to the actual code of the function but rather an architecture specific descriptor. */ #ifndef ELF_FUNCTION_PTR_IS_SPECIAL # define DL_SYMBOL_ADDRESS(map, ref) \ - (void *) (LOOKUP_VALUE_ADDRESS (map) + ref->st_value) + (void *) SYMBOL_ADDRESS (map, ref, false) # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr)) # define DL_CALL_DT_INIT(map, start, argc, argv, env) \ ((init_t) (start)) (argc, argv, env) diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h index 31c855bfb0..3a57c7eb9d 100644 --- a/sysdeps/hppa/dl-machine.h +++ b/sysdeps/hppa/dl-machine.h @@ -562,7 +562,7 @@ elf_machine_rela (struct link_map *map, if (sym_map) { - value = sym ? sym_map->l_addr + sym->st_value : 0; + value = SYMBOL_ADDRESS (sym_map, sym, true); value += reloc->r_addend; } else @@ -586,8 +586,8 @@ elf_machine_rela (struct link_map *map, case R_PARISC_DIR21L: { unsigned int insn = *(unsigned int *)reloc_addr; - value = sym_map->l_addr + sym->st_value - + ((reloc->r_addend + 0x1000) & -0x2000); + value = (SYMBOL_ADDRESS (sym_map, sym, true) + + ((reloc->r_addend + 0x1000) & -0x2000)); value = value >> 11; insn = (insn &~ 0x1fffff) | reassemble_21 (value); *(unsigned int *)reloc_addr = insn; @@ -597,8 +597,8 @@ elf_machine_rela (struct link_map *map, case R_PARISC_DIR14R: { unsigned int insn = *(unsigned int *)reloc_addr; - value = ((sym_map->l_addr + sym->st_value) & 0x7ff) - + (((reloc->r_addend & 0x1fff) ^ 0x1000) - 0x1000); + value = ((SYMBOL_ADDRESS (sym_map, sym, true) & 0x7ff) + + (((reloc->r_addend & 0x1fff) ^ 0x1000) - 0x1000)); insn = (insn &~ 0x3fff) | reassemble_14 (value); *(unsigned int *)reloc_addr = insn; } diff --git a/sysdeps/hppa/dl-symaddr.c b/sysdeps/hppa/dl-symaddr.c index aa5ac2f50d..4615dfc5b8 100644 --- a/sysdeps/hppa/dl-symaddr.c +++ b/sysdeps/hppa/dl-symaddr.c @@ -23,7 +23,7 @@ void * _dl_symbol_address (struct link_map *map, const ElfW(Sym) *ref) { /* Find the "ip" from the "map" and symbol "ref" */ - Elf32_Addr value = (map ? map->l_addr : 0) + ref->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (map, ref, false); /* On hppa, we have to return the pointer to function descriptor. This involves an "| 2" to inform $$dyncall that this is a plabel32 */ diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 3d6fb9b99f..1afdcbd9ea 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -320,7 +320,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc, const Elf32_Sym *const refsym = sym; # endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC) @@ -500,7 +500,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, const Elf32_Sym *const refsym = sym; # endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __glibc_likely (sym->st_shndx != SHN_UNDEF) diff --git a/sysdeps/ia64/dl-machine.h b/sysdeps/ia64/dl-machine.h index bc43a9d86e..61d7bb5795 100644 --- a/sysdeps/ia64/dl-machine.h +++ b/sysdeps/ia64/dl-machine.h @@ -419,7 +419,7 @@ elf_machine_rela (struct link_map *map, /* RESOLVE_MAP() will return NULL if it fail to locate the symbol. */ if ((sym_map = RESOLVE_MAP (&sym, version, r_type))) { - value = sym_map->l_addr + sym->st_value + reloc->r_addend; + value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend; if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_DIR64LSB)) ;/* No adjustment. */ diff --git a/sysdeps/m68k/dl-machine.h b/sysdeps/m68k/dl-machine.h index bb0f47eb57..8eb2295deb 100644 --- a/sysdeps/m68k/dl-machine.h +++ b/sysdeps/m68k/dl-machine.h @@ -229,7 +229,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, { const Elf32_Sym *const refsym = sym; struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); switch (r_type) { diff --git a/sysdeps/microblaze/dl-machine.h b/sysdeps/microblaze/dl-machine.h index 07f6b5cbf4..8480a7a34e 100644 --- a/sysdeps/microblaze/dl-machine.h +++ b/sysdeps/microblaze/dl-machine.h @@ -223,7 +223,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, { const Elf32_Sym *const refsym = sym; struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); value += reloc->r_addend; if (r_type == R_MICROBLAZE_GLOB_DAT || 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; diff --git a/sysdeps/nios2/dl-machine.h b/sysdeps/nios2/dl-machine.h index db2298fb74..1f57a343e0 100644 --- a/sysdeps/nios2/dl-machine.h +++ b/sysdeps/nios2/dl-machine.h @@ -250,7 +250,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, { const Elf32_Sym *const refsym = sym; struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); switch (r_type) { diff --git a/sysdeps/powerpc/powerpc32/dl-machine.h b/sysdeps/powerpc/powerpc32/dl-machine.h index bf57467695..31c7f3f95a 100644 --- a/sysdeps/powerpc/powerpc32/dl-machine.h +++ b/sysdeps/powerpc/powerpc32/dl-machine.h @@ -317,7 +317,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, else { 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); } value += reloc->r_addend; #else diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h index 7ca81f3e70..99a83d0c82 100644 --- a/sysdeps/powerpc/powerpc64/dl-machine.h +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -708,8 +708,7 @@ elf_machine_rela (struct link_map *map, /* We need SYM_MAP even in the absence of TLS, for elf_machine_fixup_plt and STT_GNU_IFUNC. */ struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf64_Addr value = ((sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value) - + reloc->r_addend); + Elf64_Addr value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend; if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index 9e3c2925f0..4cbde333ac 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -172,7 +172,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); ElfW(Addr) value = 0; if (sym_map != NULL) - value = sym_map->l_addr + sym->st_value + reloc->r_addend; + value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend; switch (r_type) { diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h index e2b6f72351..ded41adff8 100644 --- a/sysdeps/s390/s390-32/dl-machine.h +++ b/sysdeps/s390/s390-32/dl-machine.h @@ -358,7 +358,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, const Elf32_Sym *const refsym = sym; #endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h index c6e5be5419..f22db7860b 100644 --- a/sysdeps/s390/s390-64/dl-machine.h +++ b/sysdeps/s390/s390-64/dl-machine.h @@ -305,7 +305,7 @@ elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc, const Elf64_Sym *const refsym = sym; #endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - Elf64_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; + Elf64_Addr value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h index 3f157c9a7d..d85f40f1a7 100644 --- a/sysdeps/sh/dl-machine.h +++ b/sysdeps/sh/dl-machine.h @@ -320,7 +320,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, const Elf32_Sym *const refsym = sym; struct link_map *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); value += reloc->r_addend; switch (r_type) @@ -406,7 +406,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, binding found in the user program or a loaded library rather than the dynamic linker's built-in definitions used while loading those libraries. */ - value -= map->l_addr + refsym->st_value + reloc->r_addend; + value -= SYMBOL_ADDRESS (map, refsym, true) + reloc->r_addend; #endif COPY_UNALIGNED_WORD (&value, reloc_addr_arg, (int) reloc_addr_arg & 3); diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h index 88388f8192..042d02c7ca 100644 --- a/sysdeps/sparc/sparc32/dl-machine.h +++ b/sysdeps/sparc/sparc32/dl-machine.h @@ -382,7 +382,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, else { 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); } #else value = 0; diff --git a/sysdeps/sparc/sparc64/dl-machine.h b/sysdeps/sparc/sparc64/dl-machine.h index b914537493..cd6a6996cb 100644 --- a/sysdeps/sparc/sparc64/dl-machine.h +++ b/sysdeps/sparc/sparc64/dl-machine.h @@ -409,7 +409,7 @@ elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc, else { 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); } #else value = 0; diff --git a/sysdeps/tile/dl-machine.h b/sysdeps/tile/dl-machine.h index 9e36ee9820..d615447a20 100644 --- a/sysdeps/tile/dl-machine.h +++ b/sysdeps/tile/dl-machine.h @@ -430,7 +430,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, else if (ELFW_ST_TYPE (sym->st_info) == STT_SECTION) value = map->l_addr; /* like a RELATIVE reloc */ else - value = sym_map->l_addr + sym->st_value; + value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 2201818aa6..1942ed5061 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -306,8 +306,7 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, const ElfW(Sym) *const refsym = sym; # endif struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); - ElfW(Addr) value = (sym == NULL ? 0 - : (ElfW(Addr)) sym_map->l_addr + sym->st_value); + ElfW(Addr) value = SYMBOL_ADDRESS (sym_map, sym, true); if (sym != NULL && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)