public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Remove use of _global_impure_ptr
@ 2022-05-03 13:40 Sebastian Huber
  2022-05-04 13:34 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Huber @ 2022-05-03 13:40 UTC (permalink / raw)
  To: newlib

Remove the pointer indrection through the read-only _global_impure_ptr and
directly use a globally visible _impure_data object of type struct reent.  This
enables the static initialization of global data structures in a follow up
patch.  In addition, we get rid of a machine-specific file.
---
 newlib/Makefile.in                   | 42 ++++++++++++++--------------
 newlib/libc/include/sys/reent.h      |  9 ++++--
 newlib/libc/machine/spu/Makefile.inc |  2 +-
 newlib/libc/machine/spu/impure.c     | 14 ----------
 newlib/libc/machine/spu/sys/errno.h  |  1 -
 newlib/libc/reent/Makefile.inc       |  1 +
 newlib/libc/reent/impure-compat.c    |  5 ++++
 newlib/libc/reent/impure.c           | 16 ++---------
 winsup/cygwin/dcrt0.cc               |  2 +-
 9 files changed, 39 insertions(+), 53 deletions(-)
 delete mode 100644 newlib/libc/machine/spu/impure.c
 create mode 100644 newlib/libc/reent/impure-compat.c

diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 41e41412b..aa0e710a6 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -816,7 +816,7 @@ check_PROGRAMS =
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/ferror.c libc/machine/spu/fflush.c libc/machine/spu/fgetc.c libc/machine/spu/fgetpos.c libc/machine/spu/fgets.c libc/machine/spu/fileno.c libc/machine/spu/fiprintf.S \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/fiscanf.S libc/machine/spu/fopen.c libc/machine/spu/fprintf.S libc/machine/spu/fputc.c libc/machine/spu/fputs.c libc/machine/spu/fread.c libc/machine/spu/freopen.c \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/fscanf.S libc/machine/spu/fseek.c libc/machine/spu/fsetpos.c libc/machine/spu/ftell.c libc/machine/spu/fwrite.c libc/machine/spu/getc.c libc/machine/spu/getchar.c \
-@HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/gets.c libc/machine/spu/impure.c libc/machine/spu/iprintf.S libc/machine/spu/iscanf.S libc/machine/spu/memcmp.c libc/machine/spu/memcpy.c libc/machine/spu/memmove.c \
+@HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/gets.c libc/machine/spu/iprintf.S libc/machine/spu/iscanf.S libc/machine/spu/memcmp.c libc/machine/spu/memcpy.c libc/machine/spu/memmove.c \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/memset.c libc/machine/spu/perror.c libc/machine/spu/printf.S libc/machine/spu/putc.c libc/machine/spu/putchar.c libc/machine/spu/puts.c libc/machine/spu/remove.c \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/rename.c libc/machine/spu/rewind.c libc/machine/spu/scanf.S libc/machine/spu/setbuf.c libc/machine/spu/setvbuf.c libc/machine/spu/siprintf.S libc/machine/spu/siscanf.S \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/sleep.c libc/machine/spu/sniprintf.S libc/machine/spu/snprintf.S libc/machine/spu/sprintf.S libc/machine/spu/sscanf.S libc/machine/spu/stdio.c libc/machine/spu/strcat.c \
@@ -2131,7 +2131,6 @@ am__objects_51 = libc/ssp/libc_a-chk_fail.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-getc.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-getchar.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-gets.$(OBJEXT) \
-@HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-impure.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-iprintf.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-iscanf.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_SPU_TRUE@	libc/machine/spu/libc_a-memcmp.$(OBJEXT) \
@@ -2506,6 +2505,7 @@ am_libc_a_OBJECTS = $(am__objects_1) \
 	libc/reent/libc_a-closer.$(OBJEXT) \
 	libc/reent/libc_a-reent.$(OBJEXT) \
 	libc/reent/libc_a-impure.$(OBJEXT) \
+	libc/reent/libc_a-impure-compat.$(OBJEXT) \
 	libc/reent/libc_a-fcntlr.$(OBJEXT) \
 	libc/reent/libc_a-fstatr.$(OBJEXT) \
 	libc/reent/libc_a-getreent.$(OBJEXT) \
