From patchwork Thu Jul 18 16:40:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 1133776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505291-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qKd845FGz9s3l for ; Fri, 19 Jul 2019 02:40:39 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=B75eD393W1Jg+WrIomYTzGHLtIvOoAznOsTBC84oTQalIvPrcN Rql6FTqCNHHQcWJliPB3YBrKfCrmw1KlOH4u5BqmI2wHDnvBtrxWqcjvGN9PhKQn kRXP3LmkaZ8/r5ZXNiUJAjfTCfurbOz9eHV/Y1Vq3TnruBoWDrfCRCiko= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=zWaauKi9++tJtmwdMEYRQamioIs=; b=eMxWy5uWxB8NAjPY46e5 vmwtEm+OsuAZ/qHku9uNjndzY+30ypgtr88LaDAC62egH6zYtKpDWBv3I+j691sb jRJo8zU3rZb3IEskKAajBNc988h7NunUBLxtVrImp15p2BOTSn2tF9+Z6PkkhOHL Xm7gXq9eqd5bZWTSKGc45og= Received: (qmail 2642 invoked by alias); 18 Jul 2019 16:40:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2460 invoked by uid 89); 18 Jul 2019 16:40:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=c, offers, vs, VS X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Jul 2019 16:40:28 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7BF7C56230; Thu, 18 Jul 2019 12:40:26 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Ty4hqW8FjB6m; Thu, 18 Jul 2019 12:40:26 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 43812560B8; Thu, 18 Jul 2019 12:40:26 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 3D8366A9; Thu, 18 Jul 2019 12:40:26 -0400 (EDT) Date: Thu, 18 Jul 2019 12:40:26 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Pierre-Marie de Rodat Subject: [Ada] clean ups in C runtime files Message-ID: <20190718164026.GA112453@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This change introduces a "STANDALONE" mode where the C files of the Ada runtime do not have any dependency on GCC include files. This is useful for rebuilding the Ada runtime in a sandbox where GCC include files are not available. Also a few clean ups along the way. Tested on x86_64-pc-linux-gnu, committed on trunk. 2019-07-18 Arnaud Charlet * Makefile.rtl, expect.c, env.c, aux-io.c, mkdir.c, initialize.c, cstreams.c, raise.c, tracebak.c, adadecode.c, init.c, raise-gcc.c, argv.c, adaint.c, adaint.h, ctrl_c.c, sysdep.c, rtinit.c, cio.c, seh_init.c, exit.c, targext.c: Introduce a "STANDALONE" mode where C runtime files do not have any dependency on GCC include files. Remove unnecessary includes. Remove remaining references to VMS in runtime C file. * runtime.h: new File. Index: expect.c =================================================================== --- expect.c (revision 273575) +++ expect.c (working copy) @@ -29,14 +29,11 @@ * * ****************************************************************************/ -#ifdef __alpha_vxworks -#include "vxWorks.h" -#endif - #ifdef IN_RTS #define POSIX -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" +#include + #else #include "config.h" #include "system.h" Index: env.c =================================================================== --- env.c (revision 273575) +++ env.c (working copy) @@ -30,15 +30,11 @@ ****************************************************************************/ #ifdef IN_RTS -# include "tconfig.h" -# include "tsystem.h" +# include "runtime.h" +# include +# include +# include -# include -# include -# include -# ifdef VMS -# include -# endif /* We don't have libiberty, so use malloc. */ # define xmalloc(S) malloc (S) #else /* IN_RTS */ @@ -109,89 +105,10 @@ return; } -/* VMS specific declarations for set_env_value. */ - -#ifdef VMS - -typedef struct _ile3 -{ - unsigned short len, code; - __char_ptr32 adr; - __char_ptr32 retlen_adr; -} ile_s; - -#endif - void __gnat_setenv (char *name, char *value) { -#if defined (VMS) - struct dsc$descriptor_s name_desc; - $DESCRIPTOR (table_desc, "LNM$PROCESS"); - char *host_pathspec = value; - char *copy_pathspec; - int num_dirs_in_pathspec = 1; - char *ptr; - long status; - - name_desc.dsc$w_length = strlen (name); - name_desc.dsc$b_dtype = DSC$K_DTYPE_T; - name_desc.dsc$b_class = DSC$K_CLASS_S; - name_desc.dsc$a_pointer = name; /* ??? Danger, not 64bit safe. */ - - if (*host_pathspec == 0) - /* deassign */ - { - status = LIB$DELETE_LOGICAL (&name_desc, &table_desc); - /* no need to check status; if the logical name is not - defined, that's fine. */ - return; - } - - ptr = host_pathspec; - while (*ptr++) - if (*ptr == ',') - num_dirs_in_pathspec++; - - { - int i, status; - /* Alloca is guaranteed to be 32bit. */ - ile_s *ile_array = alloca (sizeof (ile_s) * (num_dirs_in_pathspec + 1)); - char *copy_pathspec = alloca (strlen (host_pathspec) + 1); - char *curr, *next; - - strcpy (copy_pathspec, host_pathspec); - curr = copy_pathspec; - for (i = 0; i < num_dirs_in_pathspec; i++) - { - next = strchr (curr, ','); - if (next == 0) - next = strchr (curr, 0); - - *next = 0; - ile_array[i].len = strlen (curr); - - /* Code 2 from lnmdef.h means it's a string. */ - ile_array[i].code = 2; - ile_array[i].adr = curr; - - /* retlen_adr is ignored. */ - ile_array[i].retlen_adr = 0; - curr = next + 1; - } - - /* Terminating item must be zero. */ - ile_array[i].len = 0; - ile_array[i].code = 0; - ile_array[i].adr = 0; - ile_array[i].retlen_adr = 0; - - status = LIB$SET_LOGICAL (&name_desc, 0, &table_desc, 0, ile_array); - if ((status & 1) != 1) - LIB$SIGNAL (status); - } - -#elif (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__) +#if (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__) setenv (name, value, 1); #else @@ -213,10 +130,7 @@ char ** __gnat_environ (void) { -#if defined (VMS) || defined (RTX) - /* Not implemented */ - return NULL; -#elif defined (__MINGW32__) +#if defined (__MINGW32__) return _environ; #elif defined (__sun__) extern char **_environ; @@ -247,10 +161,7 @@ void __gnat_unsetenv (char *name) { -#if defined (VMS) - /* Not implemented */ - return; -#elif defined (__hpux__) || defined (__sun__) \ +#if defined (__hpux__) || defined (__sun__) \ || (defined (__vxworks) && ! defined (__RTP__)) \ || defined (_AIX) || defined (__Lynx__) @@ -306,10 +217,7 @@ void __gnat_clearenv (void) { -#if defined (VMS) - /* not implemented */ - return; -#elif defined (__sun__) \ +#if defined (__sun__) \ || (defined (__vxworks) && ! defined (__RTP__)) || defined (__Lynx__) \ || defined (__PikeOS__) /* On Solaris, VxWorks (not RTPs), and Lynx there is no system Index: aux-io.c =================================================================== --- aux-io.c (revision 273575) +++ aux-io.c (working copy) @@ -31,10 +31,7 @@ #include -#ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#else +#ifndef IN_RTS #include "config.h" #include "system.h" #endif Index: mkdir.c =================================================================== --- mkdir.c (revision 273575) +++ mkdir.c (working copy) @@ -35,8 +35,7 @@ #endif /* __vxworks */ #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" #include #else #include "config.h" Index: initialize.c =================================================================== --- initialize.c (revision 273575) +++ initialize.c (working copy) @@ -41,8 +41,7 @@ #endif #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" /* We don't have libiberty, so use malloc. */ #define xmalloc(S) malloc (S) #define xrealloc(V,S) realloc (V,S) Index: cstreams.c =================================================================== --- cstreams.c (revision 273575) +++ cstreams.c (working copy) @@ -53,9 +53,7 @@ #endif #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#include +#include #else #include "config.h" #include "system.h" Index: raise.c =================================================================== --- raise.c (revision 273575) +++ raise.c (working copy) @@ -33,8 +33,7 @@ is shared between all exception handling mechanisms. */ #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" #else #include "config.h" #include "system.h" @@ -56,16 +55,6 @@ void __gnat_unhandled_terminate (void) { -#ifdef VMS - /* Special termination handling for VMS */ - long prvhnd; - - /* Remove the exception vector so it won't intercept any errors - in the call to exit, and go into and endless loop */ - - SYS$SETEXV (1, 0, 3, &prvhnd); -#endif - /* Default termination handling */ __gnat_os_exit (1); } Index: tracebak.c =================================================================== --- tracebak.c (revision 273575) +++ tracebak.c (working copy) @@ -50,14 +50,10 @@ extern "C" { #endif -#ifdef __alpha_vxworks -#include "vxWorks.h" -#endif - #ifdef IN_RTS #define POSIX -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" +#include #else #include "config.h" #include "system.h" Index: adadecode.c =================================================================== --- adadecode.c (revision 273575) +++ adadecode.c (working copy) @@ -29,15 +29,7 @@ * * ****************************************************************************/ - -#if defined(IN_RTS) -#include "tconfig.h" -#include "tsystem.h" -#elif defined(IN_GCC) -#include "config.h" -#include "system.h" -#endif - +#include "runtime.h" #include #include #include Index: init.c =================================================================== --- init.c (revision 273575) +++ init.c (working copy) @@ -54,8 +54,14 @@ #endif #ifdef IN_RTS + +#ifdef STANDALONE +#include "runtime.h" +#else #include "tconfig.h" #include "tsystem.h" +#endif + #include /* We don't have libiberty, so use malloc. */ @@ -463,6 +469,7 @@ void __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED, void *ucontext) { +#ifndef STANDALONE mcontext_t *mcontext = &((ucontext_t *) ucontext)->uc_mcontext; /* On the i386 and x86-64 architectures, stack checking is performed by @@ -513,6 +520,7 @@ mcontext->arm_pc+=1; #endif #endif +#endif } #endif Index: raise-gcc.c =================================================================== --- raise-gcc.c (revision 273575) +++ raise-gcc.c (working copy) @@ -39,11 +39,11 @@ /* Don't use fancy_abort. */ # undef abort #else -# ifndef CERT +# if !defined(CERT) && !defined(STANDALONE) # include "tconfig.h" # include "tsystem.h" # else -# define ATTRIBUTE_UNUSED __attribute__((unused)) +# include "runtime.h" # define HAVE_GETIPINFO 1 # endif #endif @@ -115,6 +115,10 @@ /* Called in case of error during propagation. */ extern void __gnat_raise_abort (void) __attribute__ ((noreturn)); #define abort() __gnat_raise_abort() + +#elif defined(STANDALONE) +#include +#define inhibit_libc #endif #include "unwind-pe.h" Index: Makefile.rtl =================================================================== --- Makefile.rtl (revision 273575) +++ Makefile.rtl (working copy) @@ -2610,7 +2610,7 @@ LIBGNAT_SRCS = $(patsubst %.o,%.c,$(LIBGNAT_OBJS)) \ adadecode.h adaint.h env.h gsocket.h raise.h standard.ads.h \ - tb-gcc.c libgnarl/thread.c $(EXTRA_LIBGNAT_SRCS) + tb-gcc.c runtime.h libgnarl/thread.c $(EXTRA_LIBGNAT_SRCS) # memtrack.o is special as not put into libgnat. GNATRTL_OBJS = $(GNATRTL_NONTASKING_OBJS) $(GNATRTL_TASKING_OBJS) \ Index: argv.c =================================================================== --- argv.c (revision 273575) +++ argv.c (working copy) @@ -43,9 +43,8 @@ Ada.Command_Line.Environment package. */ #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#include +#include "runtime.h" +#include #else #include "config.h" #include "system.h" Index: adaint.c =================================================================== --- adaint.c (revision 273575) +++ adaint.c (working copy) @@ -88,8 +88,26 @@ #endif #ifdef IN_RTS + +#ifdef STANDALONE +#include +#include +#include +#include +#include +#include + +/* for CPU_SET/CPU_ZERO */ +#define _GNU_SOURCE +#define __USE_GNU + +#include "runtime.h" + +#else #include "tconfig.h" #include "tsystem.h" +#endif + #include #include #include Index: adaint.h =================================================================== --- adaint.h (revision 273575) +++ adaint.h (working copy) @@ -51,7 +51,7 @@ determine at compile time what support the system offers for large files. For now we just list the platforms we have manually tested. */ -#if defined (__GLIBC__) || defined (__sun__) || defined (__QNX__) +#if (defined (__GLIBC__) && !defined(STANDALONE)) || defined (__sun__) || defined (__QNX__) #define GNAT_FOPEN fopen64 #define GNAT_OPEN open64 #define GNAT_STAT stat64 Index: ctrl_c.c =================================================================== --- ctrl_c.c (revision 273575) +++ ctrl_c.c (working copy) @@ -29,11 +29,7 @@ * * ****************************************************************************/ -#ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#include -#else +#ifndef IN_RTS #include "config.h" #include "system.h" #endif Index: sysdep.c =================================================================== --- sysdep.c (revision 273575) +++ sysdep.c (working copy) @@ -54,8 +54,10 @@ #ifdef IN_RTS #define POSIX -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" +#include +#include + #include #include #else Index: runtime.h =================================================================== --- runtime.h (revision 0) +++ runtime.h (revision 0) @@ -0,0 +1,44 @@ +/**************************************************************************** + * * + * GNAT COMPILER COMPONENTS * + * * + * RUNTIME * + * * + * C Header File * + * * + * Copyright (C) 2019, Free Software Foundation, Inc. * + * * + * GNAT is free software; you can redistribute it and/or modify it under * + * terms of the GNU General Public License as published by the Free Soft- * + * ware Foundation; either version 3, or (at your option) any later ver- * + * sion. GNAT is distributed in the hope that it will be useful, but WITH- * + * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * + * or FITNESS FOR A PARTICULAR PURPOSE. * + * * + * As a special exception under Section 7 of GPL version 3, you are granted * + * additional permissions described in the GCC Runtime Library Exception, * + * version 3.1, as published by the Free Software Foundation. * + * * + * You should have received a copy of the GNU General Public License and * + * a copy of the GCC Runtime Library Exception along with this program; * + * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see * + * . * + * * + * GNAT was originally developed by the GNAT team at New York University. * + * Extensive contributions were provided by Ada Core Technologies Inc. * + * * + ****************************************************************************/ + +/* This file provides common definitions used by GNAT C runtime files. */ + +#ifdef __vxworks +#include "vxWorks.h" +#endif /* __vxworks */ + +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED __attribute__((unused)) +#endif + +#ifndef ATTRIBUTE_NORETURN +#define ATTRIBUTE_NORETURN __attribute__((noreturn)) +#endif Index: rtinit.c =================================================================== --- rtinit.c (revision 273575) +++ rtinit.c (working copy) @@ -41,8 +41,6 @@ #endif #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" /* We don't have libiberty, so use malloc. */ #define xmalloc(S) malloc (S) #define xrealloc(V,S) realloc (V,S) Index: cio.c =================================================================== --- cio.c (revision 273575) +++ cio.c (working copy) @@ -30,8 +30,7 @@ ****************************************************************************/ #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" #include #else #include "config.h" Index: seh_init.c =================================================================== --- seh_init.c (revision 273575) +++ seh_init.c (working copy) @@ -39,9 +39,9 @@ #endif #ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" +#include "runtime.h" + /* We don't have libiberty, so use malloc. */ #define xmalloc(S) malloc (S) Index: exit.c =================================================================== --- exit.c (revision 273575) +++ exit.c (working copy) @@ -29,21 +29,6 @@ * * ****************************************************************************/ -#ifdef __alpha_vxworks -#include "vxWorks.h" -#endif - -#ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#include -#else -#include "config.h" -#include "system.h" -#endif - -#include "adaint.h" - #ifdef __cplusplus extern "C" { #endif Index: targext.c =================================================================== --- targext.c (revision 273575) +++ targext.c (working copy) @@ -36,14 +36,21 @@ the file must be compiled with IN_GCC defined, even for the library. */ #ifdef IN_RTS + +#ifndef STANDALONE #include "tconfig.h" #include "tsystem.h" +#endif + #else #include "config.h" #include "system.h" #endif + +#ifndef STANDALONE #include "coretypes.h" #include "tm.h" +#endif #ifndef TARGET_OBJECT_SUFFIX #define TARGET_OBJECT_SUFFIX ".o"