2013-07-02 Joey Ye <joey.ye@arm.com>

Lite exit support.
        * README: Add information about lite-exit.
        * acconfig.h (_LITE_EXIT): New macro.
        * configure.in (enable-lite-exit): New option.
        (_LITE_EXIT): Define new macro.
        * configure: Regenerated.
        * newlib.hin (_LITE_EXIT): New macro.
        * libc/stdlib/__atexit.c [_LITE_EXIT]: Add dummy explicit
        reference to __call_exitprocs.
        * libc/stdlib/cxa_atexit.c [_LITE_EXIT]: Make __register_exitproc a
        weak reference.
        * libc/stdlib/exit.c (exit)[_LITE_EXIT]: Remove TWS and weakly reference
        __call_exitprocs.
This commit is contained in:
Jeff Johnston 2013-07-02 21:30:57 +00:00
parent a838011d07
commit e2ac49d3d7
9 changed files with 121 additions and 5 deletions

View File

@ -1,3 +1,19 @@
2013-07-02 Joey Ye <joey.ye@arm.com>
Lite exit support.
* README: Add information about lite-exit.
* acconfig.h (_LITE_EXIT): New macro.
* configure.in (enable-lite-exit): New option.
(_LITE_EXIT): Define new macro.
* configure: Regenerated.
* newlib.hin (_LITE_EXIT): New macro.
* libc/stdlib/__atexit.c [_LITE_EXIT]: Add dummy explicit
reference to __call_exitprocs.
* libc/stdlib/cxa_atexit.c [_LITE_EXIT]: Make __register_exitproc a
weak reference.
* libc/stdlib/exit.c (exit)[_LITE_EXIT]: Remove TWS and weakly reference
__call_exitprocs.
2013-07-02 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/reent.h: Fix typo in comment.

View File

@ -361,6 +361,11 @@ One feature can be enabled by specifying `--enable-FEATURE=yes' or
Disable newlib from supplying syscalls.
Enabled by default.
`--enable-lite-exit'
Enable lite exit, a size-reduced implementation of exit that doesn't
invoke clean-up functions such as _fini or global destructors.
Disabled by default.
Running the Testsuite
=====================

View File

