From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id DE2A2395C41A for ; Fri, 13 May 2022 13:47:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE2A2395C41A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy02.your-server.de ([78.47.166.47]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1npVdJ-000A8q-HV for newlib@sourceware.org; Fri, 13 May 2022 15:47:05 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1npVdJ-000P4W-MF for newlib@sourceware.org; Fri, 13 May 2022 15:47:05 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 6CF97480181 for ; Fri, 13 May 2022 15:47:05 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id RSsLLsvNJaqE for ; Fri, 13 May 2022 15:47:03 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 36A63480196 for ; Fri, 13 May 2022 15:47:03 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id K2I5EFrkiPHl for ; Fri, 13 May 2022 15:47:03 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 06252480195 for ; Fri, 13 May 2022 15:47:03 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 7/7] Use global atexit data for all configurations Date: Fri, 13 May 2022 15:47:00 +0200 Message-Id: <20220513134700.68563-8-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220513134700.68563-1-sebastian.huber@embedded-brains.de> References: <20220513134700.68563-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26540/Fri May 13 10:03:59 2022) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 13:47:12 -0000 For the exit processing only members of _GLOBAL_REENT were used by defaul= t. If the _REENT_GLOBAL_ATEXIT option was enabled, then the data structures wer= e provided to dedicated global objects. Make this option the default. Rem= ove the option. Provide the struct _reent _atexit and atexit members only if backward binary compatibility is requested (_NEWLIB_BACKWARD_BINARY_COMPA= T). --- newlib/README | 6 ------ newlib/configure | 7 ------- newlib/configure.ac | 8 ++------ newlib/libc/include/sys/config.h | 1 - newlib/libc/include/sys/reent.h | 30 ++++++++++-------------------- newlib/libc/reent/reent.c | 19 ------------------- newlib/libc/stdlib/__atexit.c | 15 +++++---------- newlib/libc/stdlib/__call_atexit.c | 8 +++----- newlib/newlib.hin | 3 --- 9 files changed, 20 insertions(+), 77 deletions(-) diff --git a/newlib/README b/newlib/README index 54921893f..8cf37c5ef 100644 --- a/newlib/README +++ b/newlib/README @@ -294,12 +294,6 @@ One feature can be enabled by specifying `--enable-F= EATURE=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 atexi= t - is not referenced. - Disabled by default. - `--enable-newlib-global-stdio-streams' Enable to move the stdio stream FILE objects out of struct _reent a= nd make them global. The stdio stream pointers of struct _reent are initia= lized diff --git a/newlib/configure b/newlib/configure index 6ea3f5631..02e243de7 100755 --- a/newlib/configure +++ b/newlib/configure @@ -2373,7 +2373,6 @@ if test "${enable_newlib_global_atexit+set}" =3D se= t; then : enableval=3D$enable_newlib_global_atexit; if test "${newlib_global_ate= xit+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= option" "$LINENO" 5 ;; esac fi @@ -6478,12 +6477,6 @@ $as_echo "#define _ATEXIT_DYNAMIC_ALLOC 1" >>confd= efs.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 556580967..196daeb0a 100644 --- a/newlib/configure.ac +++ b/newlib/configure.ac @@ -142,13 +142,13 @@ 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 usag= e 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 op= tion) ;; esac fi], [newlib_global_atexit=3Dno])dnl @@ -466,10 +466,6 @@ if test "${newlib_atexit_dynamic_alloc}" =3D "yes"; = then AC_DEFINE(_ATEXIT_DYNAMIC_ALLOC, 1, [If atexit() may dynamically alloc= ate 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 g= lobal.]) -fi - if test "${newlib_fvwrite_in_streamio}" =3D "yes"; then AC_DEFINE(_FVWRITE_IN_STREAMIO, 1, [Define if ivo supported in streami= o.]) fi diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/c= onfig.h index fbc1e0fe1..7bbba2497 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/re= ent.h index c21f11de2..d1d84ffe5 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. * @@ -343,10 +336,12 @@ struct _rand48 { #define _REENT_SIGNAL_SIZE 24 =20 #ifdef _NEWLIB_BACKWARD_BINARY_COMPAT +#define _REENT_INIT_UNUSED_ATEXIT _NULL, _ATEXIT_INIT, #define _REENT_INIT_UNUSED_LOCALE_INFO 0, #define _REENT_INIT_UNUSED_RAND 0, #define _REENT_INIT_UNUSED_SDIDINIT 0, #else +#define _REENT_INIT_UNUSED_ATEXIT /* Nothing to initialize */ #define _REENT_INIT_UNUSED_LOCALE_INFO /* Nothing to initialize */ #define _REENT_INIT_UNUSED_RAND /* Nothing to initialize */ #define _REENT_INIT_UNUSED_SDIDINIT /* Nothing to initialize */ @@ -431,11 +426,11 @@ struct _reent /* signal info */ void (**(_sig_func))(int); =20 -# ifndef _REENT_GLOBAL_ATEXIT +#ifdef _NEWLIB_BACKWARD_BINARY_COMPAT /* atexit stuff */ struct _atexit *_atexit; struct _atexit _atexit0; -# endif +#endif =20 struct _glue __sglue; /* root of glue chain */ __FILE *__sf; /* file descriptors */ @@ -464,7 +459,7 @@ struct _reent _NULL, \ _NULL, \ _NULL, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_UNUSED_ATEXIT \ {_NULL, 0, _NULL}, \ _NULL, \ _NULL, \ @@ -502,7 +497,7 @@ extern const struct __sFILE_fake __sf_fake_stderr; _NULL, \ _NULL, \ _NULL, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_UNUSED_ATEXIT \ {_NULL, 0, _NULL}, \ _NULL, \ _NULL, \ @@ -704,11 +699,11 @@ struct _reent #endif } _new; =20 -# ifndef _REENT_GLOBAL_ATEXIT +#ifdef _NEWLIB_BACKWARD_BINARY_COMPAT /* atexit stuff */ struct _atexit *_atexit; /* points to head of LIFO stack */ struct _atexit _atexit0; /* one guaranteed table, required by ANSI */ -# endif +#endif =20 /* signal info */ void (**_sig_func)(int); @@ -777,7 +772,7 @@ struct _reent {0, {0}} \ } \ }, \ - _REENT_INIT_ATEXIT \ + _REENT_INIT_UNUSED_ATEXIT \ _NULL \ _REENT_INIT_SGLUE(&(var)) \ } @@ -879,12 +874,7 @@ extern int _fwalk_sglue (struct _reent *, int (*)(st= ruct _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 */ =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 97ce053bf..3f7bf8c2b 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 +static struct _atexit atexit0 =3D _ATEXIT_INIT; =20 /* * Register a function to be performed at exit or on shared library unlo= ad. @@ -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 ((we= ak)); 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/__ca= ll_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 cf3086c32..f59fc57aa 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 =20 --=20 2.35.3