[uClibc-cvs] CVS update of uClibc/ldso (include/ldso.h ldso/dl-elf.c ldso/dl-hash.c ldso/ldso.c libdl/libdl.c)

Erik Andersen andersen at codepoet.org
Wed Jul 14 12:27:04 UTC 2004


    Date: Wednesday, July 14, 2004 @ 06:27:04
  Author: andersen
    Path: /var/cvs/uClibc/ldso

Modified: include/ldso.h (1.9 -> 1.10) ldso/dl-elf.c (1.70 -> 1.71)
          ldso/dl-hash.c (1.20 -> 1.21) ldso/ldso.c (1.98 -> 1.99)
          libdl/libdl.c (1.41 -> 1.42)

Based on a patch from Alexandre Oliva, make sure _dl_malloc returns a nicely
aligned pointer that may be aligned up to page_size.  Also add _dl_free,


Index: uClibc/ldso/include/ldso.h
diff -u uClibc/ldso/include/ldso.h:1.9 uClibc/ldso/include/ldso.h:1.10
--- uClibc/ldso/include/ldso.h:1.9	Tue May 11 05:14:57 2004
+++ uClibc/ldso/include/ldso.h	Wed Jul 14 06:27:02 2004
@@ -65,6 +65,7 @@
 #endif
 
 extern void *_dl_malloc(int size);
+extern void _dl_free(void *);
 extern char *_dl_getenv(const char *symbol, char **envp);
 extern void _dl_unsetenv(const char *symbol, char **envp);
 extern char *_dl_strdup(const char *string);
Index: uClibc/ldso/ldso/dl-elf.c
diff -u uClibc/ldso/ldso/dl-elf.c:1.70 uClibc/ldso/ldso/dl-elf.c:1.71
--- uClibc/ldso/ldso/dl-elf.c:1.70	Sat Jun 12 02:38:39 2004
+++ uClibc/ldso/ldso/dl-elf.c	Wed Jul 14 06:27:03 2004
@@ -31,6 +31,7 @@
 
 
 #include "ldso.h"
+void *(*_dl_malloc_function) (size_t size) = NULL;
 
 #ifdef USE_CACHE
 
