GCN: Implement '_exit' instead of 'exit' (was: nvptx: Implement '_exit' instead of 'exit')

Thomas Schwinge <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi!

On 2022-12-01T22:13:38+0100, I wrote:
> Subject: [PATCH] nvptx: Implement '_exit' instead of 'exit'
>
> ... so that all of 'exit', '_exit', '_Exit' work.  'exit' thus becomes the
> standard 'newlib/libc/stdlib/exit.c' -- and functions registered via 'atexit'
> are now called at return from 'main' or manual 'exit' invocation.

A year later, the same thing for GCN -- pushed to main branch
commit 1a177610d8e181d09206a5a8ce2d873822751657
"GCN: Implement '_exit' instead of 'exit'", see attached.


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
0001-GCN-Implement-_exit-instead-of-exit.patch (text/x-diff, 12 KB)
From 1a177610d8e181d09206a5a8ce2d873822751657 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <[email protected]>
Date: Mon, 6 Nov 2023 16:48:20 +0100
Subject: [PATCH] GCN: Implement '_exit' instead of 'exit'

... so that all of 'exit', '_exit', '_Exit' work.  'exit' thus becomes the
standard 'newlib/libc/stdlib/exit.c'.  (Getting 'atexit' functional needs
further work elsewhere.)

See also commit 5841b2f6a4208682264d03e3edfa0a09881932a6
"nvptx: Implement '_exit' instead of 'exit'".
---
 newlib/Makefile.in                            | 40 +++++++++----------
 newlib/libc/machine/amdgcn/Makefile.inc       |  2 +-
 .../libc/machine/amdgcn/{exit.c => _exit.c}   |  4 +-
 newlib/libc/machine/amdgcn/atexit.c           |  3 +-
 4 files changed, 24 insertions(+), 25 deletions(-)
 rename newlib/libc/machine/amdgcn/{exit.c => _exit.c} (95%)

diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 99a29465a..9a32646ab 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -630,8 +630,8 @@ check_PROGRAMS =
 @HAVE_LIBC_MACHINE_AARCH64_TRUE@	libc/machine/aarch64/strrchr.S
 
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@am__append_67 = \
+@HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/_exit.c \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/abort.c \
-@HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/exit.c \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/atexit.c \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/mlock.c \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/getreent.c \
@@ -1892,8 +1892,8 @@ am__objects_51 = libc/ssp/libc_a-chk_fail.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AARCH64_TRUE@	libc/machine/aarch64/libc_a-strnlen.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AARCH64_TRUE@	libc/machine/aarch64/libc_a-strrchr-stub.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AARCH64_TRUE@	libc/machine/aarch64/libc_a-strrchr.$(OBJEXT)
-@HAVE_LIBC_MACHINE_AMDGCN_TRUE@am__objects_78 = libc/machine/amdgcn/libc_a-abort.$(OBJEXT) \
-@HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/libc_a-exit.$(OBJEXT) \
+@HAVE_LIBC_MACHINE_AMDGCN_TRUE@am__objects_78 = libc/machine/amdgcn/libc_a-_exit.$(OBJEXT) \
+@HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/libc_a-abort.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/libc_a-atexit.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/libc_a-mlock.$(OBJEXT) \
 @HAVE_LIBC_MACHINE_AMDGCN_TRUE@	libc/machine/amdgcn/libc_a-getreent.$(OBJEXT) \
@@ -8161,10 +8161,10 @@ libc/machine/amdgcn/$(am__dirstamp):
 libc/machine/amdgcn/$(DEPDIR)/$(am__dirstamp):
 	@$(MKDIR_P) libc/machine/amdgcn/$(DEPDIR)
 	@: > libc/machine/amdgcn/$(DEPDIR)/$(am__dirstamp)
-libc/machine/amdgcn/libc_a-abort.$(OBJEXT):  \
+libc/machine/amdgcn/libc_a-_exit.$(OBJEXT):  \
 	libc/machine/amdgcn/$(am__dirstamp) \
 	libc/machine/amdgcn/$(DEPDIR)/$(am__dirstamp)
-libc/machine/amdgcn/libc_a-exit.$(OBJEXT):  \
+libc/machine/amdgcn/libc_a-abort.$(OBJEXT):  \
 	libc/machine/amdgcn/$(am__dirstamp) \
 	libc/machine/amdgcn/$(DEPDIR)/$(am__dirstamp)
 libc/machine/amdgcn/libc_a-atexit.$(OBJEXT):  \
@@ -12816,9 +12816,9 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/aarch64/$(DEPDIR)/libc_a-strnlen.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/aarch64/$(DEPDIR)/libc_a-strrchr-stub.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/aarch64/$(DEPDIR)/libc_a-strrchr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-abort.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-atexit.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-getreent.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-mlock.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@libc/machine/amdgcn/$(DEPDIR)/libc_a-signal.Po@am__quote@
@@ -33347,6 +33347,20 @@ libc/machine/aarch64/libc_a-strrchr-stub.obj: libc/machine/aarch64/strrchr-stub.
 @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/aarch64/libc_a-strrchr-stub.obj `if test -f 'libc/machine/aarch64/strrchr-stub.c'; then $(CYGPATH_W) 'libc/machine/aarch64/strrchr-stub.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/aarch64/strrchr-stub.c'; fi`
 
