[PATCH 3/3] Add and use _REENT_NEGLECT_BINARY_COMPATIBILITY

Sebastian Huber sebastian.huber@embedded-brains.de
Sat May 4 14:12:00 GMT 2013


This patch adds a new define _REENT_NEGLECT_BINARY_COMPATIBILITY which
will remove some fields of struct _reent.  A global variable defined in
__atexit.c will be used to store the first 32 atexit() handlers.  A
global variable in __call_atexit.c contains the LIFO head.  This option
is interesting for all targets which don't care about binary
compatibility and want to save approximately 400 bytes per struct
_reent.

newlib/ChangeLog
2013-05-04  Sebastian Huber <sebastian.huber@embedded-brains.de>

	* libc/include/sys/config.h
	(_REENT_NEGLECT_BINARY_COMPATIBILITY): Define for RTEMS.
	* libc/include/sys/reent.h (_reent): Use
	_REENT_NEGLECT_BINARY_COMPATIBILITY.
	(_global_atexit): Declare if _REENT_NEGLECT_BINARY_COMPATIBILITY
	is defined.
	* libc/stdlib/__atexit.c (_global_atexit0): Define if
	_REENT_NEGLECT_BINARY_COMPATIBILITY is defined.
	* libc/stdlib/__call_atexit.c (_global_atexit): Define if
	_REENT_NEGLECT_BINARY_COMPATIBILITY is defined.
---
 newlib/libc/include/sys/config.h   |    1 +
 newlib/libc/include/sys/reent.h    |   22 +++++++++++++++++++---
 newlib/libc/stdlib/__atexit.c      |    7 ++++++-
 newlib/libc/stdlib/__call_atexit.c |    4 ++++
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index a6528b8..5eb1bd0 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -217,6 +217,7 @@
 #if defined(__rtems__)
 #define __FILENAME_MAX__ 255
 #define _READ_WRITE_RETURN_TYPE _ssize_t
+#define _REENT_NEGLECT_BINARY_COMPATIBILITY
 #endif
 
 #ifndef __EXPORT
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index cf2969d..0f0aa45 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -108,10 +108,15 @@ struct _atexit {
   (var)->_on_exit_args._fnargs[0] = _NULL
 #endif
 
-#define _REENT_INIT_ATEXIT \
+#ifdef _REENT_NEGLECT_BINARY_COMPATIBILITY
+# define _REENT_INIT_ATEXIT
+# define _REENT_INIT_ATEXIT_PTR(var, var0)
+#else
+# define _REENT_INIT_ATEXIT \
   _NULL, _ATEXIT_INIT,
-#define _REENT_INIT_ATEXIT_PTR(var, var0) \
+# define _REENT_INIT_ATEXIT_PTR(var, var0) \
   (var)->_atexit = _NULL; _ATEXIT_INIT_PTR(var0);
+#endif
 
 /*
  * Stdio buffers.
@@ -410,10 +415,12 @@ struct _reent
   /* signal info */
   void (**(_sig_func))(int);
 
+# ifndef _REENT_NEGLECT_BINARY_COMPATIBILITY
   /* The next two fields are used for atexit stuff.  They are used only in
      _GLOBAL_REENT, but not in other struct _reent instances.  */
   struct _atexit *_atexit;	/* points to head of LIFO stack */
   struct _atexit _atexit0;	/* one guaranteed table, required by ANSI */
+# endif
 
   struct _glue __sglue;			/* root of glue chain */
   __FILE *__sf;			        /* file descriptors */
@@ -644,6 +651,7 @@ struct _reent
           _mbstate_t _wcsrtombs_state;
 	  int _h_errno;
         } _reent;
+# ifndef _REENT_NEGLECT_BINARY_COMPATIBILITY
   /* Two next two fields were once used by malloc.  They are no longer
      used. They are used to preserve the space used before so as to
      allow addition of new reent fields and keep binary compatibility.   */
@@ -653,12 +661,15 @@ struct _reent
           unsigned char * _nextf[_N_LISTS];
           unsigned int _nmalloc[_N_LISTS];
         } _unused;
+# endif
     } _new;
 
+# ifndef _REENT_NEGLECT_BINARY_COMPATIBILITY
   /* The next two fields are used for atexit stuff.  They are used only in
      _GLOBAL_REENT, but not in other struct _reent instances.  */
   struct _atexit *_atexit;	/* points to head of LIFO stack */
   struct _atexit _atexit0;	/* one guaranteed table, required by ANSI */
+# endif
 
   /* signal info */
   void (**(_sig_func))(int);
@@ -805,7 +816,12 @@ void _reclaim_reent _PARAMS ((struct _reent *));
 
 #define _GLOBAL_REENT _global_impure_ptr
 
-#define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit)
+#ifdef _REENT_NEGLECT_BINARY_COMPATIBILITY
+extern struct _atexit *_global_atexit; /* points to head of LIFO stack */
+# define _GLOBAL_ATEXIT _global_atexit
+#else
+# define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit)
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/newlib/libc/stdlib/__atexit.c b/newlib/libc/stdlib/__atexit.c
index a095313..90a9285 100644
--- a/newlib/libc/stdlib/__atexit.c
+++ b/newlib/libc/stdlib/__atexit.c
@@ -15,7 +15,12 @@ void * malloc(size_t) _ATTRIBUTE((__weak__));
 extern _LOCK_RECURSIVE_T __atexit_lock;
 #endif
 
-#define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0)
+#ifdef _REENT_NEGLECT_BINARY_COMPATIBILITY
+static struct _atexit _global_atexit0 = _ATEXIT_INIT;
+# define _GLOBAL_ATEXIT0 (&_global_atexit0)
+#else
+# define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0)
+#endif
 
 /*
  * Register a function to be performed at exit or on shared library unload.
diff --git a/newlib/libc/stdlib/__call_atexit.c b/newlib/libc/stdlib/__call_atexit.c
index 76d3f12..5e63fe2 100644
--- a/newlib/libc/stdlib/__call_atexit.c
+++ b/newlib/libc/stdlib/__call_atexit.c
@@ -13,6 +13,10 @@ void free(void *) _ATTRIBUTE((__weak__));
 
 __LOCK_INIT_RECURSIVE(, __atexit_lock);
 
+#ifdef _REENT_NEGLECT_BINARY_COMPATIBILITY
+struct _atexit *_global_atexit = _NULL;
+#endif
+
 #ifdef _WANT_REGISTER_FINI
 
 /* If "__libc_fini" is defined, finalizers (either
-- 
1.7.10.4



More information about the Newlib mailing list