svn commit: trunk/uClibc/ldso: include ldso libdl
bernds at uclibc.org
bernds at uclibc.org
Mon Dec 3 22:41:40 UTC 2007
Author: bernds
Date: 2007-12-03 14:41:36 -0800 (Mon, 03 Dec 2007)
New Revision: 20612
Log:
Blackfin FD-PIC patch 1/6.
Add a new function _dl_free. In _dl_malloc, ensure we always get back a full
page from mmap.
Reset _dl_malloc_function and _dl_free_function when libdl is initialized.
Modified:
trunk/uClibc/ldso/include/ldso.h
trunk/uClibc/ldso/ldso/ldso.c
trunk/uClibc/ldso/libdl/libdl.c
Changeset:
Modified: trunk/uClibc/ldso/include/ldso.h
===================================================================
--- trunk/uClibc/ldso/include/ldso.h 2007-12-03 20:58:30 UTC (rev 20611)
+++ trunk/uClibc/ldso/include/ldso.h 2007-12-03 22:41:36 UTC (rev 20612)
@@ -99,7 +99,8 @@
#define NULL ((void *) 0)
#endif
-extern void *_dl_malloc(int size);
+extern void *_dl_malloc(size_t 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);
Modified: trunk/uClibc/ldso/ldso/ldso.c
===================================================================
--- trunk/uClibc/ldso/ldso/ldso.c 2007-12-03 20:58:30 UTC (rev 20611)
+++ trunk/uClibc/ldso/ldso/ldso.c 2007-12-03 22:41:36 UTC (rev 20612)
@@ -50,6 +50,7 @@
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;
+void (*_dl_free_function) (void *p) = NULL;
#ifdef __SUPPORT_LD_DEBUG__
char *_dl_debug = 0;
@@ -884,7 +885,7 @@
return 0;
}
-void *_dl_malloc(int size)
+void *_dl_malloc(size_t size)
{
void *retval;
@@ -895,9 +896,26 @@
if (_dl_malloc_function)
return (*_dl_malloc_function) (size);
- if (_dl_malloc_addr - _dl_mmap_zero + (unsigned)size > _dl_pagesize) {
+ if (_dl_malloc_addr - _dl_mmap_zero + size > _dl_pagesize) {
+ size_t 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 < _dl_pagesize)
+ rounded_size = (size + _dl_pagesize - 1) & _dl_pagesize;
+ else
+ rounded_size = size;
+
_dl_debug_early("mmapping more memory\n");
- _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);
@@ -916,5 +934,11 @@
return retval;
}
+void _dl_free (void *p)
+{
+ if (_dl_free_function)
+ (*_dl_free_function) (p);
+}
+
#include "dl-hash.c"
#include "dl-elf.c"
Modified: trunk/uClibc/ldso/libdl/libdl.c
===================================================================
--- trunk/uClibc/ldso/libdl/libdl.c 2007-12-03 20:58:30 UTC (rev 20611)
+++ trunk/uClibc/ldso/libdl/libdl.c 2007-12-03 22:41:36 UTC (rev 20612)
@@ -32,6 +32,7 @@
#include <ldso.h>
#include <stdio.h>
+#include <string.h>
#ifdef SHARED
@@ -51,6 +52,7 @@
extern struct r_debug *_dl_debug_addr;
extern unsigned long _dl_error_number;
extern void *(*_dl_malloc_function)(size_t);
+extern void (*_dl_free_function) (void *p);
extern void _dl_run_init_array(struct elf_resolve *);
extern void _dl_run_fini_array(struct elf_resolve *);
#ifdef __LDSO_CACHE_SUPPORT__
@@ -67,6 +69,9 @@
#else /* SHARED */
+#define _dl_malloc malloc
+#define _dl_free free
+
/* When libdl is linked as a static library, we need to replace all
* the symbols that otherwise would have been loaded in from ldso... */
@@ -83,13 +88,15 @@
int _dl_debug_file = 2;
#endif
const char *_dl_progname = ""; /* Program name */
+void *(*_dl_malloc_function)(size_t);
+void (*_dl_free_function) (void *p);
char *_dl_library_path = 0; /* Where we look for libraries */
char *_dl_ldsopath = 0; /* Location of the shared lib loader */
int _dl_errno = 0; /* We can't use the real errno in ldso */
size_t _dl_pagesize = PAGE_SIZE; /* Store the page size for use later */
/* This global variable is also to communicate with debuggers such as gdb. */
struct r_debug *_dl_debug_addr = NULL;
-#define _dl_malloc malloc
+
#include "../ldso/dl-array.c"
#include "../ldso/dl-debug.c"
#include LDSO_ELFINTERP
@@ -157,6 +164,7 @@
struct init_fini_list *tmp, *runp, *runp2, *dep_list;
unsigned int nlist, i;
struct elf_resolve **init_fini_list;
+ static int _dl_init = 0;
/* A bit of sanity checking... */
if (!(flag & (RTLD_LAZY|RTLD_NOW))) {
@@ -166,6 +174,11 @@
from = (ElfW(Addr)) __builtin_return_address(0);
+ if (!_dl_init) {
+ _dl_init++;
+ _dl_malloc_function = malloc;
+ _dl_free_function = free;
+ }
/* Cover the trivial case first */
if (!libname)
return _dl_symbol_tables;
More information about the uClibc-cvs
mailing list