OSDN Git Service

2009-04-23 Paul Brook <paul@codesourcery.com>
authorjjohnstn <jjohnstn>
Thu, 23 Apr 2009 17:54:22 +0000 (17:54 +0000)
committerjjohnstn <jjohnstn>
Thu, 23 Apr 2009 17:54:22 +0000 (17:54 +0000)
            Kazu Hirata  <kazu@codesourcery.com>

        * libc/stdlib/__atexit.c (__register_exitproc): Use weak reference
        to malloc.  Allocate dynamically only if it is present.
        * libc/stdlib/__call_atexit.c (__call_exitprocs): Use weak
        reference to free.  Call free only if it is present.

newlib/ChangeLog
newlib/libc/stdlib/__atexit.c
newlib/libc/stdlib/__call_atexit.c

index 39ab966..fce8f2a 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-23  Paul Brook  <paul@codesourcery.com>
+           Kazu Hirata  <kazu@codesourcery.com>
+
+       * libc/stdlib/__atexit.c (__register_exitproc): Use weak reference
+       to malloc.  Allocate dynamically only if it is present.
+       * libc/stdlib/__call_atexit.c (__call_exitprocs): Use weak
+       reference to free.  Call free only if it is present.
+
 2009-04-22 Anthony Green <green@moxielogic.com>
 
        * configure.host: Add moxie support.
index 49eebb3..4f0b67c 100644 (file)
@@ -8,6 +8,8 @@
 #include <sys/lock.h>
 #include "atexit.h"
 
+/* Make this a weak reference to avoid pulling in malloc.  */
+void * malloc(size_t) _ATTRIBUTE((__weak__));
 
 /*
  * Register a function to be performed at exit or on shared library unload.
@@ -38,6 +40,11 @@ _DEFUN (__register_exitproc,
 #ifndef _ATEXIT_DYNAMIC_ALLOC
       return -1;
 #else
+      /* Don't dynamically allocate the atexit array if malloc is not
+        available.  */
+      if (!malloc)
+       return -1;
+
       p = (struct _atexit *) malloc (sizeof *p);
       if (p == NULL)
        {
@@ -62,7 +69,9 @@ _DEFUN (__register_exitproc,
       args = p->_on_exit_args_ptr;
       if (args == NULL)
        {
-         args = malloc (sizeof * p->_on_exit_args_ptr);
+         if (malloc)
+           args = malloc (sizeof * p->_on_exit_args_ptr);
+
          if (args == NULL)
            {
 #ifndef __SINGLE_THREAD__
index ab86fca..e7f9561 100644 (file)
@@ -7,6 +7,9 @@
 #include <reent.h>
 #include "atexit.h"
 
+/* Make this a weak reference to avoid pulling in free.  */
+void free(void *) _ATTRIBUTE((__weak__));
+
 /*
  * Call registered exit handlers.  If D is null then all handlers are called,
  * otherwise only the handlers from that DSO are called.
@@ -76,6 +79,11 @@ _DEFUN (__call_exitprocs, (code, d),
 #ifndef _ATEXIT_DYNAMIC_ALLOC
       break;
 #else
+      /* Don't dynamically free the atexit array if free is not
+        available.  */
+      if (!free)
+       break;
+
       /* Move to the next block.  Free empty blocks except the last one,
         which is part of _GLOBAL_REENT.  */
       if (p->_ind == 0 && p->_next)