Mon Feb 17 21:40:00 CET 2020

making pcc compile on netbsd-current/i386

It's done:

% pcc hw.c && ./a.out
hello world!

This is pcc(1) on eddie, an i386 running netbsd-9.99.thirtyish. The Portable C Compiler is currently not among the official build targets of netbsd because gcc refuses to build it as-is. That needed to be fixed.

It turned out I had to give a little TLC to just three files, a bit of work spread across a month:

% pwd
/usr/src/external/bsd/pcc/dist/pcc/cc
% ls -lrt ccom/pftn.c cxxcom/builtins.c driver/driver.c
-rw-rw-r--  1 neitzel  wsrc  74886 Jan 22 02:24 ccom/pftn.c
-rw-rw-r--  1 neitzel  wsrc  20350 Jan 29 00:28 driver/driver.c
-rw-rw-r--  1 neitzel  wsrc  22602 Feb 17 21:40 cxxcom/builtins.c

The required changes where small and need further review by someone more competent than me:

% cvs -q diff -u
Index: ccom/pftn.c
===================================================================
RCS file: /cvsroot/src/external/bsd/pcc/dist/pcc/cc/ccom/pftn.c,v
retrieving revision 1.10
diff -u -r1.10 pftn.c
--- ccom/pftn.c 9 Feb 2016 20:37:32 -0000       1.10
+++ ccom/pftn.c 12 May 2020 20:30:52 -0000
@@ -2544,8 +2544,11 @@
    if (apole != NULL)
        uerror("too many arguments to function");

-build: if (apary)
+build: if (apary) {
+       /* MN: braces because gcc thinks the following
+       stmt is not existing */
        FUNFREE(apary);
+       }
    if (sp != NULL && (sp->sflags & SINLINE) && (w = inlinetree(sp, f, a)))
        return w;
    return buildtree(a == NIL ? UCALL : CALL, f, a);
Index: cxxcom/builtins.c
===================================================================
RCS file: /cvsroot/src/external/bsd/pcc/dist/pcc/cc/cxxcom/builtins.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 builtins.c
--- cxxcom/builtins.c   9 Feb 2016 20:28:56 -0000       1.1.1.4
+++ cxxcom/builtins.c   12 May 2020 20:30:52 -0000
@@ -537,7 +537,13 @@
 #ifdef LDBL_128
 static const unsigned char vLDOUBLE[] = { 0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f };
 #else /* LDBL_80 */
-static const unsigned char vLDOUBLE[] = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f };
+/*
+ * MN: create 2 extra bytes for a total of 96 bits, as with nLDOUBLE;
+ * gcc's sizeof(long double) is 12 bytes = 96 bits, this may be an ABI issue.
+ * the hardware-supported "extended precision floating point" is 80 bits,
+ * 64 bit significant + 16 bits exponent, each signed.
+ */
+static const unsigned char vLDOUBLE[] = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f, 0, 0 };
 #endif
 static const unsigned char nFLOAT[] = { 0, 0, 0xc0, 0x7f };
 static const unsigned char nDOUBLE[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
@@ -552,6 +558,7 @@
 #ifdef LDBL_128
 static const unsigned char vLDOUBLE[] = { 0x7f, 0xff, 0x80, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0 };
 #else /* LDBL_80 */
+/* MN: this appears to fall short of the 12 byte ABI size, cf. TARGET_LE: */
 static const unsigned char vLDOUBLE[] = { 0x7f, 0xff, 0x80, 0, 0, 0, 0, 0, 0, 0 };
 #endif
 static const unsigned char nFLOAT[] = { 0x7f, 0xc0, 0, 0 };
@@ -559,6 +566,7 @@
 #ifdef LDBL_128
 static const unsigned char nLDOUBLE[] = { 0x7f, 0xff, 0xc0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0 };
 #else /* LDBL_80 */
+/* MN: this appears to fall short of the 12 byte ABI size, cf. TARGET_LE: */
 static const unsigned char nLDOUBLE[] = { 0x7f, 0xff, 0xc0, 0, 0, 0, 0, 0, 0, 0 };
 #endif
 #endif
Index: driver/driver.c
===================================================================
RCS file: /cvsroot/src/external/bsd/pcc/dist/pcc/cc/driver/driver.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 driver.c
--- driver/driver.c     1 Sep 2011 12:47:04 -0000       1.1.1.1
+++ driver/driver.c     12 May 2020 20:30:53 -0000
@@ -193,7 +193,7 @@
    strlist_make_array(l, &argv, &argc);
    if (verbose_mode) {
        printf("Calling ");
-               strlist_print(l, stdout);
+               strlist_print(l, stdout, 1 /* MN XXX guessed! */);
        printf("\n");
    }

(This is not a proper diff -- the white space was mangled during cutnpaste and the markup may also do funny things to the tabs.)

As you can see I rather coaxed it through gcc than really knowing what's correct. This needs some further shaking out. However, there's some light at the end of the tunnel, and the tunnel seems not to be as endless as someone argued on a netbsd mailing list.

The most difficult part for me was to find out how to run the proper make from the proper place in the netbsd /usr/src tree. Building the entire system is no option when tackling just a small part of the system.


Posted by neitzel | Permanent link | File under: done, bsd