comp.lang.ada
 help / color / mirror / Atom feed
From: Fernando Oleo Blanco <irvise_ml@irvise.xyz>
Subject: Help: Ada in NetBSD
Date: Sun, 29 Aug 2021 13:06:53 +0200	[thread overview]
Message-ID: <sgfpod$19sl$1@gioia.aioe.org> (raw)

Dear All,

I have been trying for the past few months to make GCC/Ada work in 
NetBSD. I am writing this message to you since I have been stuck in a 
roadblock for far too long and without concrete answers.

Long story short: JMarino, within the Aurora project, already ported 
GCC/Ada to a lot of systems, namely FreeBSD, DragonflyBSD, NetBSD and 
Solaris. The last version that works without friction in NetBSD/pkgsrc 
is GCC v6. I wanted to update GCC to v10 (10.3.0).

So, one can compile GCC v10 with C, C++ and Ada support with v6 without 
any issues. The biggest problem is that the RT (RunTime Files) had no 
configuration for NetBSD (see the original Makefile.rtl in the gcc/ada 
directory). I fixed it by copying the FreeBSD support files and 
modifying a imported C function to be POSIX compilant, since NetBSD did 
not had the function that FreeBSD used (related to pthreads).

The results of compiling GCC v10 with this "small" change are documented 
in a blog entry I did: 
https://www.irvise.xyz/Projects%20&%20Engineering/updating-gcc-ada-pkgsrc.html

TL;DR: GCC v10 compiles and can generate binaries!!! :D But...

The tasking system is not working correctly (I have been testing the 
compiler with the ACATS test suite provided by Simon). The linker 
complains about some C functions not being correctly imported within Ada 
files. And the programs where the linker complains, once compiled, tend 
to get blocked or die. Here is one such example:

