summaryrefslogtreecommitdiff
path: root/ldso
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-07-05 23:21:22 +0000
committerMike Frysinger <vapier@gentoo.org>2006-07-05 23:21:22 +0000
commit47319595bdfdc0dfc8eb5f51bc8bd055a6ea0a7f (patch)
tree2ba1a4c78410fcb692dad3b6ce01ca1bf3cbb2a4 /ldso
parent9aa22cc9745be04035873b26f82adc4581e602b4 (diff)
patch from Bernd Schmidt to abstract away initializing of relocation addresses
Diffstat (limited to 'ldso')
-rw-r--r--ldso/include/dl-defs.h33
-rw-r--r--ldso/include/dl-elf.h2
-rw-r--r--ldso/ldso/dl-elf.c23
-rw-r--r--ldso/ldso/dl-hash.c6
-rw-r--r--ldso/ldso/dl-startup.c10
-rw-r--r--ldso/ldso/ldso.c44
-rw-r--r--ldso/libdl/libdl.c12
7 files changed, 84 insertions, 46 deletions
diff --git a/ldso/include/dl-defs.h b/ldso/include/dl-defs.h
index db65f78f6..932f6ac53 100644
--- a/ldso/include/dl-defs.h
+++ b/ldso/include/dl-defs.h
@@ -75,6 +75,14 @@ typedef struct {
# define DL_LOADADDR_TYPE ElfW(Addr)
#endif
+/* When DL_LOADADDR_TYPE is not a scalar value, or some different
+ * computation is needed to relocate an address, define this.
+ */
+#ifndef DL_RELOC_ADDR
+# define DL_RELOC_ADDR(LOADADDR, ADDR) \
+ ((LOADADDR) + (ADDR))
+#endif
+
/* Initialize a LOADADDR representing the loader itself. It's only
* called from DL_BOOT, so additional arguments passed to it may be
* referenced.
@@ -84,6 +92,24 @@ typedef struct {
((LOADADDR) = (BASEADDR))
#endif
+/* Define if any declarations/definitions of local variables are
+ * needed in a function that calls DT_INIT_LOADADDR or
+ * DL_INIT_LOADADDR_HDR. Declarations must be properly terminated
+ * with a semicolon, and non-declaration statements are forbidden.
+ */
+#ifndef DL_INIT_LOADADDR_EXTRA_DECLS
+# define DL_INIT_LOADADDR_EXTRA_DECLS /* int i; */
+#endif
+
+/* Prepare a DL_LOADADDR_TYPE data structure for incremental
+ * initialization with DL_INIT_LOADADDR_HDR, given pointers to a base
+ * load address and to program headers.
+ */
+#ifndef DL_INIT_LOADADDR
+# define DL_INIT_LOADADDR(LOADADDR, BASEADDR, PHDR, PHDRCNT) \
+ ((LOADADDR) = (BASEADDR))
+#endif
+
/* Initialize a LOADADDR representing the program. It's called from
* DL_BOOT only.
*/
@@ -92,6 +118,13 @@ typedef struct {
((LOADADDR) = (DL_LOADADDR_TYPE)(BASEADDR))
#endif
+/* Convert a DL_LOADADDR_TYPE to an identifying pointer. Used mostly
+ * for debugging.
+ */
+#ifndef DL_LOADADDR_BASE
+# define DL_LOADADDR_BASE(LOADADDR) (LOADADDR)
+#endif
+
/* Test whether a given ADDR is more likely to be within the memory
* region mapped to TPNT (a struct elf_resolve *) than to TFROM.
* Everywhere that this is used, TFROM is initially NULL, and whenever
diff --git a/ldso/include/dl-elf.h b/ldso/include/dl-elf.h
index 7b609d592..9d8da0d13 100644
--- a/ldso/include/dl-elf.h
+++ b/ldso/include/dl-elf.h
@@ -141,7 +141,7 @@ void __dl_parse_dynamic_info(ElfW(Dyn) *dpnt, unsigned long dynamic_info[],
#define ADJUST_DYN_INFO(tag, load_off) \
do { \
if (dynamic_info[tag]) \
- dynamic_info[tag] += load_off; \
+ dynamic_info[tag] = (unsigned long) DL_RELOC_ADDR(load_off, dynamic_info[tag]); \
} while(0)
ADJUST_DYN_INFO(DT_HASH, load_off);
ADJUST_DYN_INFO(DT_PLTGOT, load_off);
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 923e0cfe7..443b0802e 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -118,9 +118,9 @@ int _dl_unmap_cache(void)
void
_dl_protect_relro (struct elf_resolve *l)
{
- ElfW(Addr) start = ((l->loadaddr + l->relro_addr)
+ ElfW(Addr) start = (DL_RELOC_ADDR(l->loadaddr, l->relro_addr)
& ~(_dl_pagesize - 1));
- ElfW(Addr) end = ((l->loadaddr + l->relro_addr + l->relro_size)
+ ElfW(Addr) end = ((DL_RELOC_ADDR(l->loadaddr, l->relro_addr) + l->relro_size)
& ~(_dl_pagesize - 1));
_dl_if_debug_dprint("RELRO protecting %s: start:%x, end:%x\n", l->libname, start, end);
if (start != end &&
@@ -352,8 +352,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
ElfW(Addr) relro_addr = 0;
size_t relro_size = 0;
struct stat st;
+ DL_LOADADDR_TYPE lib_loadaddr;
+ DL_INIT_LOADADDR_EXTRA_DECLS
- libaddr = 0;
infile = _dl_open(libname, O_RDONLY, 0);
if (infile < 0) {
_dl_internal_error_number = LD_ERROR_NOFILE;
@@ -471,6 +472,8 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
/* Get the memory to store the library */
ppnt = (ElfW(Phdr) *)(intptr_t) & header[epnt->e_phoff];
+ DL_INIT_LOADADDR(lib_loadaddr, libaddr, ppnt, epnt->e_phnum);
+
for (i = 0; i < epnt->e_phnum; i++) {
if (ppnt->p_type == PT_GNU_RELRO) {
relro_addr = ppnt->p_vaddr;
@@ -547,7 +550,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
/* For a non-PIC library, the addresses are all absolute */
if (piclib) {
- dynamic_addr += (unsigned long) libaddr;
+ dynamic_addr = (unsigned long) DL_RELOC_ADDR(lib_loadaddr, dynamic_addr);
}
/*
@@ -567,7 +570,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
dpnt = (ElfW(Dyn) *) dynamic_addr;
_dl_memset(dynamic_info, 0, sizeof(dynamic_info));
- _dl_parse_dynamic_info(dpnt, dynamic_info, NULL, libaddr);
+ _dl_parse_dynamic_info(dpnt, dynamic_info, NULL, lib_loadaddr);
/* If the TEXTREL is set, this means that we need to make the pages
writable before we perform relocations. Do this now. They get set
back again later. */
@@ -588,13 +591,13 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
#endif
}
- tpnt = _dl_add_elf_hash_table(libname, libaddr, dynamic_info,
+ tpnt = _dl_add_elf_hash_table(libname, lib_loadaddr, dynamic_info,
dynamic_addr, 0);
tpnt->relro_addr = relro_addr;
tpnt->relro_size = relro_size;
tpnt->st_dev = st.st_dev;
tpnt->st_ino = st.st_ino;
- tpnt->ppnt = (ElfW(Phdr) *)(intptr_t) (tpnt->loadaddr + epnt->e_phoff);
+ tpnt->ppnt = (ElfW(Phdr) *) DL_RELOC_ADDR(tpnt->loadaddr, epnt->e_phoff);
tpnt->n_phent = epnt->e_phnum;
/*
@@ -625,9 +628,9 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
}
_dl_if_debug_dprint("\n\tfile='%s'; generating link map\n", libname);
- _dl_if_debug_dprint("\t\tdynamic: %x base: %x\n", dynamic_addr, libaddr);
+ _dl_if_debug_dprint("\t\tdynamic: %x base: %x\n", dynamic_addr, DL_LOADADDR_BASE(libaddr));
_dl_if_debug_dprint("\t\t entry: %x phdr: %x phnum: %x\n\n",
- epnt->e_entry + libaddr, tpnt->ppnt, tpnt->n_phent);
+ DL_RELOC_ADDR(lib_loadaddr, epnt->e_entry), tpnt->ppnt, tpnt->n_phent);
_dl_munmap(header, _dl_pagesize);
@@ -819,7 +822,7 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void
int ret = 0;
for (l = _dl_loaded_modules; l != NULL; l = l->next) {
- info.dlpi_addr = l->loadaddr;
+ info.dlpi_addr = DL_LOADADDR_BASE(l->loadaddr);
info.dlpi_name = l->libname;
info.dlpi_phdr = l->ppnt;
info.dlpi_phnum = l->n_phent;
diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c
index ccf191a70..4fd7ba0b7 100644
--- a/ldso/ldso/dl-hash.c
+++ b/ldso/ldso/dl-hash.c
@@ -163,7 +163,7 @@ char *_dl_find_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *
/* Avoid calling .urem here. */
do_rem(hn, elf_hash_number, tpnt->nbucket);
- symtab = (ElfW(Sym) *) (intptr_t) (tpnt->dynamic_info[DT_SYMTAB]);
+ symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB];
strtab = (char *) (tpnt->dynamic_info[DT_STRTAB]);
for (si = tpnt->elf_buckets[hn]; si != STN_UNDEF; si = tpnt->chains[si]) {
@@ -184,11 +184,11 @@ char *_dl_find_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *
/* Perhaps we should support old style weak symbol handling
* per what glibc does when you export LD_DYNAMIC_WEAK */
if (!weak_result)
- weak_result = (char *)tpnt->loadaddr + sym->st_value;
+ weak_result = (char *) DL_RELOC_ADDR(tpnt->loadaddr, sym->st_value);
break;
#endif
case STB_GLOBAL:
- return (char*)tpnt->loadaddr + sym->st_value;
+ return (char*) DL_RELOC_ADDR(tpnt->loadaddr, sym->st_value);
default: /* Local symbols not handled here */
break;
}
diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
index 4115f299c..a3764449e 100644
--- a/ldso/ldso/dl-startup.c
+++ b/ldso/ldso/dl-startup.c
@@ -186,14 +186,14 @@ static void * __attribute_used__ _dl_start(unsigned long args)
_dl_exit(0);
}
SEND_STDERR_DEBUG("ELF header=");
- SEND_ADDRESS_STDERR_DEBUG(load_addr, 1);
+ SEND_ADDRESS_STDERR_DEBUG(DL_LOADADDR_BASE(load_addr), 1);
/* Locate the global offset table. Since this code must be PIC
* we can take advantage of the magic offset register, if we
* happen to know what that is for this architecture. If not,
* we can always read stuff out of the ELF file to find it... */
got = elf_machine_dynamic();
- dpnt = (ElfW(Dyn) *) (got + load_addr);
+ dpnt = (ElfW(Dyn) *) DL_RELOC_ADDR(load_addr, got);
SEND_STDERR_DEBUG("First Dynamic section entry=");
SEND_ADDRESS_STDERR_DEBUG(dpnt, 1);
_dl_memset(tpnt, 0, sizeof(struct elf_resolve));
@@ -259,9 +259,9 @@ static void * __attribute_used__ _dl_start(unsigned long args)
rel_addr += relative_count * sizeof(ELF_RELOC);
}
- rpnt = (ELF_RELOC *) (rel_addr + load_addr);
+ rpnt = (ELF_RELOC *) DL_RELOC_ADDR(load_addr, rel_addr);
for (i = 0; i < rel_size; i += sizeof(ELF_RELOC), rpnt++) {
- reloc_addr = (unsigned long *) (load_addr + (unsigned long) rpnt->r_offset);
+ reloc_addr = (unsigned long *) DL_RELOC_ADDR(load_addr, (unsigned long)rpnt->r_offset);
symtab_index = ELF_R_SYM(rpnt->r_info);
symbol_addr = 0;
sym = NULL;
@@ -272,7 +272,7 @@ static void * __attribute_used__ _dl_start(unsigned long args)
symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB];
strtab = (char *) tpnt->dynamic_info[DT_STRTAB];
sym = &symtab[symtab_index];
- symbol_addr = load_addr + sym->st_value;
+ symbol_addr = (unsigned long) DL_RELOC_ADDR(load_addr, sym->st_value);
SEND_STDERR_DEBUG("relocating symbol: ");
SEND_STDERR_DEBUG(strtab + sym->st_name);
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index a6209678e..d5b87d5eb 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -109,7 +109,7 @@ static void _dl_run_array_forward(unsigned long array, unsigned long size,
unsigned int jm;
ElfW(Addr) *addrs;
jm = size / sizeof (ElfW(Addr));
- addrs = (ElfW(Addr) *) (array + loadaddr);
+ addrs = (ElfW(Addr) *) DL_RELOC_ADDR(loadaddr, array);
for (j = 0; j < jm; ++j) {
void (*dl_elf_func) (void);
dl_elf_func = (void (*)(void)) (intptr_t) addrs[j];
@@ -136,7 +136,7 @@ void _dl_run_fini_array(struct elf_resolve *tpnt);
void _dl_run_fini_array(struct elf_resolve *tpnt)
{
if (tpnt->dynamic_info[DT_FINI_ARRAY]) {
- ElfW(Addr) *array = (ElfW(Addr) *) (tpnt->loadaddr + tpnt->dynamic_info[DT_FINI_ARRAY]);
+ ElfW(Addr) *array = (ElfW(Addr) *) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_FINI_ARRAY]);
unsigned int i = (tpnt->dynamic_info[DT_FINI_ARRAYSZ] / sizeof(ElfW(Addr)));
while (i-- > 0) {
void (*dl_elf_func) (void);
@@ -166,7 +166,7 @@ static void __attribute__ ((destructor)) __attribute_used__ _dl_fini(void)
if (tpnt->dynamic_info[DT_FINI]) {
void (*dl_elf_func) (void);
- dl_elf_func = (void (*)(void)) (intptr_t) (tpnt->loadaddr + tpnt->dynamic_info[DT_FINI]);
+ dl_elf_func = (void (*)(void)) (intptr_t) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_FINI]);
_dl_if_debug_dprint("\ncalling FINI: %s\n\n", tpnt->libname);
(*dl_elf_func) ();
}
@@ -299,9 +299,9 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
break;
}
- if (app_tpnt->loadaddr)
+ if (DL_LOADADDR_BASE(app_tpnt->loadaddr))
_dl_debug_early("Position Independent Executable: "
- "app_tpnt->loadaddr=%x\n", app_tpnt->loadaddr);
+ "app_tpnt->loadaddr=%x\n", DL_LOADADDR_BASE(app_tpnt->loadaddr));
}
/*
@@ -318,7 +318,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
relro_size = ppnt->p_memsz;
}
if (ppnt->p_type == PT_DYNAMIC) {
- dpnt = (ElfW(Dyn) *) (ppnt->p_vaddr + app_tpnt->loadaddr);
+ dpnt = (ElfW(Dyn) *) DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr);
_dl_parse_dynamic_info(dpnt, app_tpnt->dynamic_info, debug_addr, app_tpnt->loadaddr);
#ifndef __FORCE_SHAREABLE_TEXT_SEGMENTS__
/* Ugly, ugly. We need to call mprotect to change the
@@ -332,7 +332,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_val;
for (i = 0; i < auxvt[AT_PHNUM].a_un.a_val; i++, ppnt++) {
if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W))
- _dl_mprotect((void *) ((ppnt->p_vaddr + app_tpnt->loadaddr) & PAGE_ALIGN),
+ _dl_mprotect((void *) (DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr) & PAGE_ALIGN),
((ppnt->p_vaddr + app_tpnt->loadaddr) & ADDR_ALIGN) +
(unsigned long) ppnt->p_filesz,
PROT_READ | PROT_WRITE | PROT_EXEC);
@@ -347,7 +347,9 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
#endif
/* OK, we have what we need - slip this one into the list. */
app_tpnt = _dl_add_elf_hash_table(_dl_progname, app_tpnt->loadaddr,
- app_tpnt->dynamic_info, ppnt->p_vaddr + app_tpnt->loadaddr, ppnt->p_filesz);
+ app_tpnt->dynamic_info,
+ DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr),
+ ppnt->p_filesz);
_dl_loaded_modules->libtype = elf_executable;
_dl_loaded_modules->ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_val;
_dl_loaded_modules->n_phent = auxvt[AT_PHNUM].a_un.a_val;
@@ -368,7 +370,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
if (ppnt->p_type == PT_INTERP) {
char *ptmp;
- tpnt->libname = (char *) ppnt->p_vaddr + app_tpnt->loadaddr;
+ tpnt->libname = (char *) DL_RELOC_ADDR(app_tpnt->loadaddr, ppnt->p_vaddr);
/* Store the path where the shared lib loader was found
* for later use
@@ -378,7 +380,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
if (ptmp != _dl_ldsopath)
*ptmp = '\0';
- _dl_debug_early("Lib Loader: (%x) %s\n", tpnt->loadaddr, tpnt->libname);
+ _dl_debug_early("Lib Loader: (%x) %s\n", DL_LOADADDR_BASE(tpnt->loadaddr), tpnt->libname);
}
}
app_tpnt->relro_addr = relro_addr;
@@ -450,7 +452,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
*/
debug_addr->r_map = (struct link_map *) _dl_loaded_modules;
debug_addr->r_version = 1;
- debug_addr->r_ldbase = load_addr;
+ debug_addr->r_ldbase = DL_LOADADDR_BASE(load_addr);
debug_addr->r_brk = (unsigned long) &_dl_debug_state;
_dl_debug_addr = debug_addr;
@@ -497,7 +499,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
} else {
tpnt1->rtld_flags = unlazy | RTLD_GLOBAL;
- _dl_debug_early("Loading: (%x) %s\n", tpnt1->loadaddr, tpnt1->libname);
+ _dl_debug_early("Loading: (%x) %s\n", DL_LOADADDR_BASE(tpnt1->loadaddr), tpnt1->libname);
#ifdef __LDSO_LDD_SUPPORT__
if (trace_loaded_objects &&
@@ -509,7 +511,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
*/
if (_dl_strcmp(_dl_progname, str) != 0)
_dl_dprintf(1, "\t%s => %s (%x)\n", str, tpnt1->libname,
- tpnt1->loadaddr);
+ DL_LOADADDR_BASE(tpnt1->loadaddr));
}
#endif
}
@@ -588,14 +590,14 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
} else {
tpnt1->rtld_flags = unlazy | RTLD_GLOBAL;
- _dl_debug_early("Loading: (%x) %s\n", tpnt1->loadaddr, tpnt1->libname);
+ _dl_debug_early("Loading: (%x) %s\n", DL_LOADADDR_BASE(tpnt1->loadaddr), tpnt1->libname);
#ifdef __LDSO_LDD_SUPPORT__
if (trace_loaded_objects &&
tpnt1->usage_count == 1) {
_dl_dprintf(1, "\t%s => %s (%x)\n",
cp2, tpnt1->libname,
- (unsigned)tpnt1->loadaddr);
+ DL_LOADADDR_BASE(tpnt1->loadaddr));
}
#endif
}
@@ -647,14 +649,14 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
tpnt1->rtld_flags = unlazy | RTLD_GLOBAL;
- _dl_debug_early("Loading: (%x) %s\n", tpnt1->loadaddr, tpnt1->libname);
+ _dl_debug_early("Loading: (%x) %s\n", DL_LOADADDR_BASE(tpnt1->loadaddr), tpnt1->libname);
#ifdef __LDSO_LDD_SUPPORT__
if (trace_loaded_objects &&
tpnt1->usage_count == 1) {
_dl_dprintf(1, "\t%s => %s (%x)\n",
lpntstr, tpnt1->libname,
- (unsigned)tpnt1->loadaddr);
+ DL_LOADADDR_BASE(tpnt1->loadaddr));
}
#endif
}
@@ -715,7 +717,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
*/
if (tpnt) {
ElfW(Ehdr) *epnt = (ElfW(Ehdr) *) auxvt[AT_BASE].a_un.a_val;
- ElfW(Phdr) *myppnt = (ElfW(Phdr) *) (load_addr + epnt->e_phoff);
+ ElfW(Phdr) *myppnt = (ElfW(Phdr) *) DL_RELOC_ADDR(load_addr, epnt->e_phoff);
int j;
tpnt = _dl_add_elf_hash_table(tpnt->libname, load_addr,
@@ -765,7 +767,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
if (trace_loaded_objects) {
_dl_dprintf(1, "\t%s => %s (%x)\n",
rpnt->dyn->libname + _dl_strlen(_dl_ldsopath) + 1,
- rpnt->dyn->libname, rpnt->dyn->loadaddr);
+ rpnt->dyn->libname, DL_LOADADDR_BASE(rpnt->dyn->loadaddr));
_dl_exit(0);
}
#endif
@@ -817,7 +819,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
for (myppnt = tpnt->ppnt, j = 0; j < tpnt->n_phent; j++, myppnt++) {
if (myppnt->p_type == PT_LOAD && !(myppnt->p_flags & PF_W) && tpnt->dynamic_info[DT_TEXTREL]) {
- _dl_mprotect((void *) (tpnt->loadaddr + (myppnt->p_vaddr & PAGE_ALIGN)),
+ _dl_mprotect((void *) (DL_RELOC_ADDR(tpnt->loadaddr, myppnt->p_vaddr) & PAGE_ALIGN),
(myppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) myppnt->p_filesz, LXFLAGS(myppnt->p_flags));
}
}
@@ -846,7 +848,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
if (tpnt->dynamic_info[DT_INIT]) {
void (*dl_elf_func) (void);
- dl_elf_func = (void (*)(void)) (intptr_t) (tpnt->loadaddr + tpnt->dynamic_info[DT_INIT]);
+ dl_elf_func = (void (*)(void)) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_INIT]);
_dl_if_debug_dprint("calling INIT: %s\n\n", tpnt->libname);
diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index 84102d730..79b181628 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -377,7 +377,7 @@ void *dlopen(const char *libname, int flag)
if (tpnt->dynamic_info[DT_INIT]) {
void (*dl_elf_func) (void);
- dl_elf_func = (void (*)(void)) (tpnt->loadaddr + tpnt->dynamic_info[DT_INIT]);
+ dl_elf_func = (void (*)(void)) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_INIT]);
if (dl_elf_func && *dl_elf_func != NULL) {
_dl_if_debug_print("running ctors for library %s at '%p'\n",
tpnt->libname, dl_elf_func);
@@ -510,7 +510,7 @@ static int do_dlclose(void *vhandle, int need_fini)
#endif
if (tpnt->dynamic_info[DT_FINI]) {
- dl_elf_fini = (int (*)(void)) (tpnt->loadaddr + tpnt->dynamic_info[DT_FINI]);
+ dl_elf_fini = (int (*)(void)) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_FINI]);
_dl_if_debug_print("running dtors for library %s at '%p'\n",
tpnt->libname, dl_elf_fini);
(*dl_elf_fini) ();
@@ -620,7 +620,7 @@ int dlinfo(void)
/* First start with a complete list of all of the loaded files. */
for (tpnt = _dl_loaded_modules; tpnt; tpnt = tpnt->next) {
fprintf(stderr, "\t%p %p %p %s %d %s\n",
- tpnt->loadaddr, tpnt, tpnt->symbol_scope,
+ DL_LOADADDR_BASE(tpnt->loadaddr), tpnt, tpnt->symbol_scope,
type[tpnt->libtype],
tpnt->usage_count, tpnt->libname);
}
@@ -658,7 +658,7 @@ int dladdr(const void *__address, Dl_info * __info)
tpnt = rpnt;
_dl_if_debug_print("Module \"%s\" at %p\n",
- tpnt->libname, tpnt->loadaddr);
+ tpnt->libname, DL_LOADADDR_BASE(tpnt->loadaddr));
if (DL_ADDR_IN_LOADADDR((ElfW(Addr)) __address, tpnt, pelf))
pelf = tpnt;
@@ -687,7 +687,7 @@ int dladdr(const void *__address, Dl_info * __info)
for (si = pelf->elf_buckets[hn]; si; si = pelf->chains[si]) {
ElfW(Addr) symbol_addr;
- symbol_addr = pelf->loadaddr + symtab[si].st_value;
+ symbol_addr = (ElfW(Addr)) DL_RELOC_ADDR(pelf->loadaddr, symtab[si].st_value);
if (symbol_addr <= (ElfW(Addr))__address && (!sf || sa < symbol_addr)) {
sa = symbol_addr;
sn = si;
@@ -701,7 +701,7 @@ int dladdr(const void *__address, Dl_info * __info)
if (sf) {
__info->dli_fname = pelf->libname;
- __info->dli_fbase = (void *)pelf->loadaddr;
+ __info->dli_fbase = (void *) DL_LOADADDR_BASE(pelf->loadaddr);
__info->dli_sname = strtab + symtab[sn].st_name;
__info->dli_saddr = (void *)sa;
}