From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id A736D3858D3C; Wed, 18 May 2022 05:58:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A736D3858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Use global atexit data for all configurations X-Act-Checkin: newlib-cygwin X-Git-Author: Sebastian Huber X-Git-Refname: refs/heads/master X-Git-Oldrev: 9035e406cbda2dcab02dde1c6bd7db0a6f6f1563 X-Git-Newrev: 2faeaf50fd3e83a8573d6008f3e927c1d40c3b4a Message-Id: <20220518055824.A736D3858D3C@sourceware.org> Date: Wed, 18 May 2022 05:58:24 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2022 05:58:24 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D2faeaf50fd3= e83a8573d6008f3e927c1d40c3b4a commit 2faeaf50fd3e83a8573d6008f3e927c1d40c3b4a Author: Sebastian Huber Date: Fri May 13 13:44:13 2022 +0200 Use global atexit data for all configurations =20 For the exit processing only members of _GLOBAL_REENT were used by defa= ult. If the _REENT_GLOBAL_ATEXIT option was enabled, then the data structures w= ere provided through dedicated global objects. Make this option the defaul= t. Remove the option. Rename struct _reent members _atexit and _atexit0 to _reserved_6 and _reserved_7, respectively. Provide them only if _REENT_BACKWARD_BINARY_COMPAT is defined. Diff: --- libgloss/arc/crt0.S | 11 +++++----- libgloss/epiphany/crt0.S | 26 ++++++++++------------- libgloss/sparc_leon/locore_atexit.c | 4 ++-- newlib/README | 6 ------ newlib/configure | 9 +------- newlib/configure.ac | 10 +++------ newlib/libc/include/sys/config.h | 1 - newlib/libc/include/sys/reent.h | 41 ++++++++++++++-------------------= ---- newlib/libc/reent/reent.c | 19 ----------------- newlib/libc/stdlib/__atexit.c | 15 +++++--------- newlib/libc/stdlib/__call_atexit.c | 8 +++----- newlib/newlib.hin | 3 --- 12 files changed, 46 insertions(+), 107 deletions(-) diff --git a/libgloss/arc/crt0.S b/libgloss/arc/crt0.S index 46c9efd71..8d9adaa52 100644 --- a/libgloss/arc/crt0.S +++ b/libgloss/arc/crt0.S @@ -187,12 +187,13 @@ __start: ; calling atexit drags in malloc, so instead poke the function ; address directly into the reent structure ld r1, [gp, @_impure_ptr@sda] - mov_s r0, @_fini - add r1, r1, 0x14c ; &_GLOBAL_REENT->atexit0 - st r1, [r1, -4] ; _GLOBAL_REENT->atexit - st_s r0, [r1, 8] ; _GLOBAL_REENT->atexit0._fns[0] + mov_s r1, @__atexit0 + mov_s r2, @__atexit + st_s r1, [r2, 0] ; __atexit =3D &__atexit0 mov_s r0, 1 - st_s r0, [r1, 4] ; _GLOBAL_REENT->atexit0._ind + st_s r0, [r1, 4] ; __atexit0._ind =3D 1 + mov_s r0, @_fini + st_s r0, [r1, 8] ; __atexit0._fns[0] =3D _fini ; branch to _init #if defined (__ARCEM__) || defined (__ARCHS__) jl @_init diff --git a/libgloss/epiphany/crt0.S b/libgloss/epiphany/crt0.S index d684e1e10..b0d9ecbab 100644 --- a/libgloss/epiphany/crt0.S +++ b/libgloss/epiphany/crt0.S @@ -113,23 +113,19 @@ _external_start: #else ; calling atexit drags in malloc, so instead poke the function ; address directly into the reent structure - mov r2,%low(__impure_ptr) - movt r2,%high(__impure_ptr) - ldr r2,[r2] - mov r1,%low(fini) - movt r1,%high(fini) + mov r1,%low(__atexit0) + movt r1,%high(__atexit0) + mov r2,%low(__atexit) + movt r2,%high(__atexit) #ifdef __STRUCT_ALIGN_64__ -#error - add r2,r2,need_to_find_out; &_GLOBAL_REENT->atexit0 - str r2, [r2,-1];??or -2?; _GLOBAL_REENT->atexit - mov r0, 1 - str r0, [r2,1] ; _GLOBAL_REENT->atexit0._ind - str r1, [r2,2] ; _GLOBAL_REENT->atexit0._fns[0] +#error "not implemented" #else /* !__STRUCT_ALIGN_64__ */ - add r0,r2,0x14c ; &_GLOBAL_REENT->atexit0 - str r0, [r0,-1] ; _GLOBAL_REENT->atexit - mov r0, 1 - strd r0, [r2,0x2a] ; _GLOBAL_REENT->atexit0._ind + str r1, [r2, 0] ; __atexit =3D &__atexit0 + movr r0, 1 + str r0, [r1, 4] ; __atexit0._ind =3D 1 + mov r0,%low(fini) + movt r0,%high(fini) + str r0, [r1, 8] ; __atexit0._fns[0] =3D fini #endif /* !__STRUCT_ALIGN_64__ */ #endif /* !0 */ ;; Call global and static constructors diff --git a/libgloss/sparc_leon/locore_atexit.c b/libgloss/sparc_leon/loco= re_atexit.c index b23054c77..e3e6df12f 100644 --- a/libgloss/sparc_leon/locore_atexit.c +++ b/libgloss/sparc_leon/locore_atexit.c @@ -37,9 +37,9 @@ atexit (void (*fn) (void)) { register struct _atexit *p; =20 - p =3D _GLOBAL_REENT->_atexit; + p =3D __atexit; if (p =3D=3D NULL) - _GLOBAL_REENT->_atexit =3D p =3D &_GLOBAL_REENT->_atexit0; + __atexit =3D p =3D &__atexit0; if (p->_ind >=3D _ATEXIT_SIZE) { return -1; diff --git a/newlib/README b/newlib/README index 9de294e9c..f00e66019 100644 --- a/newlib/README +++ b/newlib/README @@ -294,12 +294,6 @@ One feature can be enabled by specifying `--enable-FEA= TURE=3Dyes' or Disable dynamic allocation of atexit entries. Most hosts and targets have it enabled in configure.host. =20 -`--enable-newlib-global-atexit' - Enable atexit data structure as global variable. By doing so it is - move out of _reent structure, and can be garbage collected if atexit - is not referenced. - Disabled by default. - `--enable-newlib-global-stdio-streams' Enable to move the stdio stream FILE objects out of struct _reent and= make them global. The stdio stream pointers of struct _reent are initiali= zed diff --git a/newlib/configure b/newlib/configure index 60cbc1fa8..aa12fdce0 100755 --- a/newlib/configure +++ b/newlib/configure @@ -2373,12 +2373,11 @@ if test "${enable_newlib_global_atexit+set}" =3D se= t; then : enableval=3D$enable_newlib_global_atexit; if test "${newlib_global_atexi= t+set}" !=3D set; then case "${enableval}" in yes) newlib_global_atexit=3Dyes ;; - no) newlib_global_atexit=3Dno ;; *) as_fn_error $? "bad value ${enableval} for newlib-global-atexit o= ption" "$LINENO" 5 ;; esac fi else - newlib_global_atexit=3Dno + newlib_global_atexit=3Dyes fi =20 # Check whether --enable-newlib-reent-small was given. @@ -6484,12 +6483,6 @@ $as_echo "#define _ATEXIT_DYNAMIC_ALLOC 1" >>confdef= s.h =20 fi =20 -if test "${newlib_global_atexit}" =3D "yes"; then - -$as_echo "#define _REENT_GLOBAL_ATEXIT 1" >>confdefs.h - -fi - if test "${newlib_fvwrite_in_streamio}" =3D "yes"; then =20 $as_echo "#define _FVWRITE_IN_STREAMIO 1" >>confdefs.h diff --git a/newlib/configure.ac b/newlib/configure.ac index 12d52c262..57f830960 100644 --- a/newlib/configure.ac +++ b/newlib/configure.ac @@ -142,16 +142,16 @@ AC_ARG_ENABLE(newlib-atexit-dynamic-alloc, =20 dnl Support --enable-newlib-global-atexit dnl Enable atexit data structure as global variables to save memory usage = in -dnl _reent. +dnl _reent. This is no longer optional. It is enabled in all Newlib +dnl configurations. AC_ARG_ENABLE(newlib-global-atexit, [ --enable-newlib-global-atexit enable atexit data structure as global], [if test "${newlib_global_atexit+set}" !=3D set; then case "${enableval}" in yes) newlib_global_atexit=3Dyes ;; - no) newlib_global_atexit=3Dno ;; *) AC_MSG_ERROR(bad value ${enableval} for newlib-global-atexit opti= on) ;; esac - fi], [newlib_global_atexit=3Dno])dnl + fi], [newlib_global_atexit=3Dyes])dnl =20 dnl Support --enable-newlib-reent-small AC_ARG_ENABLE(newlib-reent-small, @@ -470,10 +470,6 @@ if test "${newlib_atexit_dynamic_alloc}" =3D "yes"; th= en AC_DEFINE(_ATEXIT_DYNAMIC_ALLOC, 1, [If atexit() may dynamically allocat= e space for cleanup functions.]) fi =20 -if test "${newlib_global_atexit}" =3D "yes"; then - AC_DEFINE(_REENT_GLOBAL_ATEXIT, 1, [Define if declare atexit data as glo= bal.]) -fi - if test "${newlib_fvwrite_in_streamio}" =3D "yes"; then AC_DEFINE(_FVWRITE_IN_STREAMIO, 1, [Define if ivo supported in streamio.= ]) fi diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/con= fig.h index b4d755957..c40bb51c2 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -242,7 +242,6 @@ #define __FILENAME_MAX__ 255 #define _READ_WRITE_RETURN_TYPE _ssize_t #define __DYNAMIC_REENT__ -#define _REENT_GLOBAL_ATEXIT #define _REENT_GLOBAL_STDIO_STREAMS #endif =20 diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reen= t.h index b99cfe099..4a3cfbd34 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -105,13 +105,6 @@ struct _atexit { # define _ATEXIT_INIT {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}} #endif =20 -#ifdef _REENT_GLOBAL_ATEXIT -# define _REENT_INIT_ATEXIT -#else -# define _REENT_INIT_ATEXIT \ - _NULL, _ATEXIT_INIT, -#endif - /* * Stdio buffers. * @@ -346,10 +339,12 @@ struct _rand48 { #define _REENT_INIT_RESERVED_0 0, #define _REENT_INIT_RESERVED_1 0, #define _REENT_INIT_RESERVED_2 0, +#define _REENT_INIT_RESERVED_6_7 _NULL, _ATEXIT_INIT, #else #define _REENT_INIT_RESERVED_0 /* Nothing to initialize */ #define _REENT_INIT_RESERVED_1 /* Nothing to initialize */ #define _REENT_INIT_RESERVED_2 /* Nothing to initialize */ +#define _REENT_INIT_RESERVED_6_7 /* Nothing to initialize */ #endif =20 /* @@ -428,11 +423,10 @@ struct _reent /* signal info */ void (**(_sig_func))(int); =20 -# ifndef _REENT_GLOBAL_ATEXIT - /* atexit stuff */ - struct _atexit *_atexit; - struct _atexit _atexit0; -# endif +#ifdef _REENT_BACKWARD_BINARY_COMPAT + struct _atexit *_reserved_6; + struct _atexit _reserved_7; +#endif =20 struct _glue __sglue; /* root of glue chain */ __FILE *__sf; /* file descriptors */ @@ -461,7 +455,7 @@ struct _reent _NULL, \ _NULL, \ _NULL, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_RESERVED_6_7 \ {_NULL, 0, _NULL}, \ _NULL, \ _NULL, \ @@ -499,7 +493,7 @@ extern const struct __sFILE_fake __sf_fake_stderr; _NULL, \ _NULL, \ _NULL, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_RESERVED_6_7 \ {_NULL, 0, _NULL}, \ _NULL, \ _NULL, \ @@ -694,11 +688,10 @@ struct _reent #endif } _new; =20 -# ifndef _REENT_GLOBAL_ATEXIT - /* atexit stuff */ - struct _atexit *_atexit; /* points to head of LIFO stack */ - struct _atexit _atexit0; /* one guaranteed table, required by ANSI */ -# endif +#ifdef _REENT_BACKWARD_BINARY_COMPAT + struct _atexit *_reserved_6; + struct _atexit _reserved_7; +#endif =20 /* signal info */ void (**_sig_func)(int); @@ -767,7 +760,7 @@ struct _reent {0, {0}} \ } \ }, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_RESERVED_6_7 \ _NULL \ _REENT_INIT_SGLUE(&(var)) \ } @@ -869,12 +862,8 @@ extern int _fwalk_sglue (struct _reent *, int (*)(stru= ct _reent *, __FILE *), =20 #define _GLOBAL_REENT (&_impure_data) =20 -#ifdef _REENT_GLOBAL_ATEXIT -extern struct _atexit *_global_atexit; /* points to head of LIFO stack */ -# define _GLOBAL_ATEXIT _global_atexit -#else -# define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit) -#endif +extern struct _atexit *__atexit; /* points to head of LIFO stack */ +extern struct _atexit __atexit0; /* one guaranteed table, required by ANSI= */ =20 #ifdef __cplusplus } diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c index 70f1c5f45..04942ce4d 100644 --- a/newlib/libc/reent/reent.c +++ b/newlib/libc/reent/reent.c @@ -93,25 +93,6 @@ _reclaim_reent (struct _reent *ptr) _free_r (ptr, ptr->_misc); #endif =20 -#ifndef _REENT_GLOBAL_ATEXIT - /* atexit stuff */ -# ifdef _REENT_SMALL - if (ptr->_atexit && ptr->_atexit->_on_exit_args_ptr) - _free_r (ptr, ptr->_atexit->_on_exit_args_ptr); -# else - if ((ptr->_atexit) && (ptr->_atexit !=3D &ptr->_atexit0)) - { - struct _atexit *p, *q; - for (p =3D ptr->_atexit; p !=3D &ptr->_atexit0;) - { - q =3D p; - p =3D p->_next; - _free_r (ptr, q); - } - } -# endif -#endif - if (ptr->_cvtbuf) _free_r (ptr, ptr->_cvtbuf); /* We should free _sig_func to avoid a memory leak, but how to diff --git a/newlib/libc/stdlib/__atexit.c b/newlib/libc/stdlib/__atexit.c index ed7af4200..e59f04c2e 100644 --- a/newlib/libc/stdlib/__atexit.c +++ b/newlib/libc/stdlib/__atexit.c @@ -53,12 +53,7 @@ const void * __atexit_dummy =3D &__call_exitprocs; extern _LOCK_RECURSIVE_T __atexit_recursive_mutex; #endif =20 -#ifdef _REENT_GLOBAL_ATEXIT -static struct _atexit _global_atexit0 =3D _ATEXIT_INIT; -# define _GLOBAL_ATEXIT0 (&_global_atexit0) -#else -# define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0) -#endif +struct _atexit __atexit0 =3D _ATEXIT_INIT; =20 /* * Register a function to be performed at exit or on shared library unload. @@ -77,10 +72,10 @@ __register_exitproc (int type, __lock_acquire_recursive(__atexit_recursive_mutex); #endif =20 - p =3D _GLOBAL_ATEXIT; + p =3D __atexit; if (p =3D=3D NULL) { - _GLOBAL_ATEXIT =3D p =3D _GLOBAL_ATEXIT0; + __atexit =3D p =3D &__atexit0; #ifdef _REENT_SMALL extern struct _on_exit_args * const __on_exit_args _ATTRIBUTE ((weak= )); if (&__on_exit_args !=3D NULL) @@ -104,8 +99,8 @@ __register_exitproc (int type, return -1; } p->_ind =3D 0; - p->_next =3D _GLOBAL_ATEXIT; - _GLOBAL_ATEXIT =3D p; + p->_next =3D __atexit; + __atexit =3D p; #ifndef _REENT_SMALL p->_on_exit_args._fntypes =3D 0; p->_on_exit_args._is_cxa =3D 0; diff --git a/newlib/libc/stdlib/__call_atexit.c b/newlib/libc/stdlib/__call= _atexit.c index c29a03c8e..710440389 100644 --- a/newlib/libc/stdlib/__call_atexit.c +++ b/newlib/libc/stdlib/__call_atexit.c @@ -17,9 +17,7 @@ void free(void *) _ATTRIBUTE((__weak__)); __LOCK_INIT_RECURSIVE(, __atexit_recursive_mutex); #endif =20 -#ifdef _REENT_GLOBAL_ATEXIT -struct _atexit *_global_atexit =3D _NULL; -#endif +struct _atexit *__atexit =3D _NULL; =20 #ifdef _WANT_REGISTER_FINI =20 @@ -83,8 +81,8 @@ __call_exitprocs (int code, void *d) =20 restart: =20 - p =3D _GLOBAL_ATEXIT; - lastp =3D &_GLOBAL_ATEXIT; + p =3D __atexit; + lastp =3D &__atexit; while (p) { #ifdef _REENT_SMALL diff --git a/newlib/newlib.hin b/newlib/newlib.hin index 4a9614970..718e5d970 100644 --- a/newlib/newlib.hin +++ b/newlib/newlib.hin @@ -378,9 +378,6 @@ /* Verify _REENT_CHECK macros allocate memory successfully. */ #undef _REENT_CHECK_VERIFY =20 -/* Define if declare atexit data as global. */ -#undef _REENT_GLOBAL_ATEXIT - /* Define if using retargetable functions for default lock routines. */ #undef _RETARGETABLE_LOCKING