public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option
@ 2022-05-16  6:55 Sebastian Huber
  2022-05-16  6:55 ` [PATCH 1/6] Add --enable-newlib-reent-binary-compat Sebastian Huber
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

This patch set adds the --enable-newlib-reent-binary-compat configure option
which may be used to define the new Newlib configuration option
_REENT_BACKWARD_BINARY_COMPAT.  This option is used to provide binary backward
compatibility for struct _reent by preserving unused members in struct _reent
to keep the structure layout.  Make _REENT_GLOBAL_ATEXIT the default and remove
this option.

v2:

* Rename --enable-newlib-backward-binary-compat in --enable-newlib-reent-binary-compat.

* Do not enable option for Cygwin.

* Adjust code in libgloss.

Sebastian Huber (6):
  Add --enable-newlib-reent-binary-compat
  Optional struct _reent::__unused_sdidinit
  Optional struct _reent::_unspecified_locale_info
  Optional struct _reent::_new::_unused
  Optional struct _reent::_new::_reent::_unused_rand
  Use global atexit data for all configurations

 libgloss/arc/crt0.S                 | 11 +++--
 libgloss/epiphany/crt0.S            | 26 +++++-----
 libgloss/sparc_leon/locore_atexit.c |  4 +-
 newlib/README                       | 12 ++---
 newlib/configure                    | 30 ++++++++----
 newlib/configure.ac                 | 25 +++++++---
 newlib/libc/include/sys/config.h    |  7 ++-
 newlib/libc/include/sys/reent.h     | 74 +++++++++++++++++------------
 newlib/libc/reent/reent.c           | 19 --------
 newlib/libc/stdlib/__atexit.c       | 15 ++----
 newlib/libc/stdlib/__call_atexit.c  |  8 ++--
 newlib/newlib.hin                   |  6 +--
 12 files changed, 125 insertions(+), 112 deletions(-)

-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] Add --enable-newlib-reent-binary-compat
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  2022-05-16 11:18   ` Corinna Vinschen
  2022-05-16  6:55 ` [PATCH 2/6] Optional struct _reent::__unused_sdidinit Sebastian Huber
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

Add the --enable-newlib-reent-binary-compat configure option.  This option is
disabled by default.  If enabled, then unused members in struct _reent are
preserved to maintain the structure layout.
---
 newlib/README                    |  6 ++++++
 newlib/configure                 | 21 +++++++++++++++++++++
 newlib/configure.ac              | 15 +++++++++++++++
 newlib/libc/include/sys/config.h |  6 ++++++
 newlib/newlib.hin                |  3 +++
 5 files changed, 51 insertions(+)

diff --git a/newlib/README b/newlib/README
index 97890b9d2..c99ab47c6 100644
--- a/newlib/README
+++ b/newlib/README
@@ -362,6 +362,12 @@ One feature can be enabled by specifying `--enable-FEATURE=yes' or
      less conversion accuracy.
      Enabled by default.
 
+`--enable-newlib-reent-binary-compat'
+     Enable backward binary compatibility for struct _reent.  If enabled, then
+     unused members in struct _reent are preserved to maintain the structure
+     layout.
+     Disabled by default.
+
 `--enable-multilib'
      Build many library versions.
      Enabled by default.
diff --git a/newlib/configure b/newlib/configure
index c83511da6..4ff02360b 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -972,6 +972,7 @@ enable_newlib_iconv_external_ccs
 enable_newlib_atexit_dynamic_alloc
 enable_newlib_global_atexit
 enable_newlib_reent_small
+enable_newlib_reent_binary_compat
 enable_newlib_global_stdio_streams
 enable_newlib_fvwrite_in_streamio
 enable_newlib_fseek_optimization
@@ -1639,6 +1640,7 @@ Optional Features:
   --disable-newlib-atexit-dynamic-alloc    disable dynamic allocation of atexit entries
   --enable-newlib-global-atexit	enable atexit data structure as global
   --enable-newlib-reent-small   enable small reentrant struct support