+libc/machine/amdgcn/libc_a-_exit.o: libc/machine/amdgcn/_exit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-_exit.o -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Tpo -c -o libc/machine/amdgcn/libc_a-_exit.o `test -f 'libc/machine/amdgcn/_exit.c' || echo '$(srcdir)/'`libc/machine/amdgcn/_exit.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/amdgcn/_exit.c' object='libc/machine/amdgcn/libc_a-_exit.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/amdgcn/libc_a-_exit.o `test -f 'libc/machine/amdgcn/_exit.c' || echo '$(srcdir)/'`libc/machine/amdgcn/_exit.c
+
+libc/machine/amdgcn/libc_a-_exit.obj: libc/machine/amdgcn/_exit.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-_exit.obj -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Tpo -c -o libc/machine/amdgcn/libc_a-_exit.obj `if test -f 'libc/machine/amdgcn/_exit.c'; then $(CYGPATH_W) 'libc/machine/amdgcn/_exit.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/amdgcn/_exit.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-_exit.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/amdgcn/_exit.c' object='libc/machine/amdgcn/libc_a-_exit.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/amdgcn/libc_a-_exit.obj `if test -f 'libc/machine/amdgcn/_exit.c'; then $(CYGPATH_W) 'libc/machine/amdgcn/_exit.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/amdgcn/_exit.c'; fi`
+
 libc/machine/amdgcn/libc_a-abort.o: libc/machine/amdgcn/abort.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-abort.o -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-abort.Tpo -c -o libc/machine/amdgcn/libc_a-abort.o `test -f 'libc/machine/amdgcn/abort.c' || echo '$(srcdir)/'`libc/machine/amdgcn/abort.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-abort.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-abort.Po
@@ -33361,20 +33375,6 @@ libc/machine/amdgcn/libc_a-abort.obj: libc/machine/amdgcn/abort.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/amdgcn/libc_a-abort.obj `if test -f 'libc/machine/amdgcn/abort.c'; then $(CYGPATH_W) 'libc/machine/amdgcn/abort.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/amdgcn/abort.c'; fi`
 
-libc/machine/amdgcn/libc_a-exit.o: libc/machine/amdgcn/exit.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-exit.o -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Tpo -c -o libc/machine/amdgcn/libc_a-exit.o `test -f 'libc/machine/amdgcn/exit.c' || echo '$(srcdir)/'`libc/machine/amdgcn/exit.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/amdgcn/exit.c' object='libc/machine/amdgcn/libc_a-exit.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/amdgcn/libc_a-exit.o `test -f 'libc/machine/amdgcn/exit.c' || echo '$(srcdir)/'`libc/machine/amdgcn/exit.c
-
-libc/machine/amdgcn/libc_a-exit.obj: libc/machine/amdgcn/exit.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-exit.obj -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Tpo -c -o libc/machine/amdgcn/libc_a-exit.obj `if test -f 'libc/machine/amdgcn/exit.c'; then $(CYGPATH_W) 'libc/machine/amdgcn/exit.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/amdgcn/exit.c'; fi`
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-exit.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/machine/amdgcn/exit.c' object='libc/machine/amdgcn/libc_a-exit.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/amdgcn/libc_a-exit.obj `if test -f 'libc/machine/amdgcn/exit.c'; then $(CYGPATH_W) 'libc/machine/amdgcn/exit.c'; else $(CYGPATH_W) '$(srcdir)/libc/machine/amdgcn/exit.c'; fi`
-
 libc/machine/amdgcn/libc_a-atexit.o: libc/machine/amdgcn/atexit.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/machine/amdgcn/libc_a-atexit.o -MD -MP -MF libc/machine/amdgcn/$(DEPDIR)/libc_a-atexit.Tpo -c -o libc/machine/amdgcn/libc_a-atexit.o `test -f 'libc/machine/amdgcn/atexit.c' || echo '$(srcdir)/'`libc/machine/amdgcn/atexit.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/machine/amdgcn/$(DEPDIR)/libc_a-atexit.Tpo libc/machine/amdgcn/$(DEPDIR)/libc_a-atexit.Po
diff --git a/newlib/libc/machine/amdgcn/Makefile.inc b/newlib/libc/machine/amdgcn/Makefile.inc
index d26603aa8..e1fc5ae4d 100644
--- a/newlib/libc/machine/amdgcn/Makefile.inc
+++ b/newlib/libc/machine/amdgcn/Makefile.inc
@@ -1,6 +1,6 @@
 libc_a_SOURCES += \
+	%D%/_exit.c \
 	%D%/abort.c \
-	%D%/exit.c \
 	%D%/atexit.c \
 	%D%/mlock.c \
 	%D%/getreent.c \
diff --git a/newlib/libc/machine/amdgcn/exit.c b/newlib/libc/machine/amdgcn/_exit.c
similarity index 95%
rename from newlib/libc/machine/amdgcn/exit.c
rename to newlib/libc/machine/amdgcn/_exit.c
index bdd532edd..82171aff9 100644
--- a/newlib/libc/machine/amdgcn/exit.c
+++ b/newlib/libc/machine/amdgcn/_exit.c
@@ -13,11 +13,11 @@
  * they apply.
  */
 
-#include <stdlib.h>
+#include <unistd.h>
 #include "exit-value.h"
 
 void __attribute__((noreturn))
-exit (int val)
+_exit (int val)
 {
   exit_with_status_and_signal (val, 0);
 }
diff --git a/newlib/libc/machine/amdgcn/atexit.c b/newlib/libc/machine/amdgcn/atexit.c
index 674571435..8ddd92cfa 100644
--- a/newlib/libc/machine/amdgcn/atexit.c
+++ b/newlib/libc/machine/amdgcn/atexit.c
@@ -18,8 +18,7 @@
 int
 atexit (void (*function)(void))
 {
-  /* Our current implementation of exit does not run functions registered with
-     atexit, so fail here.  */
+  /* Fail here.  */
   abort ();
   return 1;
 }
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.