public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Tom de Vries <tdevries@suse.de>
Subject: Make 'libgcc/config/nvptx/crt0.c' build '--without-headers' (was: [PING] nvptx: Support global constructors/destructors via 'collect2')
Date: Tue, 24 Jan 2023 10:01:16 +0100	[thread overview]
Message-ID: <87edrk1f37.fsf@dem-tschwing-1.ger.mentorg.com> (raw)
In-Reply-To: <87fsdacxi0.fsf@euler.schwinge.homeip.net>

[-- Attachment #1: Type: text/plain, Size: 1408 bytes --]

Hi!

On 2022-12-20T09:03:51+0100, I wrote:
> Minor change in the attached
> "nvptx: Support global constructors/destructors via 'collect2'": for
> 'atexit', add '#include <stdlib.h>' to 'libgcc/config/nvptx/crt0.c'.

Turns out, it's not that easy.  ;-) Pushed to devel/omp/gcc-12 branch
commit d90a8a5685c8bd3657892feac01739fe87a457a5
"Make 'libgcc/config/nvptx/crt0.c' build '--without-headers'", see
attached.  Please consider that one 'fixup'ed into the GCC master branch
submission.


Grüße
 Thomas


> --- a/libgcc/config/nvptx/crt0.c
> +++ b/libgcc/config/nvptx/crt0.c
> @@ -19,6 +19,9 @@
>     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>     <http://www.gnu.org/licenses/>.  */
>
> +#include <stdlib.h>
> +#include "gbl-ctors.h"
> +
>  int *__exitval_ptr;
>
>  extern void __attribute__((noreturn)) exit (int status);
> @@ -47,5 +50,8 @@ __main (int *rval_ptr, int argc, void **argv)
>    __nvptx_stacks[0] = stack + sizeof stack;
>    __nvptx_uni[0] = 0;
>
> +  __do_global_ctors ();
> +  atexit (__do_global_dtors);
> +
>    exit (main (argc, argv));
>  }


-----------------
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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-libgcc-config-nvptx-crt0.c-build-without-header.patch --]
[-- Type: text/x-diff, Size: 1767 bytes --]

From d90a8a5685c8bd3657892feac01739fe87a457a5 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Tue, 24 Jan 2023 09:49:34 +0100
Subject: [PATCH] Make 'libgcc/config/nvptx/crt0.c' build '--without-headers'

..., where it currently fails:

    [...]/libgcc/config/nvptx/crt0.c:22:10: fatal error: stdlib.h: No such file or directory
       22 | #include <stdlib.h>
          |          ^~~~~~~~~~

Fix-up for "nvptx: Support global constructors/destructors via 'collect2'".

	libgcc/
	* config/nvptx/crt0.c [!HAVE_STDLIB_H]: Don't '#include <stdlib.h>'.
	(atexit): Prototype.
---
 libgcc/ChangeLog.omp       | 5 +++++
 libgcc/config/nvptx/crt0.c | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libgcc/ChangeLog.omp b/libgcc/ChangeLog.omp
index c46f49bf5b7..cf509a70d61 100644
--- a/libgcc/ChangeLog.omp
+++ b/libgcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-01-24  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* config/nvptx/crt0.c [!HAVE_STDLIB_H]: Don't '#include <stdlib.h>'.
+	(atexit): Prototype.
+
 2023-01-20  Thomas Schwinge  <thomas@codesourcery.com>
 	    Andrew Stubbs  <ams@codesourcery.com>
 
diff --git a/libgcc/config/nvptx/crt0.c b/libgcc/config/nvptx/crt0.c
index 860e2bfacad..02648bef84b 100644
--- a/libgcc/config/nvptx/crt0.c
+++ b/libgcc/config/nvptx/crt0.c
@@ -19,11 +19,16 @@
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <stdlib.h>
+#include "auto-target.h"
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
 #include "gbl-ctors.h"
 
 int *__exitval_ptr;
 
+extern int atexit (void (*function) (void));
 extern void __attribute__((noreturn)) exit (int status);
 extern int main (int, void **);
 
-- 
2.25.1


  parent reply	other threads:[~2023-01-24  9:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <878rjqaku5.fsf@dem-tschwing-1.ger.mentorg.com>
2022-12-02 13:35 ` nvptx: Support global constructors/destructors via 'collect2' Thomas Schwinge
2022-12-20  8:03   ` [PING] " Thomas Schwinge
2023-01-11 11:48     ` [PING^2] " Thomas Schwinge
2023-01-24  9:01     ` Thomas Schwinge [this message]
2022-12-23 13:35   ` nvptx: Support global constructors/destructors via 'collect2' for offloading (was: nvptx: Support global constructors/destructors via 'collect2') Thomas Schwinge
2022-12-23 13:37     ` Thomas Schwinge
2023-01-11 11:49       ` [PING] " Thomas Schwinge
2023-01-20 20:46     ` [og12] " Thomas Schwinge
2023-01-20 20:41   ` [og12] nvptx: Support global constructors/destructors via 'collect2' Thomas Schwinge
2023-01-20 20:45     ` Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edrk1f37.fsf@dem-tschwing-1.ger.mentorg.com \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).