Bläddra i källkod

Let ldso find libc's malloc function and set _dl_malloc_function.
This removes some crap in libdl.c(and future libs which needs
to access ldso functions).
What do you think?

Joakim Tjernlund 20 år sedan
förälder
incheckning
94a9a5a209
2 ändrade filer med 4 tillägg och 10 borttagningar
  1. 4 2
      ldso/ldso/ldso.c
  2. 0 8
      ldso/libdl/libdl.c

+ 4 - 2
ldso/ldso/ldso.c

@@ -45,7 +45,7 @@ int _dl_secure                 = 1;		/* Are we dealing with setuid stuff? */
 int _dl_errno                  = 0;     /* We can't use the real errno in ldso */
 size_t _dl_pagesize            = 0;		/* Store the page size for use later */
 struct r_debug *_dl_debug_addr = NULL;  /* Used to communicate with the gdb debugger */
-
+void *(*_dl_malloc_function) (size_t size) = NULL;
 
 
 #ifdef __SUPPORT_LD_DEBUG__
@@ -776,6 +776,9 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, unsigned long load_addr,
 	/* Notify the debugger that all objects are now mapped in.  */
 	_dl_debug_addr->r_state = RT_CONSISTENT;
 	_dl_debug_state();
+
+	/* Find the real malloc function and make ldso functions use that from now on */
+	 _dl_malloc_function = (void (*)(size_t)) (intptr_t) _dl_find_hash("malloc", _dl_symbol_tables, ELF_RTYPE_CLASS_PLT);
 }
 
 char *_dl_getenv(const char *symbol, char **envp)
@@ -827,7 +830,6 @@ static int _dl_suid_ok(void)
 	return 0;
 }
 
-void *(*_dl_malloc_function) (size_t size) = NULL;
 void *_dl_malloc(int size)
 {
 	void *retval;

+ 0 - 8
ldso/libdl/libdl.c

@@ -144,14 +144,6 @@ void *dlopen(const char *libname, int flag)
 
 	from = (ElfW(Addr)) __builtin_return_address(0);
 
-	/* Have the dynamic linker use the regular malloc function now */
-	if (!dl_init) {
-		dl_init++;
-#if defined (__LIBDL_SHARED__)
-		_dl_malloc_function = malloc;
-#endif
-	}
-
 	/* Cover the trivial case first */
 	if (!libname)
 		return _dl_symbol_tables;