+  --enable-newlib-reent-binary-compat   enable backward binary compatibility for struct _reent
   --enable-newlib-global-stdio-streams   enable global stdio streams
   --disable-newlib-fvwrite-in-streamio    disable iov in streamio
   --disable-newlib-fseek-optimization    disable fseek optimization
@@ -2390,6 +2392,19 @@ else
   newlib_reent_small=
 fi
 
+# Check whether --enable-newlib-reent-binary-compat was given.
+if test "${enable_newlib_reent_binary_compat+set}" = set; then :
+  enableval=$enable_newlib_reent_binary_compat; if test "${newlib_enable_reent_binary_compat+set}" != set; then
+  case "${enableval}" in
+    yes) newlib_enable_reent_binary_compat=yes ;;
+    no)  newlib_enable_reent_binary_compat=no  ;;
+    *)   as_fn_error $? "bad value ${enableval} for newlib-enable-reent-binary-compat option" "$LINENO" 5 ;;
+  esac
+ fi
+else
+  newlib_enable_reent_binary_compat=no
+fi
+
 # Check whether --enable-newlib-global-stdio-streams was given.
 if test "${enable_newlib_global_stdio_streams+set}" = set; then :
   enableval=$enable_newlib_global_stdio_streams; case "${enableval}" in
@@ -6418,6 +6433,12 @@ $as_echo "#define _WANT_REENT_SMALL 1" >>confdefs.h
 
 fi
 
+if test "${newlib_enable_reent_binary_compat}" = "yes"; then
+
+$as_echo "#define _WANT_REENT_BACKWARD_BINARY_COMPAT 1" >>confdefs.h
+
+fi
+
 if test "${newlib_global_stdio_streams}" = "yes"; then
 
 $as_echo "#define _WANT_REENT_GLOBAL_STDIO_STREAMS 1" >>confdefs.h
diff --git a/newlib/configure.ac b/newlib/configure.ac
index 195d336f2..7c7297564 100644
--- a/newlib/configure.ac
+++ b/newlib/configure.ac
@@ -162,6 +162,17 @@ AC_ARG_ENABLE(newlib-reent-small,
   *)   AC_MSG_ERROR(bad value ${enableval} for newlib-reent-small option) ;;
  esac], [newlib_reent_small=])dnl
 
