Tuesday, October 25, 2022

lang/pcc for powerpc

Hello, ports list!

I want to commit this diff, which will unbreak lang/pcc/pcc-libs and
minimally fix lang/pcc/pcc for powerpc. I can now compile the
simplest C program for powerpc,

$ cat hello.c
#include <stdio.h>
int main(void) { puts("Hello, BSD!"); return 0; }
$ pcc -O2 -o hello hello.c
$ ./hello

I like how my macppc can build pcc in a few minutes; the same mac
might take 3 to 4 days to build either clang or gcc.

Is anyone using pcc on OpenBSD? This diff should not affect arches
other than powerpc, but I want to know if anyone is running pcc on
any OpenBSD arch.

--George

Index: pcc/Makefile
===================================================================
RCS file: /cvs/ports/lang/pcc/pcc/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- pcc/Makefile 11 Mar 2022 19:29:10 -0000 1.3
+++ pcc/Makefile 25 Oct 2022 19:21:14 -0000
@@ -2,6 +2,7 @@ COMMENT = portable C compiler

DISTNAME = pcc-${DISTVER}
PKGNAME = pcc-${PKGVER}
+REVISION = 0

WANTLIB += c

Index: pcc/patches/patch-arch_powerpc_local2_c
===================================================================
RCS file: pcc/patches/patch-arch_powerpc_local2_c
diff -N pcc/patches/patch-arch_powerpc_local2_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pcc/patches/patch-arch_powerpc_local2_c 25 Oct 2022 19:21:14 -0000
@@ -0,0 +1,45 @@
+Emit code for the secure PLT, where r30 must point to the global
+offset table.
+
+Add a shape SGOTCON to emit code like "lwz %r3,.L459@got(30)" for
+loading a constant address from the global offset table. This fixes
+string literals in PIC.
+
+Index: arch/powerpc/local2.c
+--- arch/powerpc/local2.c.orig
++++ arch/powerpc/local2.c
+@@ -143,8 +143,21 @@ prologue(struct interpass_prolog *ipp)
+
+ if (kflag) {
+ #if defined(ELFABI)
++#if 0 /* BSS PLT */
+ printf("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n");
+ printf("\tmflr %s\n", rnames[GOTREG]);
++#else /* secure PLT */
++ const char *gotreg = rnames[GOTREG];
++ int lab = getlab2();
++
++ printf("\tbcl 20,31," LABFMT "\n", lab);
++ deflab(lab);
++ printf("\tmflr %s\n", gotreg);
++ printf("\taddis %s,%s,_GLOBAL_OFFSET_TABLE_-" LABFMT "@ha\n",
++ gotreg, gotreg, lab);
++ printf("\taddi %s,%s,_GLOBAL_OFFSET_TABLE_-" LABFMT "@l\n",
++ gotreg, gotreg, lab);
++

No comments:

Post a Comment