From 6c1b16d6cfeff7c4332606e54a55e7ff039f3440 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 19 Nov 2002 05:05:03 +0000 Subject: Stefan Allius writes: I fixed two little bugs in ldso.c: - For LDD support we test the old environment variable LD_TRACE_LOADED_OBJECTS. - Before we init the GOT table of the dynamic loader we have to check, if we have a DT_PLTGOT entry. If DT_PLTGOT was zero we patch somthing in the header of the dynamic loader. This was the cause, why we have to enable the DO_MPROTECT_HACKS option for all targets, to avoid segment faults. In readelflib1.c I added a warning, if we try to load a shared library, which wasn't compiled with -fPIC or -fpic. So if we disable the DO_MPROTECT_HACKS option we are sure, that we don't waste memory by shared libraries which aren't able to share their text segment. I think this is a helpful option on little embedded systems. --- ldso/ldso/dl-elf.c | 5 +++++ ldso/ldso/ldso.c | 12 +++++++++--- ldso/ldso/readelflib1.c | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'ldso') diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index b84476338..aefcf19e3 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -573,6 +573,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, back again later. */ if (dynamic_info[DT_TEXTREL]) { +#ifdef DO_MPROTECT_HACKS ppnt = (elf_phdr *)(intptr_t) & header[epnt->e_phoff]; for (i = 0; i < epnt->e_phnum; i++, ppnt++) { if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) @@ -581,6 +582,10 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, (ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, PROT_READ | PROT_WRITE | PROT_EXEC); } +#else + _dl_dprintf(_dl_debug_file, "Can't modify %s's text section. Use GCC option -fPIC for shared objects, please.\n",libname); + _dl_exit(1); +#endif } tpnt = _dl_add_elf_hash_table(libname, (char *) libaddr, dynamic_info, diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 3dd5d19c9..bd8ef6e7f 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -659,10 +659,16 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a tpnt->libtype = program_interpreter; tpnt->loadaddr = (char *) load_addr; - INIT_GOT(lpnt, tpnt); +#ifdef ALLOW_ZERO_PLTGOT + if (tpnt->dynamic_info[DT_PLTGOT]) +#endif + { + INIT_GOT(lpnt, tpnt); #ifdef __SUPPORT_LD_DEBUG_EARLY__ - _dl_dprintf(_dl_debug_file, "GOT found at %x\n", lpnt); + _dl_dprintf(_dl_debug_file, "GOT found at %x\n", lpnt); #endif + } + /* OK, this was a big step, now we need to scan all of the user images and load them properly. */ @@ -859,7 +865,7 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a #endif - _dl_trace_loaded_objects = _dl_getenv("__LDSO_LDD_SUPPORT___LOADED_OBJECTS", envp); + _dl_trace_loaded_objects = _dl_getenv("LD_TRACE_LOADED_OBJECTS", envp); #ifndef __LDSO_LDD_SUPPORT__ if (_dl_trace_loaded_objects) { _dl_dprintf(_dl_debug_file, "Use the ldd provided by uClibc\n"); diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c index b84476338..aefcf19e3 100644 --- a/ldso/ldso/readelflib1.c +++ b/ldso/ldso/readelflib1.c @@ -573,6 +573,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, back again later. */ if (dynamic_info[DT_TEXTREL]) { +#ifdef DO_MPROTECT_HACKS ppnt = (elf_phdr *)(intptr_t) & header[epnt->e_phoff]; for (i = 0; i < epnt->e_phnum; i++, ppnt++) { if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) @@ -581,6 +582,10 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, (ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, PROT_READ | PROT_WRITE | PROT_EXEC); } +#else + _dl_dprintf(_dl_debug_file, "Can't modify %s's text section. Use GCC option -fPIC for shared objects, please.\n",libname); + _dl_exit(1); +#endif } tpnt = _dl_add_elf_hash_table(libname, (char *) libaddr, dynamic_info, -- cgit v1.2.3