+dnl Support --enable-newlib-reent-binary-compat
+AC_ARG_ENABLE(newlib-reent-binary-compat,
+[  --enable-newlib-reent-binary-compat   enable backward binary compatibility for struct _reent],
+[if test "${newlib_enable_reent_binary_compat+set}" != set; then
+  case "${enableval}" in
+    yes) newlib_enable_reent_binary_compat=yes ;;
+    no)  newlib_enable_reent_binary_compat=no  ;;
+    *)   AC_MSG_ERROR(bad value ${enableval} for newlib-enable-reent-binary-compat option) ;;
+  esac
+ fi], [newlib_enable_reent_binary_compat=no])dnl
+
 dnl Support --enable-newlib-global-stdio-streams
 AC_ARG_ENABLE(newlib-global-stdio-streams,
 [  --enable-newlib-global-stdio-streams   enable global stdio streams],
@@ -420,6 +431,10 @@ if test "${newlib_reent_small}" = "yes"; then
   AC_DEFINE(_WANT_REENT_SMALL, 1, [Optional reentrant struct support.  Used mostly on platforms with very restricted storage.])
 fi
 
+if test "${newlib_enable_reent_binary_compat}" = "yes"; then
+  AC_DEFINE(_WANT_REENT_BACKWARD_BINARY_COMPAT, 1, [Define to enable backward binary compatibility for struct _reent.])
+fi
+
 if test "${newlib_global_stdio_streams}" = "yes"; then
   AC_DEFINE(_WANT_REENT_GLOBAL_STDIO_STREAMS, 1,
 	    [Define to move the stdio stream FILE objects out of struct _reent and make them global.
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 61a6f95d8..b4d755957 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -299,6 +299,12 @@
 #endif
 #endif
 
+#ifdef _WANT_REENT_BACKWARD_BINARY_COMPAT
+#ifndef _REENT_BACKWARD_BINARY_COMPAT
+#define _REENT_BACKWARD_BINARY_COMPAT
+#endif
+#endif
+
 /* If _MB_EXTENDED_CHARSETS_ALL is set, we want all of the extended
    charsets.  The extended charsets add a few functions and a couple
    of tables of a few K each. */
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index b52bc7460..4a9614970 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -402,6 +402,9 @@
 /* Positional argument support in printf functions enabled. */
 #undef _WANT_IO_POS_ARGS
 
+/* Define to enable backward binary compatibility for struct _reent. */
+#undef _WANT_REENT_BACKWARD_BINARY_COMPAT
+
 /* Define to move the stdio stream FILE objects out of struct _reent and make
    them global. The stdio stream pointers of struct _reent are initialized to
    point to the global stdio FILE stream objects. */
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/6] Optional struct _reent::__unused_sdidinit
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
  2022-05-16  6:55 ` [PATCH 1/6] Add --enable-newlib-reent-binary-compat Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  2022-05-16  6:55 ` [PATCH 3/6] Optional struct _reent::_unspecified_locale_info Sebastian Huber
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

Provide struct _reent::__unused_sdidinit only if _REENT_BACKWARD_BINARY_COMPAT
is defined.
---
 newlib/libc/include/sys/reent.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index fa9ac57da..e2fd0b422 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -342,6 +342,12 @@ struct _rand48 {
 #define _REENT_ASCTIME_SIZE 26
 #define _REENT_SIGNAL_SIZE 24
 
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
+#define _REENT_INIT_UNUSED_SDIDINIT 0,
+#else
+#define _REENT_INIT_UNUSED_SDIDINIT /* Nothing to initialize */
+#endif
+
 /*
  * struct _reent
  *
@@ -395,9 +401,11 @@ struct _reent
 
   char *_emergency;
 
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   /* No longer used, but member retained for binary compatibility.
      Now, the __cleanup member is used to check initialization. */
   int _unused_sdidinit;
+#endif
 
   int _unspecified_locale_info;	/* unused, reserved for locale stuff */
   struct __locale_t *_locale;/* per-thread locale */
@@ -440,7 +448,7 @@ struct _reent
     &__sf[2], \
     0,   \
     _NULL, \
-    0, \
+    _REENT_INIT_UNUSED_SDIDINIT \
     0, \
     _NULL, \
     _NULL, \
@@ -478,7 +486,7 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     (__FILE *)&__sf_fake_stderr, \
     0, \
     _NULL, \
-    0, \
+    _REENT_INIT_UNUSED_SDIDINIT \
     0, \
     _NULL, \
     _NULL, \
@@ -633,9 +641,11 @@ struct _reent
   int _unspecified_locale_info;	/* unused, reserved for locale stuff */
   struct __locale_t *_locale;/* per-thread locale */
 
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   /* No longer used, but member retained for binary compatibility.
      Now, the __cleanup member is used to check initialization. */
   int _unused_sdidinit;
+#endif
 
   void (*__cleanup) (struct _reent *);
 
@@ -723,7 +733,7 @@ struct _reent
     "", \
     0, \
     _NULL, \
-    0, \
+    _REENT_INIT_UNUSED_SDIDINIT \
     _NULL, \
     _NULL, \
     0, \
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/6] Optional struct _reent::_unspecified_locale_info
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
  2022-05-16  6:55 ` [PATCH 1/6] Add --enable-newlib-reent-binary-compat Sebastian Huber
  2022-05-16  6:55 ` [PATCH 2/6] Optional struct _reent::__unused_sdidinit Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  2022-05-16  6:55 ` [PATCH 4/6] Optional struct _reent::_new::_unused Sebastian Huber
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

Provide struct _reent::_unspecified_locale_info only if
_REENT_BACKWARD_BINARY_COMPAT is defined.
---
 newlib/libc/include/sys/reent.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index e2fd0b422..5f557111e 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -343,8 +343,10 @@ struct _rand48 {
 #define _REENT_SIGNAL_SIZE 24
 
 #ifdef _REENT_BACKWARD_BINARY_COMPAT
+#define _REENT_INIT_UNUSED_LOCALE_INFO 0,
 #define _REENT_INIT_UNUSED_SDIDINIT 0,
 #else
+#define _REENT_INIT_UNUSED_LOCALE_INFO /* Nothing to initialize */
 #define _REENT_INIT_UNUSED_SDIDINIT /* Nothing to initialize */
 #endif
 
@@ -405,9 +407,9 @@ struct _reent
   /* No longer used, but member retained for binary compatibility.
      Now, the __cleanup member is used to check initialization. */
   int _unused_sdidinit;
-#endif
 
   int _unspecified_locale_info;	/* unused, reserved for locale stuff */
+#endif
   struct __locale_t *_locale;/* per-thread locale */
 
   struct _mprec *_mp;
@@ -449,7 +451,7 @@ struct _reent
     0,   \
     _NULL, \
     _REENT_INIT_UNUSED_SDIDINIT \
-    0, \
+    _REENT_INIT_UNUSED_LOCALE_INFO \
     _NULL, \
     _NULL, \
     _NULL, \
@@ -487,7 +489,7 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     0, \
     _NULL, \
     _REENT_INIT_UNUSED_SDIDINIT \
-    0, \
+    _REENT_INIT_UNUSED_LOCALE_INFO \
     _NULL, \
     _NULL, \
     _NULL, \
@@ -638,7 +640,9 @@ struct _reent
   char _emergency[_REENT_EMERGENCY_SIZE];
 
   /* TODO */
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   int _unspecified_locale_info;	/* unused, reserved for locale stuff */
+#endif
   struct __locale_t *_locale;/* per-thread locale */
 
 #ifdef _REENT_BACKWARD_BINARY_COMPAT
@@ -731,7 +735,7 @@ struct _reent
     _REENT_STDIO_STREAM(&(var), 2), \
     0, \
     "", \
-    0, \
+    _REENT_INIT_UNUSED_LOCALE_INFO \
     _NULL, \
     _REENT_INIT_UNUSED_SDIDINIT \
     _NULL, \
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/6] Optional struct _reent::_new::_unused
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
                   ` (2 preceding siblings ...)
  2022-05-16  6:55 ` [PATCH 3/6] Optional struct _reent::_unspecified_locale_info Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  2022-05-16  6:55 ` [PATCH 5/6] Optional struct _reent::_new::_reent::_unused_rand Sebastian Huber
  2022-05-16  6:55 ` [PATCH 6/6] Use global atexit data for all configurations Sebastian Huber
  5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

Provide struct _reent::_new::_unused only if _REENT_BACKWARD_BINARY_COMPAT is
defined.
---
 newlib/libc/include/sys/reent.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 5f557111e..1884ed982 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -687,6 +687,7 @@ struct _reent
           _mbstate_t _wcsrtombs_state;
 	  int _h_errno;
         } _reent;
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   /* 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.   */
@@ -696,6 +697,7 @@ struct _reent
           unsigned char * _nextf[_N_LISTS];
           unsigned int _nmalloc[_N_LISTS];
         } _unused;
+#endif
     } _new;
 
 # ifndef _REENT_GLOBAL_ATEXIT
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/6] Optional struct _reent::_new::_reent::_unused_rand
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
                   ` (3 preceding siblings ...)
  2022-05-16  6:55 ` [PATCH 4/6] Optional struct _reent::_new::_unused Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  2022-05-16  6:55 ` [PATCH 6/6] Use global atexit data for all configurations Sebastian Huber
  5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

Provide struct _reent::_new::_reent::_unused_rand only if
_REENT_BACKWARD_BINARY_COMPAT is defined.
---
 newlib/libc/include/sys/reent.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 1884ed982..4683ecc2f 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -344,9 +344,11 @@ struct _rand48 {
 
 #ifdef _REENT_BACKWARD_BINARY_COMPAT
 #define _REENT_INIT_UNUSED_LOCALE_INFO 0,
+#define _REENT_INIT_UNUSED_RAND 0,
 #define _REENT_INIT_UNUSED_SDIDINIT 0,
 #else
 #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 */
 #endif
 
@@ -667,7 +669,9 @@ struct _reent
     {
       struct
         {
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
           unsigned int _unused_rand;
+#endif
           char * _strtok_last;
           char _asctime_buf[_REENT_ASCTIME_SIZE];
           struct __tm _localtime_buf;
@@ -749,7 +753,7 @@ struct _reent
     _NULL, \
     { \
       { \
-        0, \
+        _REENT_INIT_UNUSED_RAND \
         _NULL, \
         "", \
         {0, 0, 0, 0, 0, 0, 0, 0, 0}, \
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/6] Use global atexit data for all configurations
  2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
                   ` (4 preceding siblings ...)
  2022-05-16  6:55 ` [PATCH 5/6] Optional struct _reent::_new::_reent::_unused_rand Sebastian Huber
@ 2022-05-16  6:55 ` Sebastian Huber
  5 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16  6:55 UTC (permalink / raw)
  To: newlib

For the exit processing only members of _GLOBAL_REENT were used by default.  If
the _REENT_GLOBAL_ATEXIT option was enabled, then the data structures were
provided to dedicated global objects.  Make this option the default.  Remove
the option.  Provide the struct _reent _atexit and atexit members only if
backward binary compatibility is requested (_REENT_BACKWARD_BINARY_COMPAT).
---
 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     | 39 +++++++++++------------------
 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(+), 105 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 = &__atexit0
 	mov_s	r0, 1
-	st_s	r0, [r1, 4]		; _GLOBAL_REENT->atexit0._ind
+	st_s	r0, [r1, 4]		; __atexit0._ind = 1
+	mov_s	r0, @_fini
+	st_s	r0, [r1, 8]		; __atexit0._fns[0] = _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 = &__atexit0
+	movr	r0, 1
+	str	r0, [r1, 4]	; __atexit0._ind = 1
+	mov	r0,%low(fini)
+	movt	r0,%high(fini)
+	str	r0, [r1, 8]	; __atexit0._fns[0] = 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/locore_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;
 
-  p = _GLOBAL_REENT->_atexit;
+  p = __atexit;
   if (p == NULL)
-    _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
+    __atexit = p = &__atexit0;
   if (p->_ind >= _ATEXIT_SIZE)
     {
       return -1;
diff --git a/newlib/README b/newlib/README
index c99ab47c6..68747c588 100644
--- a/newlib/README
+++ b/newlib/README
@@ -294,12 +294,6 @@ One feature can be enabled by specifying `--enable-FEATURE=yes' or
      Disable dynamic allocation of atexit entries.
      Most hosts and targets have it enabled in configure.host.
 
-`--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 initialized
diff --git a/newlib/configure b/newlib/configure
index 4ff02360b..0114e2913 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -2373,12 +2373,11 @@ if test "${enable_newlib_global_atexit+set}" = set; then :
   enableval=$enable_newlib_global_atexit; if test "${newlib_global_atexit+set}" != set; then
   case "${enableval}" in
     yes) newlib_global_atexit=yes ;;
-    no)  newlib_global_atexit=no  ;;
     *)   as_fn_error $? "bad value ${enableval} for newlib-global-atexit option" "$LINENO" 5 ;;
   esac
  fi
 else
-  newlib_global_atexit=no
+  newlib_global_atexit=yes
 fi
 
 # Check whether --enable-newlib-reent-small was given.
@@ -6484,12 +6483,6 @@ $as_echo "#define _ATEXIT_DYNAMIC_ALLOC 1" >>confdefs.h
 
 fi
 
-if test "${newlib_global_atexit}" = "yes"; then
-
-$as_echo "#define _REENT_GLOBAL_ATEXIT 1" >>confdefs.h
-
-fi
-
 if test "${newlib_fvwrite_in_streamio}" = "yes"; then
 
 $as_echo "#define _FVWRITE_IN_STREAMIO 1" >>confdefs.h
diff --git a/newlib/configure.ac b/newlib/configure.ac
index 7c7297564..5be09fcd4 100644
--- a/newlib/configure.ac
+++ b/newlib/configure.ac
@@ -142,16 +142,16 @@ AC_ARG_ENABLE(newlib-atexit-dynamic-alloc,
 
 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}" != set; then
   case "${enableval}" in
     yes) newlib_global_atexit=yes ;;
-    no)  newlib_global_atexit=no  ;;
     *)   AC_MSG_ERROR(bad value ${enableval} for newlib-global-atexit option) ;;
   esac
- fi], [newlib_global_atexit=no])dnl
+ fi], [newlib_global_atexit=yes])dnl
 
 dnl Support --enable-newlib-reent-small
 AC_ARG_ENABLE(newlib-reent-small,
@@ -470,10 +470,6 @@ if test "${newlib_atexit_dynamic_alloc}" = "yes"; then
   AC_DEFINE(_ATEXIT_DYNAMIC_ALLOC, 1, [If atexit() may dynamically allocate space for cleanup functions.])
 fi
 
-if test "${newlib_global_atexit}" = "yes"; then
-  AC_DEFINE(_REENT_GLOBAL_ATEXIT, 1, [Define if declare atexit data as global.])
-fi
-
 if test "${newlib_fvwrite_in_streamio}" = "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/config.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
 
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 4683ecc2f..ab6188958 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
 
-#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
 
 #ifdef _REENT_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);
 
-# ifndef _REENT_GLOBAL_ATEXIT
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   /* atexit stuff */
-  struct _atexit *_atexit;
-  struct _atexit _atexit0;
-# endif
+  struct _atexit *_unused_atexit;
+  struct _atexit _unused_atexit0;
+#endif
 
   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;
 
-# ifndef _REENT_GLOBAL_ATEXIT
+#ifdef _REENT_BACKWARD_BINARY_COMPAT
   /* atexit stuff */
-  struct _atexit *_atexit;	/* points to head of LIFO stack */
-  struct _atexit _atexit0;	/* one guaranteed table, required by ANSI */
-# endif
+  struct _atexit *_unused_atexit;
+  struct _atexit _unused_atexit0;
+#endif
 
   /* 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,8 @@ extern int _fwalk_sglue (struct _reent *, int (*)(struct _reent *, __FILE *),
 
 #define _GLOBAL_REENT (&_impure_data)
 
-#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 */
 
 #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
 
-#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 != &ptr->_atexit0))
-	{
-	  struct _atexit *p, *q;
-	  for (p = ptr->_atexit; p != &ptr->_atexit0;)
-	    {
-	      q = p;
-	      p = 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..04bdf194e 100644
--- a/newlib/libc/stdlib/__atexit.c
+++ b/newlib/libc/stdlib/__atexit.c
@@ -53,12 +53,7 @@ const void * __atexit_dummy = &__call_exitprocs;
 extern _LOCK_RECURSIVE_T __atexit_recursive_mutex;
 #endif
 
-#ifdef _REENT_GLOBAL_ATEXIT
-static struct _atexit _global_atexit0 = _ATEXIT_INIT;
-# define _GLOBAL_ATEXIT0 (&_global_atexit0)
-#else
-# define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0)
-#endif
+struct _atexit __atexit0 = _ATEXIT_INIT;
 
 /*
  * 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
 
-  p = _GLOBAL_ATEXIT;
+  p = __atexit;
   if (p == NULL)
     {
-      _GLOBAL_ATEXIT = p = _GLOBAL_ATEXIT0;
+      __atexit = p = &__atexit0;
 #ifdef _REENT_SMALL
       extern struct _on_exit_args * const __on_exit_args _ATTRIBUTE ((weak));
       if (&__on_exit_args != NULL)
@@ -104,8 +99,8 @@ __register_exitproc (int type,
 	  return -1;
 	}
       p->_ind = 0;
-      p->_next = _GLOBAL_ATEXIT;
-      _GLOBAL_ATEXIT = p;
+      p->_next = __atexit;
+      __atexit = p;
 #ifndef _REENT_SMALL
       p->_on_exit_args._fntypes = 0;
       p->_on_exit_args._is_cxa = 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
 
-#ifdef _REENT_GLOBAL_ATEXIT
-struct _atexit *_global_atexit = _NULL;
-#endif
+struct _atexit *__atexit = _NULL;
 
 #ifdef _WANT_REGISTER_FINI
 
@@ -83,8 +81,8 @@ __call_exitprocs (int code, void *d)
 
  restart:
 
-  p = _GLOBAL_ATEXIT;
-  lastp = &_GLOBAL_ATEXIT;
+  p = __atexit;
+  lastp = &__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
 
-/* Define if declare atexit data as global. */
-#undef _REENT_GLOBAL_ATEXIT
-
 /* Define if using retargetable functions for default lock routines. */
 #undef _RETARGETABLE_LOCKING
 
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] Add --enable-newlib-reent-binary-compat
  2022-05-16  6:55 ` [PATCH 1/6] Add --enable-newlib-reent-binary-compat Sebastian Huber
@ 2022-05-16 11:18   ` Corinna Vinschen
  2022-05-16 11:54     ` Sebastian Huber
  0 siblings, 1 reply; 9+ messages in thread
From: Corinna Vinschen @ 2022-05-16 11:18 UTC (permalink / raw)
  To: newlib

On May 16 08:55, Sebastian Huber wrote:
> Add the --enable-newlib-reent-binary-compat configure option.  This option is
> disabled by default.  If enabled, then unused members in struct _reent are
> preserved to maintain the structure layout.

Given these members are unused, we can reuse them for other purposes.
The only interesting thing is to keep the existing and still used
members in the same offset.  Along these lines, wouldn't it
be great for potential future stuff we would like to add
to _reent, if we take the chance and rename the unused members to

   int _reserved1;
   [...]
   int _reserved2[2];

etc.?  The latter array style would be possible, for instance, with
_unused_sdidinit and _unspecified_locale_info, because they happen to
clump together. The old comments describeing what has been at one
point, could go away, and the layout may become just this teeny little
bit cleaner...

What do you think?


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] Add --enable-newlib-reent-binary-compat
  2022-05-16 11:18   ` Corinna Vinschen
@ 2022-05-16 11:54     ` Sebastian Huber
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Huber @ 2022-05-16 11:54 UTC (permalink / raw)
  To: newlib

On 16/05/2022 13:18, Corinna Vinschen wrote:
> On May 16 08:55, Sebastian Huber wrote:
>> Add the --enable-newlib-reent-binary-compat configure option.  This option is
>> disabled by default.  If enabled, then unused members in struct _reent are
>> preserved to maintain the structure layout.
> Given these members are unused, we can reuse them for other purposes.
> The only interesting thing is to keep the existing and still used
> members in the same offset.  Along these lines, wouldn't it
> be great for potential future stuff we would like to add
> to _reent, if we take the chance and rename the unused members to
> 
>     int _reserved1;
>     [...]
>     int _reserved2[2];
> 
> etc.?  The latter array style would be possible, for instance, with
> _unused_sdidinit and _unspecified_locale_info, because they happen to
> clump together. The old comments describeing what has been at one
> point, could go away, and the layout may become just this teeny little
> bit cleaner...
> 
> What do you think?

Yes, this sounds good. I will update the patch set.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-16 11:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  6:55 [PATCH 0/6] Add --enable-newlib-reent-binary-compat configure option Sebastian Huber
2022-05-16  6:55 ` [PATCH 1/6] Add --enable-newlib-reent-binary-compat Sebastian Huber
2022-05-16 11:18   ` Corinna Vinschen
2022-05-16 11:54     ` Sebastian Huber
2022-05-16  6:55 ` [PATCH 2/6] Optional struct _reent::__unused_sdidinit Sebastian Huber
2022-05-16  6:55 ` [PATCH 3/6] Optional struct _reent::_unspecified_locale_info Sebastian Huber
2022-05-16  6:55 ` [PATCH 4/6] Optional struct _reent::_new::_unused Sebastian Huber
2022-05-16  6:55 ` [PATCH 5/6] Optional struct _reent::_new::_reent::_unused_rand Sebastian Huber
2022-05-16  6:55 ` [PATCH 6/6] Use global atexit data for all configurations Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).