@@ -3900,7 +3900,8 @@ libc_a_SOURCES = $(am__append_6) libc/stdlib/__adjust.c \
 	libc/time/tzset_r.c libc/time/tzvars.c libc/time/wcsftime.c \
 	libc/locale/setlocale.h libc/locale/locale.c \
 	libc/locale/localeconv.c $(am__append_20) libc/reent/closer.c \
-	libc/reent/reent.c libc/reent/impure.c libc/reent/fcntlr.c \
+	libc/reent/reent.c libc/reent/impure.c \
+	libc/reent/impure-compat.c libc/reent/fcntlr.c \
 	libc/reent/fstatr.c libc/reent/getreent.c \
 	libc/reent/gettimeofdayr.c libc/reent/isattyr.c \
 	libc/reent/linkr.c libc/reent/lseekr.c libc/reent/mkdirr.c \
@@ -6161,6 +6162,8 @@ libc/reent/libc_a-reent.$(OBJEXT): libc/reent/$(am__dirstamp) \
 	libc/reent/$(DEPDIR)/$(am__dirstamp)
 libc/reent/libc_a-impure.$(OBJEXT): libc/reent/$(am__dirstamp) \
 	libc/reent/$(DEPDIR)/$(am__dirstamp)
+libc/reent/libc_a-impure-compat.$(OBJEXT): libc/reent/$(am__dirstamp) \
+	libc/reent/$(DEPDIR)/$(am__dirstamp)
 libc/reent/libc_a-fcntlr.$(OBJEXT): libc/reent/$(am__dirstamp) \
 	libc/reent/$(DEPDIR)/$(am__dirstamp)
 libc/reent/libc_a-fstatr.$(OBJEXT): libc/reent/$(am__dirstamp) \
@@ -8812,9 +8815,6 @@ libc/machine/spu/libc_a-getchar.$(OBJEXT):  \
 libc/machine/spu/libc_a-gets.$(OBJEXT):  \
 	libc/machine/spu/$(am__dirstamp) \
 	libc/machine/spu/$(DEPDIR)/$(am__dirstamp)
-libc/machine/spu/libc_a-impure.$(OBJEXT):  \
-	libc/machine/spu/$(am__dirstamp) \
-	libc/machine/spu/$(DEPDIR)/$(am__dirstamp)
 libc/machine/spu/libc_a-iprintf.$(OBJEXT):  \
 	libc/machine/spu/$(am__dirstamp) \
 	libc/machine/spu/$(DEPDIR)/$(am__dirstamp)
@@ -12121,7 +12121,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-getc.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-getchar.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-gets.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-impure.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-iprintf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-iscanf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/spu/$(DEPDIR)/libc_a-malloc_ea.Po@am__quote@
@@ -12309,6 +12308,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-fstatr.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-getreent.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-gettimeofdayr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-impure-compat.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-impure.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-isattyr.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/reent/$(DEPDIR)/libc_a-linkr.Po@am__quote@
@@ -26801,6 +26801,20 @@ libc/reent/libc_a-impure.obj: libc/reent/impure.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/reent/libc_a-impure.obj `if test -f 'libc/reent/impure.c'; then $(CYGPATH_W) 'libc/reent/impure.c'; else $(CYGPATH_W) '$(srcdir)/libc/reent/impure.c'; fi`
 
