RFA: Reducing the size of struct _reent by not supporting on_exit()
Nick Clifton
nickc@redhat.com
Thu May 29 19:00:00 GMT 2003
Hi Jeff,
May I apply the patch below please ?
It adds a support for a new define which can be enabled in
libc/include/sys/config.h. This define suppresses support for the
on_exit() function, which can significantly reduce the size of the
_reent structure. This is important for targets with a small
address space (eg the xstormy16). The patch also uses the GCC
poison pragma to stop user applications from using on_exit() if this
define has been enabled.
Cheers
Nick
2003-05-29 Nick Clifton <nickc@redhat.com>
* libc/include/sys/config.h: Define _NO_ON_EXIT_SUPPORT for
xstormy16 target.
* libc/include/sys/reent.h (struct atexit): Do not define
_fnargs and _fntypes fields if _NO_ON_EXIT_SUPPORT is defined.
Poison the use of on_exit if it is defined.
* libc/include/stdlib.h: Suppress prototype of on_exit if
_NO_ON_EXIT_SUPPORT is defined.
* libc/stdlib/exit.c (exit): Do not check _fntypes field if
_NO_ON_EXIT_SUPPORT if defined.
* libc/stdlib/on_exit.c (on_exit): Suppress definition if
_NO_ON_EXIT_SUPPORT is defined.
Index: newlib/libc/include/sys/config.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
retrieving revision 1.39
diff -c -3 -p -w -r1.39 config.h
*** newlib/libc/include/sys/config.h 13 May 2003 09:46:48 -0000 1.39
--- newlib/libc/include/sys/config.h 29 May 2003 09:56:18 -0000
***************
*** 104,109 ****
--- 104,113 ----
#define _POINTER_INT short
#define __BUFSIZ__ 16
#define _REENT_SMALL
+ /* This significantly reduces the size of the _reent structure, at
+ the expense of stopping the on_exit() function from functioning.
+ It is only effective if _REENT_SMALL is also defined. */
+ #define _NO_ON_EXIT_SUPPORT
#endif
/* This block should be kept in sync with GCC's limits.h. The point
Index: newlib/libc/include/sys/reent.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/reent.h,v
retrieving revision 1.22
diff -c -3 -p -w -r1.22 reent.h
*** newlib/libc/include/sys/reent.h 7 Mar 2003 15:56:49 -0000 1.22
--- newlib/libc/include/sys/reent.h 29 May 2003 09:56:18 -0000
*************** struct _atexit {
*** 76,83 ****
--- 76,87 ----
struct _atexit {
int _ind; /* next index in this table */
void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
+ #ifdef _NO_ON_EXIT_SUPPORT
+ #pragma GCC poison on_exit
+ #else
void *_fnargs[_ATEXIT_SIZE]; /* fn args for on_exit */
__ULong _fntypes; /* type of exit routine */
+ #endif
};
#endif
Index: newlib/libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.20
diff -c -3 -p -w -r1.20 stdlib.h
*** newlib/libc/include/stdlib.h 6 Dec 2002 18:58:50 -0000 1.20
--- newlib/libc/include/stdlib.h 29 May 2003 09:56:18 -0000
*************** int _EXFUN(system,(const char *__string)
*** 111,117 ****
--- 111,119 ----
long _EXFUN(a64l,(const char *__input));
char * _EXFUN(l64a,(long __input));
char * _EXFUN(_l64a_r,(struct _reent *,long __input));
+ #ifndef _NO_ON_EXIT_SUPPORT
int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
+ #endif
_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((noreturn)));
int _EXFUN(putenv,(const char *__string));
int _EXFUN(_putenv_r,(struct _reent *, const char *__string));
Index: newlib/libc/stdlib/exit.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/exit.c,v
retrieving revision 1.3
diff -c -3 -p -w -r1.3 exit.c
*** newlib/libc/stdlib/exit.c 15 May 2002 22:58:10 -0000 1.3
--- newlib/libc/stdlib/exit.c 29 May 2003 09:56:19 -0000
*************** _DEFUN (exit, (code),
*** 70,78 ****
--- 70,80 ----
for (p = _REENT->_atexit; p; p = p->_next)
for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
#endif
+ #ifndef _NO_ON_EXIT_SUPPORT
if (p->_fntypes & i)
(*((void (*)(int, void *))p->_fns[n]))(code, p->_fnargs[n]);
else
+ #endif
(*p->_fns[n]) ();
if (_REENT->__cleanup)
Index: newlib/libc/stdlib/on_exit.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/on_exit.c,v
retrieving revision 1.1
diff -c -3 -p -w -r1.1 on_exit.c
*** newlib/libc/stdlib/on_exit.c 15 May 2002 22:58:10 -0000 1.1
--- newlib/libc/stdlib/on_exit.c 29 May 2003 09:56:19 -0000
*************** Supporting OS subroutines required: None
*** 61,67 ****
/*
* Register a function to be performed at exit.
*/
!
int
_DEFUN (on_exit,
(fn, arg),
--- 61,67 ----
/*
* Register a function to be performed at exit.
*/
! #ifndef _NO_ON_EXIT_SUPPORT
int
_DEFUN (on_exit,
(fn, arg),
*************** _DEFUN (on_exit,
*** 94,96 ****
--- 94,97 ----
p->_fns[p->_ind++] = x;
return 0;
}
+ #endif
More information about the Newlib
mailing list