@ -67,6 +67,9 @@
/* Define if unbuffered stream file optimization is supported. */
#undef _UNBUF_STREAM_OPT
/* Define if enable lite version of exit. */
#undef _LITE_EXIT
@BOTTOM@
/*
* Iconv encodings enabled ("to" direction)

26
newlib/configure vendored
View File

@ -794,6 +794,7 @@ enable_newlib_fseek_optimization
enable_newlib_wide_orient
enable_newlib_nano_malloc
enable_newlib_unbuf_stream_opt
enable_lite_exit
enable_multilib
enable_target_optspace
enable_malloc_debugging
@ -1462,6 +1463,7 @@ Optional Features:
--disable-newlib-wide-orient Turn off wide orientation in streamio
--enable-newlib-nano-malloc use small-footprint nano-malloc implementation
--disable-newlib-unbuf-stream-opt disable unbuffered stream optimization in streamio
--enable-lite-exit enable light weight exit
--enable-multilib build many library versions (default)
--enable-target-optspace optimize for space
--enable-malloc-debugging indicate malloc debugging requested
@ -2425,6 +2427,19 @@ else
newlib_unbuf_stream_opt=yes
fi
# Check whether --enable-lite-exit was given.
if test "${enable_lite_exit+set}" = set; then :
enableval=$enable_lite_exit; if test "${lite_exit+set}" != set; then
case "${enableval}" in
yes) lite_exit=yes ;;
no) lite_exit=no ;;
*) as_fn_error $? "bad value ${enableval} for lite-exit option" "$LINENO" 5 ;;
esac
fi
else
lite_exit=no
fi
# Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@ -11725,7 +11740,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11698 "configure"
#line 11743 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -11831,7 +11846,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11804 "configure"
#line 11849 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -12341,6 +12356,13 @@ _ACEOF
fi
if test "${lite_exit}" = "yes"; then
cat >>confdefs.h <<_ACEOF
#define _LITE_EXIT 1
_ACEOF
fi
if test "x${iconv_encodings}" != "x" \
|| test "x${iconv_to_encodings}" != "x" \

View File

@ -181,6 +181,19 @@ AC_ARG_ENABLE(newlib-unbuf-stream-opt,
esac
fi], [newlib_unbuf_stream_opt=yes])dnl
dnl Support --enable-lite-exit
dnl Lite exit is a size-reduced implementation of exit that doesn't invoke
dnl clean-up functions such as _fini or global destructors.
AC_ARG_ENABLE(lite-exit,
[ --enable-lite-exit enable light weight exit],
[if test "${lite_exit+set}" != set; then
case "${enableval}" in
yes) lite_exit=yes ;;
no) lite_exit=no ;;
*) AC_MSG_ERROR(bad value ${enableval} for lite-exit option) ;;
esac
fi], [lite_exit=no])dnl
NEWLIB_CONFIGURE(.)
dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@ -390,6 +403,10 @@ if test "${newlib_unbuf_stream_opt}" = "yes"; then
AC_DEFINE_UNQUOTED(_UNBUF_STREAM_OPT)
fi
if test "${lite_exit}" = "yes"; then
AC_DEFINE_UNQUOTED(_LITE_EXIT)
fi
dnl
dnl Parse --enable-newlib-iconv-encodings option argument
dnl

View File

@ -1,5 +1,35 @@
/*
* Common routine to implement atexit-like functionality.
*
* This is also the key function to be configured as lite exit, a size-reduced
* implementation of exit that doesn't invoke clean-up functions such as _fini
* or global destructors.
*
* Default (without lite exit) call graph is like:
* _start -> atexit -> __register_exitproc
* _start -> __libc_init_array -> __cxa_atexit -> __register_exitproc
* on_exit -> __register_exitproc
* _start -> exit -> __call_exitprocs
*
* Here an -> means arrow tail invokes arrow head. All invocations here
* are non-weak reference in current newlib/libgloss.
*
* Lite exit makes some of above calls as weak reference, so that size expansive
* functions __register_exitproc and __call_exitprocs may not be linked. These
* calls are:
* _start w-> atexit
* __cxa_atexit w-> __register_exitproc
* exit w-> __call_exitprocs
*
* Lite exit also makes sure that __call_exitprocs will be referenced as non-weak
* whenever __register_exitproc is referenced as non-weak.
*
* Thus with lite exit libs, a program not explicitly calling atexit or on_exit
* will escape from the burden of cleaning up code. A program with atexit or on_exit
* will work consistently to normal libs.
*
* Lite exit is enabled with --enable-lite-exit, and is controlled with macro
* _LITE_EXIT.
*/
#include <stddef.h>
@ -11,6 +41,12 @@
/* Make this a weak reference to avoid pulling in malloc. */
void * malloc(size_t) _ATTRIBUTE((__weak__));
#ifdef _LITE_EXIT
/* As __call_exitprocs is weak reference in lite exit, make a
non-weak reference to it here. */
const void * __atexit_dummy = &__call_exitprocs;
#endif
#ifndef __SINGLE_THREAD__
extern _LOCK_RECURSIVE_T __atexit_lock;
#endif

View File

@ -19,5 +19,14 @@ _DEFUN (__cxa_atexit,
void *arg _AND
void *d)
{
return __register_exitproc (__et_cxa, (void (*)(void)) fn, arg, d);
#ifdef _LITE_EXIT
/* Refer to comments in __atexit.c for more details of lite exit. */
int __register_exitproc _PARAMS ((int, void (*fn) (void), _PTR, _PTR))
__attribute__ ((weak));
if (!__register_exitproc)
return 0;
else
#endif
return __register_exitproc (__et_cxa, (void (*)(void)) fn, arg, d);
}

View File

@ -54,11 +54,16 @@ Supporting OS subroutines required: <<_exit>>.
* Exit, flushing stdio buffers if necessary.
*/
void
void
_DEFUN (exit, (code),
int code)
{
__call_exitprocs (code, NULL);
#ifdef _LITE_EXIT
/* Refer to comments in __atexit.c for more details of lite exit. */
void __call_exitprocs _PARAMS ((int, _PTR)) __attribute__((weak));
if (__call_exitprocs)
#endif
__call_exitprocs (code, NULL);
if (_GLOBAL_REENT->__cleanup)
(*_GLOBAL_REENT->__cleanup) (_GLOBAL_REENT);

View File

@ -70,6 +70,9 @@
/* Define if unbuffered stream file optimization is supported. */
#undef _UNBUF_STREAM_OPT
/* Define if lite version of exit supported. */
#undef _LITE_EXIT
/*
* Iconv encodings enabled ("to" direction)
*/