+libc/reent/libc_a-impure-compat.o: libc/reent/impure-compat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/reent/libc_a-impure-compat.o -MD -MP -MF libc/reent/$(DEPDIR)/libc_a-impure-compat.Tpo -c -o libc/reent/libc_a-impure-compat.o `test -f 'libc/reent/impure-compat.c' || echo '$(srcdir)/'`libc/reent/impure-compat.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/reent/$(DEPDIR)/libc_a-impure-compat.Tpo libc/reent/$(DEPDIR)/libc_a-impure-compat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/reent/impure-compat.c' object='libc/reent/libc_a-impure-compat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/reent/libc_a-impure-compat.o `test -f 'libc/reent/impure-compat.c' || echo '$(srcdir)/'`libc/reent/impure-compat.c
+
+libc/reent/libc_a-impure-compat.obj: libc/reent/impure-compat.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/reent/libc_a-impure-compat.obj -MD -MP -MF libc/reent/$(DEPDIR)/libc_a-impure-compat.Tpo -c -o libc/reent/libc_a-impure-compat.obj `if test -f 'libc/reent/impure-compat.c'; then $(CYGPATH_W) 'libc/reent/impure-compat.c'; else $(CYGPATH_W) '$(srcdir)/libc/reent/impure-compat.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/reent/$(DEPDIR)/libc_a-impure-compat.Tpo libc/reent/$(DEPDIR)/libc_a-impure-compat.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/reent/impure-compat.c' object='libc/reent/libc_a-impure-compat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/reent/libc_a-impure-compat.obj `if test -f 'libc/reent/impure-compat.c'; then $(CYGPATH_W) 'libc/reent/impure-compat.c'; else $(CYGPATH_W) '$(srcdir)/libc/reent/impure-compat.c'; fi`
+
 libc/reent/libc_a-fcntlr.o: libc/reent/fcntlr.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/reent/libc_a-fcntlr.o -MD -MP -MF libc/reent/$(DEPDIR)/libc_a-fcntlr.Tpo -c -o libc/reent/libc_a-fcntlr.o `test -f 'libc/reent/fcntlr.c' || echo '$(srcdir)/'`libc/reent/fcntlr.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/reent/$(DEPDIR)/libc_a-fcntlr.Tpo libc/reent/$(DEPDIR)/libc_a-fcntlr.Po
@@ -33451,20 +33465,6 @@ libc/machine/spu/libc_a-gets.obj: libc/machine/spu/gets.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/machine/spu/libc_a-gets.obj `if test -f 'libc/machine/spu/gets.c'; then $(CYGPATH_W) 'libc/machine/spu/gets.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/spu/gets.c'; fi`
 
-libc/machine/spu/libc_a-impure.o: libc/machine/spu/impure.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/spu/libc_a-impure.o -MD -MP -MF libc/machine/spu/$(DEPDIR)/libc_a-impure.Tpo -c -o libc/machine/spu/libc_a-impure.o `test -f 'libc/machine/spu/impure.c' || echo '$(srcdir)/'`libc/machine/spu/impure.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/spu/$(DEPDIR)/libc_a-impure.Tpo libc/machine/spu/$(DEPDIR)/libc_a-impure.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/spu/impure.c' object='libc/machine/spu/libc_a-impure.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/machine/spu/libc_a-impure.o `test -f 'libc/machine/spu/impure.c' || echo '$(srcdir)/'`libc/machine/spu/impure.c
-
-libc/machine/spu/libc_a-impure.obj: libc/machine/spu/impure.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/spu/libc_a-impure.obj -MD -MP -MF libc/machine/spu/$(DEPDIR)/libc_a-impure.Tpo -c -o libc/machine/spu/libc_a-impure.obj `if test -f 'libc/machine/spu/impure.c'; then $(CYGPATH_W) 'libc/machine/spu/impure.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/spu/impure.c'; fi`
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/spu/$(DEPDIR)/libc_a-impure.Tpo libc/machine/spu/$(DEPDIR)/libc_a-impure.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/spu/impure.c' object='libc/machine/spu/libc_a-impure.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/machine/spu/libc_a-impure.obj `if test -f 'libc/machine/spu/impure.c'; then $(CYGPATH_W) 'libc/machine/spu/impure.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/spu/impure.c'; fi`
-
 libc/machine/spu/libc_a-memcmp.o: libc/machine/spu/memcmp.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/spu/libc_a-memcmp.o -MD -MP -MF libc/machine/spu/$(DEPDIR)/libc_a-memcmp.Tpo -c -o libc/machine/spu/libc_a-memcmp.o `test -f 'libc/machine/spu/memcmp.c' || echo '$(srcdir)/'`libc/machine/spu/memcmp.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/spu/$(DEPDIR)/libc_a-memcmp.Tpo libc/machine/spu/$(DEPDIR)/libc_a-memcmp.Po
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index f8ecf8586..4bc78a447 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -821,7 +821,12 @@ extern __FILE __sf[3];
 #endif
 
 extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
-extern struct _reent *const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
+
+#ifndef __ATTRIBUTE_IMPURE_DATA__
+#define __ATTRIBUTE_IMPURE_DATA__
+#endif
+
+extern struct _reent _impure_data __ATTRIBUTE_IMPURE_DATA__;
 
 void _reclaim_reent (struct _reent *);
 
@@ -836,7 +841,7 @@ void _reclaim_reent (struct _reent *);
 # define _REENT _impure_ptr
 #endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
 
-#define _GLOBAL_REENT _global_impure_ptr
+#define _GLOBAL_REENT (&_impure_data)
 
 #ifdef _REENT_GLOBAL_ATEXIT
 extern struct _atexit *_global_atexit; /* points to head of LIFO stack */
diff --git a/newlib/libc/machine/spu/Makefile.inc b/newlib/libc/machine/spu/Makefile.inc
index bc84e9a23..5384a5f28 100644
--- a/newlib/libc/machine/spu/Makefile.inc
+++ b/newlib/libc/machine/spu/Makefile.inc
@@ -3,7 +3,7 @@ libc_a_SOURCES += \
 	%D%/ferror.c %D%/fflush.c %D%/fgetc.c %D%/fgetpos.c %D%/fgets.c %D%/fileno.c %D%/fiprintf.S \
 	%D%/fiscanf.S %D%/fopen.c %D%/fprintf.S %D%/fputc.c %D%/fputs.c %D%/fread.c %D%/freopen.c \
 	%D%/fscanf.S %D%/fseek.c %D%/fsetpos.c %D%/ftell.c %D%/fwrite.c %D%/getc.c %D%/getchar.c \
-	%D%/gets.c %D%/impure.c %D%/iprintf.S %D%/iscanf.S %D%/memcmp.c %D%/memcpy.c %D%/memmove.c \
+	%D%/gets.c %D%/iprintf.S %D%/iscanf.S %D%/memcmp.c %D%/memcpy.c %D%/memmove.c \
 	%D%/memset.c %D%/perror.c %D%/printf.S %D%/putc.c %D%/putchar.c %D%/puts.c %D%/remove.c \
 	%D%/rename.c %D%/rewind.c %D%/scanf.S %D%/setbuf.c %D%/setvbuf.c %D%/siprintf.S %D%/siscanf.S \
 	%D%/sleep.c %D%/sniprintf.S %D%/snprintf.S %D%/sprintf.S %D%/sscanf.S %D%/stdio.c %D%/strcat.c \
diff --git a/newlib/libc/machine/spu/impure.c b/newlib/libc/machine/spu/impure.c
deleted file mode 100644
index f9c86efdc..000000000
--- a/newlib/libc/machine/spu/impure.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <reent.h>
-
-/* Note that there is a copy of this in sys/reent.h.  */
-#ifndef __ATTRIBUTE_IMPURE_PTR__
-#define __ATTRIBUTE_IMPURE_PTR__
-#endif
-
-#ifndef __ATTRIBUTE_IMPURE_DATA__
-#define __ATTRIBUTE_IMPURE_DATA__
-#endif
-
-struct _reent __ATTRIBUTE_IMPURE_DATA__ _impure_data = _REENT_INIT(_impure_data);
-struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &_impure_data;
-struct _reent *const __ATTRIBUTE_IMPURE_PTR__ _global_impure_ptr = &_impure_data;
diff --git a/newlib/libc/machine/spu/sys/errno.h b/newlib/libc/machine/spu/sys/errno.h
index ef087bd68..b008ff6f4 100644
--- a/newlib/libc/machine/spu/sys/errno.h
+++ b/newlib/libc/machine/spu/sys/errno.h
@@ -27,7 +27,6 @@ extern "C" {
 
 #include <sys/reent.h>
 
-extern struct _reent _impure_data;
 #define errno (_impure_data._errno)
 
 /* Please don't use these variables directly.
diff --git a/newlib/libc/reent/Makefile.inc b/newlib/libc/reent/Makefile.inc
index b4b7f7596..46ab7fe79 100644
--- a/newlib/libc/reent/Makefile.inc
+++ b/newlib/libc/reent/Makefile.inc
@@ -2,6 +2,7 @@ libc_a_SOURCES += \
 	%D%/closer.c \
 	%D%/reent.c \
 	%D%/impure.c \
+	%D%/impure-compat.c \
 	%D%/fcntlr.c \
 	%D%/fstatr.c \
 	%D%/getreent.c \
diff --git a/newlib/libc/reent/impure-compat.c b/newlib/libc/reent/impure-compat.c
new file mode 100644
index 000000000..3f3fa3742
--- /dev/null
+++ b/newlib/libc/reent/impure-compat.c
@@ -0,0 +1,5 @@
+#include <sys/reent.h>
+
+/* Provided for backward binary compatibility */
+struct _reent *const __ATTRIBUTE_IMPURE_PTR__
+_global_impure_ptr = &_impure_data;
diff --git a/newlib/libc/reent/impure.c b/newlib/libc/reent/impure.c
index 76f67459e..f10665fd0 100644
--- a/newlib/libc/reent/impure.c
+++ b/newlib/libc/reent/impure.c
@@ -1,14 +1,5 @@
 #include <reent.h>
 
-/* Note that there is a copy of this in sys/reent.h.  */
-#ifndef __ATTRIBUTE_IMPURE_PTR__
-#define __ATTRIBUTE_IMPURE_PTR__
-#endif
-
-#ifndef __ATTRIBUTE_IMPURE_DATA__
-#define __ATTRIBUTE_IMPURE_DATA__
-#endif
-
 /* Redeclare these symbols locally as weak so that the file containing
    their definitions (along with a lot of other stuff) isn't sucked in
    unless they are actually used by other compilation units.  This is
@@ -20,9 +11,8 @@ extern const struct __sFILE_fake __sf_fake_stdout _ATTRIBUTE ((weak));
 extern const struct __sFILE_fake __sf_fake_stderr _ATTRIBUTE ((weak));
 #endif
 
-static struct _reent __ATTRIBUTE_IMPURE_DATA__ impure_data = _REENT_INIT (impure_data);
+struct _reent __ATTRIBUTE_IMPURE_DATA__ _impure_data = _REENT_INIT (_impure_data);
 #ifdef __CYGWIN__
-extern struct _reent reent_data __attribute__ ((alias("impure_data")));
+extern struct _reent reent_data __attribute__ ((alias("_impure_data")));
 #endif
-struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &impure_data;
-struct _reent *const __ATTRIBUTE_IMPURE_PTR__ _global_impure_ptr = &impure_data;
+struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &_impure_data;
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index e757c47ec..aeb81a5cd 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -816,7 +816,7 @@ static inline void
 main_thread_sinit ()
 {
   __sinit (_impure_ptr);
-  /* At this point, _impure_ptr == _global_impure_ptr == _GLOBAL_REENT is
+  /* At this point, _impure_ptr == _GLOBAL_REENT is
      initialized, but _REENT == _my_tls.local_clib doesn't know about it.
      It has been copied over from _GLOBAL_REENT in _cygtls::init_thread
      *before* the initialization took place.
-- 
2.34.1


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

* Re: [PATCH] Remove use of _global_impure_ptr
  2022-05-03 13:40 [PATCH] Remove use of _global_impure_ptr Sebastian Huber
@ 2022-05-04 13:34 ` Corinna Vinschen
  2022-05-04 13:38   ` Sebastian Huber
  2022-05-04 15:22   ` Dave Nadler
  0 siblings, 2 replies; 5+ messages in thread