@@ -405,7 +406,7 @@
 	tpnt = _dl_check_hashed_files(libname);
 	if (tpnt) {
 		if (*rpnt) {
-			(*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+			(*rpnt)->next = (struct dyn_elf *) _dl_malloc_function(sizeof(struct dyn_elf));
 			_dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
 			(*rpnt)->next->prev = (*rpnt);
 			*rpnt = (*rpnt)->next;
@@ -691,7 +692,7 @@
 	 * Add this object into the symbol chain
 	 */
 	if (*rpnt) {
-		(*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+		(*rpnt)->next = (struct dyn_elf *) _dl_malloc_function(sizeof(struct dyn_elf));
 		_dl_memset((*rpnt)->next, 0, sizeof(struct dyn_elf));
 		(*rpnt)->next->prev = (*rpnt);
 		*rpnt = (*rpnt)->next;
@@ -883,12 +884,21 @@
 	int len;
 
 	len = _dl_strlen(string);
-	retval = _dl_malloc(len + 1);
+	retval = _dl_malloc_function(len + 1);
 	_dl_strcpy(retval, string);
 	return retval;
 }
 
-void *(*_dl_malloc_function) (size_t size) = NULL;
+union __align_type
+{
+  void *p;
+  void (*fp)(void);
+  long long ll;
+#if defined __UCLIBC_HAS_FLOATS__ && ! defined __UCLIBC_HAS_SOFT_FLOAT__
+  double d;
+#endif
+};
+
 void *_dl_malloc(int size)
 {
 	void *retval;
@@ -902,11 +912,29 @@
 	if (_dl_malloc_function)
 		return (*_dl_malloc_function) (size);
 
-	if (_dl_malloc_addr - _dl_mmap_zero + size > _dl_pagesize) {
+	if ((int)(_dl_malloc_addr - _dl_mmap_zero + size) > (int)_dl_pagesize) {
+		int rounded_size;
+
+		/* Since the above assumes we get a full page even if
+		   we request less than that, make sure we request a
+		   full page, since uClinux may give us less than than
+		   a full page.  We might round even
+		   larger-than-a-page sizes, but we end up never
+		   reusing _dl_mmap_zero/_dl_malloc_addr in that case,
+		   so we don't do it.
+
+		   The actual page size doesn't really matter; as long
+		   as we're self-consistent here, we're safe.  */
+		if (size < (int)_dl_pagesize)
+			rounded_size = (size + _dl_pagesize - 1) & _dl_pagesize;
+		else
+			rounded_size = size;
+
+
 #ifdef __SUPPORT_LD_DEBUG_EARLY__
 		_dl_dprintf(2, "malloc: mmapping more memory\n");
 #endif
-		_dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, size,
+		_dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, rounded_size,
 				PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 		if (_dl_mmap_check_error(_dl_mmap_zero)) {
 			_dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
@@ -920,8 +948,16 @@
 	 * Align memory to 4 byte boundary.  Some platforms require this, others
 	 * simply get better performance.
 	 */
-	_dl_malloc_addr = (unsigned char *) (((unsigned long) _dl_malloc_addr + 3) & ~(3));
+	_dl_malloc_addr = (unsigned char *)
+		(((unsigned long) _dl_malloc_addr +
+		  __alignof__(union __align_type) - 1)
+		 & ~(__alignof__(union __align_type) - 1));
 	return retval;
 }
 
-
+void (*_dl_free_function) (void *p) = NULL;
+void
+_dl_free (void *p) {
+	if (_dl_free_function)
+		(*_dl_free_function) (p);
+}
Index: uClibc/ldso/ldso/dl-hash.c
diff -u uClibc/ldso/ldso/dl-hash.c:1.20 uClibc/ldso/ldso/dl-hash.c:1.21
--- uClibc/ldso/ldso/dl-hash.c:1.20	Sat Jun 19 15:38:41 2004
+++ uClibc/ldso/ldso/dl-hash.c	Wed Jul 14 06:27:03 2004
@@ -100,13 +100,13 @@
 	int i;
 
 	if (!_dl_loaded_modules) {
-		tpnt = _dl_loaded_modules = (struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
+		tpnt = _dl_loaded_modules = (struct elf_resolve *) _dl_malloc_function(sizeof(struct elf_resolve));
 		_dl_memset(tpnt, 0, sizeof(struct elf_resolve));
 	} else {
 		tpnt = _dl_loaded_modules;
 		while (tpnt->next)
 			tpnt = tpnt->next;
-		tpnt->next = (struct elf_resolve *) _dl_malloc(sizeof(struct elf_resolve));
+		tpnt->next = (struct elf_resolve *) _dl_malloc_function(sizeof(struct elf_resolve));
 		_dl_memset(tpnt->next, 0, sizeof(struct elf_resolve));
 		tpnt->next->prev = tpnt;
 		tpnt = tpnt->next;
Index: uClibc/ldso/ldso/ldso.c
diff -u uClibc/ldso/ldso/ldso.c:1.98 uClibc/ldso/ldso/ldso.c:1.99
--- uClibc/ldso/ldso/ldso.c:1.98	Wed May 12 16:54:50 2004
+++ uClibc/ldso/ldso/ldso.c	Wed Jul 14 06:27:03 2004
@@ -191,7 +191,7 @@
 			_dl_loaded_modules->libtype = elf_executable;
 			_dl_loaded_modules->ppnt = (ElfW(Phdr) *) auxvt[AT_PHDR].a_un.a_ptr;
 			_dl_loaded_modules->n_phent = auxvt[AT_PHNUM].a_un.a_val;
-			_dl_symbol_tables = rpnt = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+			_dl_symbol_tables = rpnt = (struct dyn_elf *) _dl_malloc_function(sizeof(struct dyn_elf));
 			_dl_memset(rpnt, 0, sizeof(struct dyn_elf));
 			rpnt->dyn = _dl_loaded_modules;
 			app_tpnt->usage_count++;
@@ -296,7 +296,7 @@
 			len1 = _dl_strlen(dl_debug_output);
 			len2 = _dl_strlen(tmp1);
 
-			filename = _dl_malloc(len1+len2+2);
+			filename = _dl_malloc_function(len1+len2+2);
 
 			if (filename)
 			{
@@ -563,12 +563,12 @@
 			tpnt->prev = NULL;
 		}
 		if (rpnt) {
-			rpnt->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+			rpnt->next = (struct dyn_elf *) _dl_malloc_function(sizeof(struct dyn_elf));
 			_dl_memset(rpnt->next, 0, sizeof(struct dyn_elf));
 			rpnt->next->prev = rpnt;
 			rpnt = rpnt->next;
 		} else {
-			rpnt = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf));
+			rpnt = (struct dyn_elf *) _dl_malloc_function(sizeof(struct dyn_elf));
 			_dl_memset(rpnt, 0, sizeof(struct dyn_elf));
 		}
 		rpnt->dyn = tpnt;
Index: uClibc/ldso/libdl/libdl.c
diff -u uClibc/ldso/libdl/libdl.c:1.41 uClibc/ldso/libdl/libdl.c:1.42
--- uClibc/ldso/libdl/libdl.c:1.41	Thu May 13 03:23:34 2004
+++ uClibc/ldso/libdl/libdl.c	Wed Jul 14 06:27:03 2004
@@ -54,6 +54,7 @@
 extern struct r_debug *_dl_debug_addr __attribute__ ((__weak__));
 extern unsigned long _dl_error_number __attribute__ ((__weak__));
 extern void *(*_dl_malloc_function)(size_t) __attribute__ ((__weak__));
+extern void (*_dl_free_function) (void *p) __attribute__ ((__weak__));
 #ifdef USE_CACHE
 int _dl_map_cache(void) __attribute__ ((__weak__));
 int _dl_unmap_cache(void) __attribute__ ((__weak__));
@@ -95,6 +96,7 @@
 static unsigned char *_dl_malloc_addr, *_dl_mmap_zero;
 void *(*_dl_malloc_function) (size_t size);
 int _dl_errno = 0;
+void (*_dl_free_function) (void *p);
 int _dl_fixup(struct dyn_elf *rpnt, int lazy);
 #include "../ldso/dl-progname.h"               /* Pull in the name of ld.so */
 #include "../ldso/dl-hash.c"
@@ -164,6 +166,7 @@
 	if (!dl_init) {
 		dl_init++;
 		_dl_malloc_function = malloc;
+		_dl_free_function = free;
 	}
 
 	/* Cover the trivial case first */



More information about the uClibc-cvs mailing list