Browse Source

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.

Eric Andersen 21 years ago
parent
commit
6c1b16d6cf
3 changed files with 19 additions and 3 deletions
  1. 5 0
      ldso/ldso/dl-elf.c
  2. 9 3
      ldso/ldso/ldso.c
  3. 5 0
      ldso/ldso/readelflib1.c

+ 5 - 0
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, 

+ 9 - 3
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");

+ 5 - 0
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,