From: Corinna Vinschen @ 2022-05-04 13:34 UTC (permalink / raw)
  To: newlib

Hi Sebastian,

On May  3 15:40, Sebastian Huber wrote:
> Remove the pointer indrection through the read-only _global_impure_ptr and
> directly use a globally visible _impure_data object of type struct reent.  This
> enables the static initialization of global data structures in a follow up
> patch.  In addition, we get rid of a machine-specific file.

the patch looks good.  I just wonder if we really need the
impure-compat.c file.  Backward-compat is no problem for embedded stuff,
and Cygwin doesn't expose _global_impure_ptr to user space either.

If there's no other compelling reason, you can just drop it and push
the rest.


Thanks,
Corinna


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

* Re: [PATCH] Remove use of _global_impure_ptr
  2022-05-04 13:34 ` Corinna Vinschen
@ 2022-05-04 13:38   ` Sebastian Huber
  2022-05-04 15:22   ` Dave Nadler
  1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Huber @ 2022-05-04 13:38 UTC (permalink / raw)
  To: newlib

On 04/05/2022 15:34, Corinna Vinschen wrote:
> On May  3 15:40, Sebastian Huber wrote:
>> Remove the pointer indrection through the read-only _global_impure_ptr and
>> directly use a globally visible _impure_data object of type struct reent.  This
>> enables the static initialization of global data structures in a follow up
>> patch.  In addition, we get rid of a machine-specific file.
> the patch looks good.  I just wonder if we really need the
> impure-compat.c file.  Backward-compat is no problem for embedded stuff,
> and Cygwin doesn't expose _global_impure_ptr to user space either.
> 
> If there's no other compelling reason, you can just drop it and push
> the rest.

Yes, _GLOBAL_REENT is only used by Newlib modules and not in public 
macros/inline functions.  If applications don't use this internal item, 
then we don't need the impure-compat.c.

I will check in the patch without the impure-compat.c. If needed we can 
add it later.

-- 
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] 5+ messages in thread

* Re: [PATCH] Remove use of _global_impure_ptr
  2022-05-04 13:34 ` Corinna Vinschen
  2022-05-04 13:38   ` Sebastian Huber
@ 2022-05-04 15:22   ` Dave Nadler
  2022-05-04 15:29     ` Sebastian Huber
  1 sibling, 1 reply; 5+ messages in thread
From: Dave Nadler @ 2022-05-04 15:22 UTC (permalink / raw)
  To: newlib

On 5/4/2022 9:34 AM, Corinna Vinschen wrote:
> Hi Sebastian,
>
> On May  3 15:40, Sebastian Huber wrote:
>> Remove the pointer indrection through the read-only _global_impure_ptr and
>> directly use a globally visible _impure_data object of type struct reent.  This
>> enables the static initialization of global data structures in a follow up
>> patch.  In addition, we get rid of a machine-specific file.
> the patch looks good.  I just wonder if we really need the
> impure-compat.c file.  Backward-compat is no problem for embedded stuff,
> and Cygwin doesn't expose _global_impure_ptr to user space either.
>
> If there's no other compelling reason, you can just drop it and push
> the rest.
>
> Thanks,
> Corinna

Apologies if this is a dumb question, but this patch does not
affect the use of the global _impure_ptr, right? For example
FreeRTOS allocates a reentrancy structure for each task and switches
_impure_ptr on context switches.

Thanks!
Best Regards, Dave

-- 
Dave Nadler, USA East Coast voice (978) 263-0097, drn@nadler.com, Skype
  Dave.Nadler1


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

* Re: [PATCH] Remove use of _global_impure_ptr
  2022-05-04 15:22   ` Dave Nadler
@ 2022-05-04 15:29     ` Sebastian Huber
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Huber @ 2022-05-04 15:29 UTC (permalink / raw)
  To: Dave Nadler, newlib

On 04/05/2022 17:22, Dave Nadler wrote:
> On 5/4/2022 9:34 AM, Corinna Vinschen wrote:
>> Hi Sebastian,
>>
>> On May  3 15:40, Sebastian Huber wrote:
>>> Remove the pointer indrection through the read-only 
>>> _global_impure_ptr and
>>> directly use a globally visible _impure_data object of type struct 
>>> reent.  This
>>> enables the static initialization of global data structures in a 
>>> follow up
>>> patch.  In addition, we get rid of a machine-specific file.
>> the patch looks good.  I just wonder if we really need the
>> impure-compat.c file.  Backward-compat is no problem for embedded stuff,
>> and Cygwin doesn't expose _global_impure_ptr to user space either.
>>
>> If there's no other compelling reason, you can just drop it and push
>> the rest.
>>
>> Thanks,
>> Corinna
> 
> Apologies if this is a dumb question, but this patch does not
> affect the use of the global _impure_ptr, right? For example
> FreeRTOS allocates a reentrancy structure for each task and switches
> _impure_ptr on context switches.

This patch doesn't change the behaviour of _impure_ptr.  The _impure_ptr 
is initialized to point to a global struct _reent object.  Now, this 
object is externally visible.

-- 
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] 5+ messages in thread

end of thread, other threads:[~2022-05-04 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03 13:40 [PATCH] Remove use of _global_impure_ptr Sebastian Huber
2022-05-04 13:34 ` Corinna Vinschen
2022-05-04 13:38   ` Sebastian Huber
2022-05-04 15:22   ` Dave Nadler
2022-05-04 15:29     ` 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).