the same file. */
if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
- DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr,
+ DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
argc, argv, env);
ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
{
unsigned int jm
= l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
- elfptr_t *addrs = (void *) (init_array->d_un.d_ptr + l->l_addr);
+ elfptr_t *addrs = (void *) dl_rx_ptr (l, init_array->d_un.d_ptr);
for (unsigned int j = 0; j < jm; ++j)
((dl_init_t) addrs[j]) (argc, argv, env);
}
/* Remember the values we need. */
memsz = phdr->p_memsz;
filesz = phdr->p_filesz;
- initimage = phdr->p_vaddr + (void *) main_map->l_addr;
+ initimage = (void *) dl_rx_ptr (main_map, phdr->p_vaddr);
align = phdr->p_align;
if (phdr->p_align > max_align)
max_align = phdr->p_align;
if (map->l_info[DT_FINI_ARRAY] != NULL)
{
elfptr_t *array =
- (elfptr_t *) (map->l_addr
- + map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+ (elfptr_t *) dl_rx_ptr (map, map->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
unsigned int sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
/ sizeof (elfptr_t));
/* Next try the old-style destructor. */
if (map->l_info[DT_FINI] != NULL)
- DL_CALL_DT_FINI (map, ((void *) map->l_addr
- + map->l_info[DT_FINI]->d_un.d_ptr));
+ DL_CALL_DT_FINI (map, dl_rx_ptr (map, map->l_info[DT_FINI]->d_un.d_ptr));
}
void
if (ph->p_type == DLFO_EH_SEGMENT_TYPE)
{
atomic_store_relaxed (&result->eh_frame,
- (void *) (ph->p_vaddr + l->l_addr));
+ (void *) dl_rx_ptr (l, ph->p_vaddr));
#if DLFO_STRUCT_HAS_EH_COUNT
atomic_store_relaxed (&result->eh_count, ph->p_memsz / 8);
#endif
/* First see whether an array is given. */
if (l->l_info[DT_FINI_ARRAY] != NULL)
{
- elfptr_t *array =
- (elfptr_t *) (l->l_addr
- + l->l_info[DT_FINI_ARRAY]->d_un.d_ptr);
+ ElfW(Addr) v = l->l_info[DT_FINI_ARRAY]->d_un.d_ptr;
+ elfptr_t *array = (elfptr_t *) dl_rx_ptr (l, v);
unsigned int i = (l->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
/ sizeof (elfptr_t));
while (i-- > 0)
/* Next try the old-style destructor. */
if (ELF_INITFINI && l->l_info[DT_FINI] != NULL)
DL_CALL_DT_FINI
- (l, l->l_addr + l->l_info[DT_FINI]->d_un.d_ptr);
+ (l, dl_rx_ptr (l, l->l_info[DT_FINI]->d_un.d_ptr));
}
#ifdef SHARED
- the others in the DT_INIT_ARRAY.
*/
if (ELF_INITFINI && l->l_info[DT_INIT] != NULL)
- DL_CALL_DT_INIT(l, l->l_addr + l->l_info[DT_INIT]->d_un.d_ptr, argc, argv, env);
+ DL_CALL_DT_INIT(l, dl_rx_ptr (l, l->l_info[DT_INIT]->d_un.d_ptr),
+ argc, argv, env);
/* Next see whether there is an array with initialization functions. */
ElfW(Dyn) *init_array = l->l_info[DT_INIT_ARRAY];
jm = l->l_info[DT_INIT_ARRAYSZ]->d_un.d_val / sizeof (elfptr_t);
- addrs = (elfptr_t *) (init_array->d_un.d_ptr + l->l_addr);
+ addrs = (elfptr_t *) dl_rx_ptr (l, init_array->d_un.d_ptr);
for (j = 0; j < jm; ++j)
((dl_init_t) addrs[j]) (argc, argv, env);
}
_dl_debug_printf ("\ncalling preinit: %s\n\n",
DSO_FILENAME (main_map->l_name));
- addrs = (elfptr_t *) (preinit_array->d_un.d_ptr + main_map->l_addr);
+ addrs = (elfptr_t *) dl_rx_ptr (main_map, preinit_array->d_un.d_ptr);
for (cnt = 0; cnt < i; ++cnt)
((dl_init_t) addrs[cnt]) (argc, argv, env);
}
void
_dl_process_pt_gnu_property (struct link_map *l, int fd, const ElfW(Phdr) *ph)
{
- const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
+ const ElfW(Nhdr) *note = (const void *) dl_rx_ptr (l, ph->p_vaddr);
const ElfW(Addr) size = ph->p_memsz;
const ElfW(Addr) align = ph->p_align;
}
else
/* Adjust the PT_PHDR value by the runtime load address. */
- l->l_phdr = (ElfW(Phdr) *) ((ElfW(Addr)) l->l_phdr + l->l_addr);
+ l->l_phdr = (ElfW(Phdr) *) dl_rx_ptr (l, (ElfW(Addr)) l->l_phdr);
if (__glibc_unlikely ((stack_flags &~ GL(dl_stack_flags)) & PF_X))
{
/* Adjust the address of the TLS initialization image. */
if (l->l_tls_initimage != NULL)
- l->l_tls_initimage = (ElfW(Addr)) l->l_tls_initimage + (char *) l->l_addr;
+ l->l_tls_initimage
+ = (void *) dl_rw_ptr (l, (ElfW(Addr)) l->l_tls_initimage);
/* Process program headers again after load segments are mapped in
case processing requires accessing those segments. Scan program
/* If this is ET_EXEC, we should have loaded it as lt_executable. */
assert (type != ET_EXEC || l->l_type == lt_executable);
- l->l_entry += l->l_addr;
+ l->l_entry = dl_rx_ptr (l, l->l_entry);
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
_dl_debug_printf ("\
void
_dl_protect_relro (struct link_map *l)
{
- elfptr_t start = ALIGN_DOWN((l->l_addr
- + l->l_relro_addr),
+ elfptr_t start = ALIGN_DOWN(dl_rx_ptr (l, l->l_relro_addr),
GLRO(dl_pagesize));
elfptr_t end = ALIGN_DOWN((l->l_addr
+ l->l_relro_addr
+ reloc_offset (pltgot, reloc_arg));
const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)];
const ElfW(Sym) *refsym = sym;
- void *const rel_addr = (void *)(l->l_addr + reloc->r_offset);
+ void *const rel_addr = (void *) dl_rw_ptr (l, reloc->r_offset);
lookup_t result;
DL_FIXUP_VALUE_TYPE value;
def_offset = map->l_info[VERSYMIDX (DT_VERDEF)]->d_un.d_ptr;
assert (def_offset != 0);
- def = (ElfW(Verdef) *) ((char *) map->l_addr + def_offset);
+ def = (ElfW(Verdef) *) dl_rx_ptr (map, def_offset);
while (1)
{
/* Currently the version number of the definition entry is 1.
if (dyn != NULL)
{
/* This file requires special versions from its dependencies. */
- ElfW(Verneed) *ent = (ElfW(Verneed) *) (map->l_addr + dyn->d_un.d_ptr);
+ ElfW(Verneed) *ent = (ElfW(Verneed) *) dl_rx_ptr (map, dyn->d_un.d_ptr);
/* Currently the version number of the needed entry is 1.
Make sure all we see is this version. */
if (def != NULL)
{
ElfW(Verdef) *ent;
- ent = (ElfW(Verdef) *) (map->l_addr + def->d_un.d_ptr);
+ ent = (ElfW(Verdef) *) dl_rx_ptr (map, def->d_un.d_ptr);
while (1)
{
if ((unsigned int) (ent->vd_ndx & 0x7fff) > ndx_high)
if (dyn != NULL)
{
ElfW(Verneed) *ent;
- ent = (ElfW(Verneed) *) (map->l_addr + dyn->d_un.d_ptr);
+ ent = (ElfW(Verneed) *) dl_rx_ptr (map, dyn->d_un.d_ptr);
while (1)
{
ElfW(Vernaux) *aux;
if (def != NULL)
{
ElfW(Verdef) *ent;
- ent = (ElfW(Verdef) *) (map->l_addr + def->d_un.d_ptr);
+ ent = (ElfW(Verdef) *) dl_rx_ptr (map, def->d_un.d_ptr);
while (1)
{
ElfW(Verdaux) *aux;
{
ElfW (Half) ndx = version[ELFW (R_SYM) (r->r_info)] & 0x7fff;
const ElfW (Sym) *sym = &symtab[ELFW (R_SYM) (r->r_info)];
- void *const r_addr_arg = (void *) (l_addr + r->r_offset);
+ void *const r_addr_arg = (void *) dl_rw_ptr (map, r->r_offset);
const struct r_found_version *rversion = &map->l_versions[ndx];
elf_machine_rel (map, scope, r, sym, rversion, r_addr_arg, skip_ifunc);
{
ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (r->r_info)];
- void *const r_addr_arg = (void *) (l_addr + r->r_offset);
+ void *const r_addr_arg = (void *) dl_rw_ptr (map, r->r_offset);
const struct r_found_version *rversion = &map->l_versions[ndx];
#if defined ELF_MACHINE_IRELATIVE
if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
elf_machine_rel (map, scope, r2,
&symtab[ELFW(R_SYM) (r2->r_info)],
&map->l_versions[ndx],
- (void *) (l_addr + r2->r_offset),
+ (void *) dl_rw_ptr (map, r2->r_offset),
skip_ifunc);
}
#endif
for (; r < end; ++r)
{
const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (r->r_info)];
- void *const r_addr_arg = (void *) (l_addr + r->r_offset);
+ void *const r_addr_arg = (void *) dl_rw_ptr (map, r->r_offset);
# ifdef ELF_MACHINE_IRELATIVE
if (ELFW(R_TYPE) (r->r_info) == ELF_MACHINE_IRELATIVE)
{
for (; r2 <= end2; ++r2)
if (ELFW(R_TYPE) (r2->r_info) == ELF_MACHINE_IRELATIVE)
elf_machine_rel (map, scope, r2, &symtab[ELFW(R_SYM) (r2->r_info)],
- NULL, (void *) (l_addr + r2->r_offset),
+ NULL, (void *) dl_rw_ptr (map, r2->r_offset),
skip_ifunc);
# endif
}
/* The file has no symbol versioning. */
return 0;
- def = (ElfW(Verdef) *) ((char *) map->l_addr
- + map->l_info[VERDEFTAG]->d_un.d_ptr);
+ def = (ElfW(Verdef) *) dl_rx_ptr (map, map->l_info[VERDEFTAG]->d_un.d_ptr);
while (1)
{
ElfW(Verdaux) *aux = (ElfW(Verdaux) *) ((char *) def + def->vd_aux);
dlopen call or DT_NEEDED entry, for something that wants to link
against the dynamic linker as a shared library, will know that
the shared object is already loaded. */
- _dl_rtld_libname.name = ((const char *) main_map->l_addr
- + ph->p_vaddr);
+ _dl_rtld_libname.name = (const char *) dl_rx_ptr (main_map,
+ ph->p_vaddr);
/* _dl_rtld_libname.next = NULL; Already zero. */
GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
the executable is actually an ET_DYN object. */
if (main_map->l_tls_initimage != NULL)
main_map->l_tls_initimage
- = (ElfW(Addr)) main_map->l_tls_initimage + (char *) main_map->l_addr;
+ = (void *) dl_rx_ptr (main_map, (ElfW(Addr)) main_map->l_tls_initimage);
if (! main_map->l_map_end)
main_map->l_map_end = ~0;
if (! main_map->l_text_end)
continue;
strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
- ent = (ElfW(Verneed) *) (map->l_addr + dyn->d_un.d_ptr);
+ ent = (ElfW(Verneed) *) dl_rx_ptr (map, dyn->d_un.d_ptr);
if (first)
{
most architectures the entry is already relocated - but for some not
and we need to relocate at access time. */
#define D_PTR(map, i) \
- ((map)->i->d_un.d_ptr + (dl_relocate_ld (map) ? 0 : (map)->l_addr))
+ (dl_relocate_ld (map) ? (map)->i->d_un.d_ptr \
+ : dl_rx_ptr ((map), (map)->i->d_un.d_ptr))
/* Result of the lookup functions and how to retrieve the base address. */
typedef struct link_map *lookup_t;