/usr/bin/ld: 
/home/fernando/mysandboxfolder/usr/pkg/gcc10/lib/gcc/x86_64--netbsd/10.3.0/adalib/libgnat.a(s-osprim.o): 
in function `system__os_primitives__clock':
/usr/pkgsrc/wip/gcc10-aux/work/build/gcc/ada/rts/s-osprim.adb:91: 
warning: warning: reference to compatibility gettimeofday(); include 
<sys/time.h> to generate correct reference

As you can see, the linker says that, in this case, gettimeofday() is 
not correctly referenced and that I should include <sys/time.h>. Notice, 
it is complaining that the file s-osprim.adb, and Ada file, is at fault 
here. This happens to all files that use the tasking system in one way 
or another, so, in summary, all large projects, such as GPRBuild.

I thought that an #include <sys/time.h> may have been missing from a C 
source file that is required to build the Ada compiler. After all, there 
were some defined (__NetBSD__) missing from the Ada sources.

I added those. Nothing. I took a really good look at JMarino's patches: 
http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/lang/gcc6-aux/files/diff-ada?rev=1.1&content-type=text/x-cvsweb-markup 
I applied some extra changes (the configure/configure.ac patches are 
failing to apply). Still nothing, it keeps failing.

I have been looking for the "missing" #include files, they are <time.h>, 
<sys/time.h> and <signal.h>. I searched through the code, there are few 
occurrences of them and, for example, <sys/time.h> only appears in a 
legacy system.

I checked the C signature files to make sure that they were also correct 
in the Ada sources, and they seem to match.

I am out of ideas.

How come the linker complains about those functions and not the other 
imported C ones? These files are automatically included with -lc.
How could I go about fixing this issue? Any ideas, pointers?

Below are the patches that I have created.

If you are wondering why am I doing this: I like alternative systems, 
Ada is portable on paper, but what about in reality? And my end goal 
would be to see Ada everywhere and upstream these fixes to GCC.

Thank you for your time,

-------

--- gcc/ada/adaint.c.orig	2021-08-28 18:39:27.509714592 +0000
+++ gcc/ada/adaint.c	2021-08-28 18:40:44.190149364 +0000
@@ -817,7 +817,8 @@
  }

  #if defined (_WIN32) || defined (__linux__) || defined (__sun__) \
-  || defined (__FreeBSD__) || defined(__DragonFly__) || defined (__QNX__)
+  || defined (__FreeBSD__) || defined(__DragonFly__) || defined (__QNX__) \
+  || defined (__NetBSD__)
  #define HAS_TARGET_WCHAR_T
  #endif

--- gcc/ada/cstreams.c.orig	2021-08-28 18:42:21.323680378 +0000
+++ gcc/ada/cstreams.c	2021-08-28 18:43:48.045445919 +0000
@@ -188,7 +188,8 @@
  	  *p = '\\';
      }

-#elif defined (__FreeBSD__) || defined (__DragonFly__) || defined 
(__OpenBSD__)
+#elif defined (__FreeBSD__) || defined (__DragonFly__) \
+  || defined (__OpenBSD__) || defined (__NetBSD__)

    /* Use realpath function which resolves links and references to . and ..
       on those Unix systems that support it. Note that GNU/Linux 
provides it but
@@ -270,7 +271,7 @@
  }

  #elif defined (__linux__) || defined (__sun__) || defined (__FreeBSD__) \
-  || defined (__APPLE__)
+  || defined (__APPLE__) || defined (__NetBSD__)
  /* section for platforms having ftello/fseeko */

  __int64

--- gcc/ada/init.c.orig	2021-08-28 20:28:13.261558335 +0000
+++ gcc/ada/init.c	2021-08-28 20:29:48.573288829 +0000
@@ -2183,6 +2183,8 @@

  #include <signal.h>
  #include <unistd.h>
+#include <time.h>
+#include <sys/time.h>

  static void
  __gnat_error_handler (int sig)

--- gcc/ada/s-oscons-tmplt.c.orig	2021-08-28 18:50:50.086632028 +0000
+++ gcc/ada/s-oscons-tmplt.c	2021-08-28 18:53:35.037358487 +0000
@@ -406,9 +406,11 @@

  */

-/* ioctl(2) requests are "int" in UNIX, but "unsigned long" on FreeBSD */
+/* ioctl(2) requests are "int" in UNIX, but "unsigned long" on FreeBSD
+   and NetBSD
+*/

-#if defined (__FreeBSD__) || defined (__DragonFly__)
+#if defined (__FreeBSD__) || defined (__DragonFly__) || defined 
(__NetBSD__)
  # define CNI CNU
  # define IOCTL_Req_T "Interfaces.C.unsigned"
  #else
@@ -1020,7 +1022,8 @@

  */

-#if defined (__FreeBSD__) || defined (__linux__) || defined (__DragonFly__)
+#if defined (__FreeBSD__) || defined (__linux__) || defined 
(__DragonFly__) \
+  || defined (__NetBSD__)
  # define PTY_Library "-lutil"
  #else
  # define PTY_Library ""
@@ -1833,7 +1836,8 @@

  #if defined(__linux__) || defined(__FreeBSD__) \
   || (defined(_AIX) && defined(_AIXVERSION_530)) \
- || defined(__DragonFly__) || defined(__QNX__)
+ || defined(__DragonFly__) || defined(__QNX__) \
+ || defined (__NetBSD__)
  /** On these platforms use system provided monotonic clock instead of
   ** the default CLOCK_REALTIME. We then need to set up cond var attributes
   ** appropriately (see thread.c).

--- gcc/ada/sysdep.c.orig	2021-08-28 13:11:25.681014624 +0000
+++ gcc/ada/sysdep.c	2021-08-28 13:21:14.748176113 +0000
@@ -320,7 +320,7 @@
    || (defined (__svr4__) && defined (__i386__)) || defined (__Lynx__) \
    || defined (__CYGWIN__) || defined (__FreeBSD__) || defined 
(__OpenBSD__) \
    || defined (__GLIBC__) || defined (__APPLE__) || defined 
(__DragonFly__) \
-  || defined (__QNX__)
+  || defined (__QNX__) || defined (__NetBSD__)

  # ifdef __MINGW32__
  #  if OLD_MINGW
@@ -373,7 +373,7 @@
      || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
      || defined (__Lynx__) || defined (__FreeBSD__) || defined 
(__OpenBSD__) \
      || defined (__GLIBC__) || defined (__APPLE__) || defined 
(__DragonFly__) \
-    || defined (__QNX__)
+    || defined (__QNX__) || defined (__NetBSD__)
    char c;
    int nread;
    int good_one = 0;
@@ -394,7 +394,7 @@
      || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
      || defined (__Lynx__) || defined (__FreeBSD__) || defined 
(__OpenBSD__) \
      || defined (__GLIBC__) || defined (__APPLE__) || defined 
(__DragonFly__) \
-    || defined (__QNX__)
+    || defined (__QNX__) || defined (__NetBSD__)
        eof_ch = termios_rec.c_cc[VEOF];

        /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
@@ -831,7 +831,7 @@

  #elif defined (__APPLE__) || defined (__FreeBSD__) || defined 
(__linux__) \
    || defined (__GLIBC__) || defined (__DragonFly__) || defined 
(__OpenBSD__) \
-  || defined (__DJGPP__) || defined (__QNX__)
+  || defined (__DJGPP__) || defined (__QNX__) || defined (__NetBSD__)
  {
    localtime_r (timer, &tp);
    *off = tp.tm_gmtoff;

-------

-- 
Fernando Oleo Blanco
https://irvise.xyz

             reply	other threads:[~2021-08-29 11:06 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 11:06 Fernando Oleo Blanco [this message]
2021-08-29 13:19 ` Help: Ada in NetBSD Stephane Carrez
2021-08-29 18:08   ` Fernando Oleo Blanco
2021-08-29 18:25     ` Simon Wright
2021-08-29 20:36       ` Fernando Oleo Blanco
2021-08-29 22:08         ` Stephane Carrez
2021-08-30  7:37           ` Simon Wright
2021-08-30  8:14           ` Fernando Oleo Blanco
2021-08-30 10:24             ` Fernando Oleo Blanco
2021-08-30 12:15               ` Fernando Oleo Blanco
2021-08-30 18:49                 ` Fernando Oleo Blanco
2021-08-30 19:23                   ` Simon Wright
2021-09-01  9:44                     ` Fernando Oleo Blanco
2021-09-01 21:41                       ` Simon Wright
2021-09-02 22:16                       ` Randy Brukardt
2021-09-03 20:18                         ` Simon Wright
2021-08-29 17:34 ` Simon Wright
2021-08-29 17:45   ` Fernando Oleo Blanco
2021-09-01 13:28 ` John R. Marino
2021-09-01 14:58   ` Fernando Oleo Blanco
2021-09-17 17:36     ` Fernando Oleo Blanco
2021-09-18 16:39       ` Fernando Oleo Blanco
2021-09-22 20:05         ` Fernando Oleo Blanco
2021-09-22 20:57           ` Simon Wright
2021-09-23  8:04           ` Luke A. Guest
2021-09-23 10:48             ` Kevin Chadwick
2021-09-23 17:01               ` Fernando Oleo Blanco
2021-09-23 17:04             ` Fernando Oleo Blanco
2021-09-23 19:53           ` Fernando Oleo Blanco
2021-09-24  7:48             ` Simon Wright
2021-09-24  9:44               ` Fernando Oleo Blanco
2021-09-13 18:49   ` Fernando Oleo Blanco
2021-09-13 22:24     ` Dennis Lee Bieber
2021-09-17 17:19       ` Fernando Oleo Blanco
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox