Fix fibers in dlang; unbreak powerpc64; add D for powerpc64

Unbreak gcc 11 on powerpc64 by adding a missing header file
(gnu-user.h in patch-gcc_config_gcc).  Add PFRAG.powerpc64-main.

The other changes are for D.  Add powerpc64 to ONLY_FOR_ARCHS-dlang,
and add enough PPC64 code to build libphobos.  While adding fibers for
powerpc64, also fix fibers for 32-bit powerpc, and pass MAP_STACK to
mmap(2) for fibers on all archs.

ok pascal@ (maintainer)
This commit is contained in:
gkoehler 2021-10-18 00:25:48 +00:00
parent 20cb4cfb4c
commit 631ea31585
11 changed files with 452 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.3 2021/08/24 18:13:19 gkoehler Exp $
# $OpenBSD: Makefile,v 1.4 2021/10/18 00:25:48 gkoehler Exp $
#
# When updating/switching to a new version, remember to adapt devel/llvm!
@ -12,7 +12,7 @@ ONLY_FOR_ARCHS = aarch64 alpha amd64 arm hppa i386 mips64 mips64el \
powerpc powerpc64 sparc64
ONLY_FOR_ARCHS-ada = amd64 i386 mips64 powerpc
ONLY_FOR_ARCHS-dlang = aarch64 amd64 arm i386 powerpc
ONLY_FOR_ARCHS-dlang = aarch64 amd64 arm i386 powerpc powerpc64
DPB_PROPERTIES = parallel
@ -20,6 +20,7 @@ V = 11.2.0
FULL_VERSION = $V
FULL_PKGVERSION = $V
REVISION = 0
REVISION-dlang = 1
ADASTRAP-amd64 = adastrap-amd64-$V-0.tar.xz
ADASTRAP-arm = adastrap-arm-4.9.4-0.tar.xz

View File

@ -1,4 +1,4 @@
$OpenBSD: patch-gcc_config_gcc,v 1.1.1.1 2021/08/15 18:42:10 pascal Exp $
$OpenBSD: patch-gcc_config_gcc,v 1.2 2021/10/18 00:25:48 gkoehler Exp $
Index: gcc/config.gcc
--- gcc/config.gcc.orig
@ -123,7 +123,7 @@ Index: gcc/config.gcc
+ ;;
+powerpc64*-*-openbsd*)
+ tm_defines="${tm_defines} DEFAULT_FLAG_PIE=2"
+ tm_file="${tm_file} dbxelf.h elfos.h openbsd.h openbsd-stdint.h openbsd-libpthread.h freebsd-spec.h rs6000/sysv4.h rs6000/default64.h rs6000/openbsd64.h"
+ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h openbsd.h openbsd-stdint.h openbsd-libpthread.h freebsd-spec.h rs6000/sysv4.h rs6000/default64.h rs6000/openbsd64.h"
+ tmake_file="${tmake_file} rs6000/t-openbsd64"
+ extra_options="${extra_options} rs6000/sysv4.opt rs6000/linux64.opt openbsd.opt"
+ ;;

View File

@ -0,0 +1,17 @@
$OpenBSD: patch-libphobos_configure,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Add fiber asm for powerpc64, to avoid
"configure: error: setcontext required but not found"
Index: libphobos/configure
--- libphobos/configure.orig
+++ libphobos/configure
@@ -15196,7 +15196,7 @@ fi
aarch64* | \
arm* | \
i[34567]86|x86_64 | \
- powerpc)
+ powerpc*)
druntime_fiber_asm_external=yes
;;
esac

View File

@ -0,0 +1,224 @@
$OpenBSD: patch-libphobos_libdruntime_config_powerpc_switchcontext_S,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Add fibers for powerpc64 ELFv2, and fix fibers for 32-bit powerpc ELF.
The old code was for some other platform (AIX?), not BSD nor Linux.
This patch fixes OpenBSD but might break the other platform.
This patch doesn't save altivec registers v20..v31, because gcc
disables altivec by default.
Index: libphobos/libdruntime/config/powerpc/switchcontext.S
--- libphobos/libdruntime/config/powerpc/switchcontext.S.orig
+++ libphobos/libdruntime/config/powerpc/switchcontext.S
@@ -24,7 +24,210 @@ see the files COPYING3 and COPYING.RUNTIME respectivel
#include "../common/threadasm.S"
-#if !defined(__PPC64__) && !defined(__MACH__)
+#if defined(__ELF__)
+
+/**
+ * Performs a context switch.
+ *
+ * r3 - old context pointer
+ * r4 - new context pointer
+ *
+ */
+ .text
+ .globl CSYM(fiber_switchContext)
+ .type CSYM(fiber_switchContext), @function
+ .align 2
+CSYM(fiber_switchContext):
+ .cfi_startproc
+#ifdef __PPC64__
+ /* ELF64 - Save linkage area */
+ mflr 0
+ mfcr 5
+ std 0, 16(1)
+ stw 5, 8(1)
+
+ /* Make room for 18 GPRs, 18 FPRs */
+ addi 6, 1, -18 * 8
+ addi 1, 6, -18 * 8
+
+ /* Save GPRs */
+ std 31, (17 * 8)(6)
+ std 30, (16 * 8)(6)
+ std 29, (15 * 8)(6)
+ std 28, (14 * 8)(6)
+ std 27, (13 * 8)(6)
+ std 26, (12 * 8)(6)
+ std 25, (11 * 8)(6)
+ std 24, (10 * 8)(6)
+ std 23, (9 * 8)(6)
+ std 22, (8 * 8)(6)
+ std 21, (7 * 8)(6)
+ std 20, (6 * 8)(6)
+ std 19, (5 * 8)(6)
+ std 18, (4 * 8)(6)
+ std 17, (3 * 8)(6)
+ std 16, (2 * 8)(6)
+ std 15, (1 * 8)(6)
+ std 14, (0 * 8)(6)
+#else
+ /* ELF32 - Save linkage area */
+ mflr 0
+ mfcr 5
+ stw 0, 4(1)
+
+ /* Make room for 18 GPRs, CR, 18 FPRs; rounding up so r1 stays
+ 16-byte aligned. We must move r1, because ELF32 allows
+ signals to clobber below r1 (no red zone). */
+ addi 6, 1, -20 * 4
+ addi 1, 6, -18 * 8
+
+ /* Save GPRs */
+ stw 31, (19 * 4)(6)
+ stw 30, (18 * 4)(6)
+ stw 29, (17 * 4)(6)
+ stw 28, (16 * 4)(6)
+ stw 27, (15 * 4)(6)
+ stw 26, (14 * 4)(6)
+ stw 25, (13 * 4)(6)
+ stw 24, (12 * 4)(6)
+ stw 23, (11 * 4)(6)
+ stw 22, (10 * 4)(6)
+ stw 21, (9 * 4)(6)
+ stw 20, (8 * 4)(6)
+ stw 19, (7 * 4)(6)
+ stw 18, (6 * 4)(6)
+ stw 17, (5 * 4)(6)
+ stw 16, (4 * 4)(6)
+ stw 15, (3 * 4)(6)
+ stw 14, (2 * 4)(6)
+
+ /* Save condition register */
+ stw 5, 0(6)
+#endif
+
+ /* ELF32 and ELF64 - Save FPRs */
+ stfd 31, (-1 * 8)(6)
+ stfd 30, (-2 * 8)(6)
+ stfd 29, (-3 * 8)(6)
+ stfd 28, (-4 * 8)(6)
+ stfd 27, (-5 * 8)(6)
+ stfd 26, (-6 * 8)(6)
+ stfd 25, (-7 * 8)(6)
+ stfd 24, (-8 * 8)(6)
+ stfd 23, (-9 * 8)(6)
+ stfd 22, (-10 * 8)(6)
+ stfd 21, (-11 * 8)(6)
+ stfd 20, (-12 * 8)(6)
+ stfd 19, (-13 * 8)(6)
+ stfd 18, (-14 * 8)(6)
+ stfd 17, (-15 * 8)(6)
+ stfd 16, (-16 * 8)(6)
+ stfd 15, (-17 * 8)(6)
+ stfd 14, (-18 * 8)(6)
+
+ /* Save r6 in the old context, since we do not want the GC to
+ scan the floating point registers. */
+
+#ifdef __PPC64__
+ /* ELF64 - Update the old stack pointer */
+ std 6, 0(3)
+
+ /* Set new stack pointer */
+ addi 1, 4, -18 * 8
+
+ /* Set condition and link register. If lr is &fiber_entryPoint,
+ then ELFv2 ABI needs the same address in r12. */
+ lwz 5, (18 * 8 + 8)(4)
+ ld 12, (18 * 8 + 16)(4)
+ mtcr 5
+ mtlr 12
+#else
+ /* ELF32 - Update the old stack pointer */
+ stw 6, 0(3)
+
+ /* Set new stack pointer */
+ addi 1, 4, -18 * 8
+
+ /* Set condition and link register */
+ lwz 5, 0(4)
+ lwz 12, (20 * 4 + 4)(4)
+ mtcr 5
+ mtlr 12
+#endif
+
+ /* PPC32 and PPC64 - Restore FPRs */
+ lfd 14, (-18 * 8)(4)
+ lfd 15, (-17 * 8)(4)
+ lfd 16, (-16 * 8)(4)
+ lfd 17, (-15 * 8)(4)
+ lfd 18, (-14 * 8)(4)
+ lfd 19, (-13 * 8)(4)
+ lfd 20, (-12 * 8)(4)
+ lfd 21, (-11 * 8)(4)
+ lfd 22, (-10 * 8)(4)
+ lfd 23, (-9 * 8)(4)
+ lfd 24, (-8 * 8)(4)
+ lfd 25, (-7 * 8)(4)
+ lfd 26, (-6 * 8)(4)
+ lfd 27, (-5 * 8)(4)
+ lfd 28, (-4 * 8)(4)
+ lfd 29, (-3 * 8)(4)
+ lfd 30, (-2 * 8)(4)
+ lfd 31, (-1 * 8)(4)
+
+#ifdef __PPC64__
+ /* PPC64 - Restore GPRs */
+ ld 14, (0 * 8)(4)
+ ld 15, (1 * 8)(4)
+ ld 16, (2 * 8)(4)
+ ld 17, (3 * 8)(4)
+ ld 18, (4 * 8)(4)
+ ld 19, (5 * 8)(4)
+ ld 20, (6 * 8)(4)
+ ld 21, (7 * 8)(4)
+ ld 22, (8 * 8)(4)
+ ld 23, (9 * 8)(4)
+ ld 24, (10 * 8)(4)
+ ld 25, (11 * 8)(4)
+ ld 26, (12 * 8)(4)
+ ld 27, (13 * 8)(4)
+ ld 28, (14 * 8)(4)
+ ld 29, (15 * 8)(4)
+ ld 30, (16 * 8)(4)
+ ld 31, (17 * 8)(4)
+
+ /* Return and switch context */
+ addi 1, 4, 18 * 8
+ blr
+#else
+ /* PPC32 - Restore GPRs */
+ lwz 14, (2 * 4)(4)
+ lwz 15, (3 * 4)(4)
+ lwz 16, (4 * 4)(4)
+ lwz 17, (5 * 4)(4)
+ lwz 18, (6 * 4)(4)
+ lwz 19, (7 * 4)(4)
+ lwz 20, (8 * 4)(4)
+ lwz 21, (9 * 4)(4)
+ lwz 22, (10 * 4)(4)
+ lwz 23, (11 * 4)(4)
+ lwz 24, (12 * 4)(4)
+ lwz 25, (13 * 4)(4)
+ lwz 26, (14 * 4)(4)
+ lwz 27, (15 * 4)(4)
+ lwz 28, (16 * 4)(4)
+ lwz 29, (17 * 4)(4)
+ lwz 30, (18 * 4)(4)
+ lwz 31, (19 * 4)(4)
+
+ /* Return and switch context */
+ addi 1, 4, 20 * 4
+ blr
+#endif
+ .cfi_endproc
+ .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext)
+
+#elif !defined(__PPC64__) && !defined(__MACH__)
/**
* Performs a context switch.

View File

@ -0,0 +1,18 @@
$OpenBSD: patch-libphobos_libdruntime_core_sys_posix_config_d,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Index: libphobos/libdruntime/core/sys/posix/config.d
--- libphobos/libdruntime/core/sys/posix/config.d.orig
+++ libphobos/libdruntime/core/sys/posix/config.d
@@ -169,6 +169,12 @@ else version (OpenBSD)
enum _STACKALIGNBYTES = 15;
enum _MAX_PAGE_SHIFT = 12;
}
+ else version (PPC64)
+ {
+ enum _ALIGNBYTES = 7;
+ enum _STACKALIGNBYTES = 15;
+ enum _MAX_PAGE_SHIFT = 12;
+ }
else version (SPARC64)
{
enum _ALIGNBYTES = 15;

View File

@ -1,16 +1,27 @@
$OpenBSD: patch-libphobos_libdruntime_core_sys_posix_setjmp_d,v 1.1.1.1 2021/08/15 18:42:11 pascal Exp $
$OpenBSD: patch-libphobos_libdruntime_core_sys_posix_setjmp_d,v 1.2 2021/10/18 00:25:49 gkoehler Exp $
Index: libphobos/libdruntime/core/sys/posix/setjmp.d
--- libphobos/libdruntime/core/sys/posix/setjmp.d.orig
+++ libphobos/libdruntime/core/sys/posix/setjmp.d
@@ -277,6 +277,10 @@ else version (OpenBSD)
@@ -265,6 +265,10 @@ else version (OpenBSD)
{
enum _JBLEN = 100;
}
+ else version (PPC64)
+ {
+ enum _JBLEN = 208;
+ }
else version (MIPS64)
{
enum _JBLEN = 83;
@@ -276,6 +280,10 @@ else version (OpenBSD)
else version (SPARC64)
{
enum _JBLEN = 14;
}
+ }
+ else version (AArch64)
+ {
+ enum _JBLEN = 64;
+ }
}
else
static assert(0);

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-libphobos_libdruntime_core_sys_posix_sys_mman_d,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Fiber needs mmap(2) MAP_STACK.
Index: libphobos/libdruntime/core/sys/posix/sys/mman.d
--- libphobos/libdruntime/core/sys/posix/sys/mman.d.orig
+++ libphobos/libdruntime/core/sys/posix/sys/mman.d
@@ -460,6 +460,7 @@ else version (OpenBSD)
enum MAP_PRIVATE = 0x0002;
enum MAP_FIXED = 0x0010;
enum MAP_ANON = 0x1000;
+ enum MAP_STACK = 0x4000;
enum MAP_FAILED = cast(void*)-1;

View File

@ -0,0 +1,31 @@
$OpenBSD: patch-libphobos_libdruntime_core_sys_posix_ucontext_d,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Index: libphobos/libdruntime/core/sys/posix/ucontext.d
--- libphobos/libdruntime/core/sys/posix/ucontext.d.orig
+++ libphobos/libdruntime/core/sys/posix/ucontext.d
@@ -1381,6 +1381,25 @@ else version (OpenBSD)
trapframe sc_frame;
}
}
+ else version (PPC64)
+ {
+ struct sigcontext
+ {
+ c_long sc_cookie;
+ int sc_mask;
+ c_long[32] sc_reg;
+ c_long sc_lr;
+ c_long sc_cr;
+ c_long sc_xer;
+ c_long sc_ctr;
+ c_long sc_pc;
+ c_long sc_ps;
+ c_long sc_vrsave;
+ ulong[2][64] sc_vsx; // __uint128_t
+ ulong sc_fpscr;
+ ulong sc_vcsr;
+ }
+ }
else version (SPARC64)
{
struct sigcontext

View File

@ -0,0 +1,82 @@
$OpenBSD: patch-libphobos_libdruntime_core_thread_fiber_d,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
Fiber needs mmap(2) MAP_STACK.
Add fibers for powerpc64 ELFv2, and fix fibers for 32-bit powerpc ELF.
The old code was for some other platform (AIX?), not BSD nor Linux.
This patch fixes OpenBSD but might break the other platform.
Index: libphobos/libdruntime/core/thread/fiber.d
--- libphobos/libdruntime/core/thread/fiber.d.orig
+++ libphobos/libdruntime/core/thread/fiber.d
@@ -125,6 +125,7 @@ private
{
version = AsmPPC_Posix;
version = AsmExternal;
+ version = AlignFiberStackTo16Byte;
}
}
else version (PPC64)
@@ -137,6 +138,8 @@ private
}
else version (Posix)
{
+ version = AsmPPC_Posix;
+ version = AsmExternal;
version = AlignFiberStackTo16Byte;
}
}
@@ -1033,10 +1036,13 @@ class Fiber (private)
// Allocate more for the memory guard
sz += guardPageSize;
+ int mmap_flags = MAP_PRIVATE | MAP_ANON;
+ version (OpenBSD)
+ mmap_flags |= MAP_STACK;
m_pmem = mmap( null,
sz,
PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON,
+ mmap_flags,
-1,
0 );
if ( m_pmem == MAP_FAILED )
@@ -1338,27 +1344,22 @@ class Fiber (private)
}
else version (AsmPPC_Posix)
{
- version (StackGrowsDown)
- {
- pstack -= int.sizeof * 5;
- }
- else
- {
- pstack += int.sizeof * 5;
- }
+ version (StackGrowsDown) {} else static assert (false);
- push( cast(size_t) &fiber_entryPoint ); // link register
- push( 0x00000000 ); // control register
- push( 0x00000000 ); // old stack pointer
-
- // GPR values
- version (StackGrowsDown)
+ version (PPC64)
{
- pstack -= int.sizeof * 20;
+ pstack -= size_t.sizeof * 5;
+ push( cast(size_t) &fiber_entryPoint); // link register
+ push( 0x00000000_00000000 ); // condition register
+ push( 0x00000000_00000000 ); // old stack pointer
+ pstack -= size_t.sizeof * 18; // GPRs
}
else
{
- pstack += int.sizeof * 20;
+ pstack -= size_t.sizeof * 6;
+ push( cast(size_t) &fiber_entryPoint); // link register
+ push( 0x00000000 ); // old stack pointer
+ pstack -= size_t.sizeof * 20; // GPRs and CR
}
assert( (cast(size_t) pstack & 0x0f) == 0 );

View File

@ -0,0 +1,42 @@
@comment $OpenBSD: PFRAG.powerpc64-main,v 1.1 2021/10/18 00:25:49 gkoehler Exp $
lib/gcc/${CONFIG}/${V}/include/altivec.h
lib/gcc/${CONFIG}/${V}/include/amo.h
lib/gcc/${CONFIG}/${V}/include/bmi2intrin.h
lib/gcc/${CONFIG}/${V}/include/bmiintrin.h
lib/gcc/${CONFIG}/${V}/include/emmintrin.h
lib/gcc/${CONFIG}/${V}/include/htmintrin.h
lib/gcc/${CONFIG}/${V}/include/htmxlintrin.h
lib/gcc/${CONFIG}/${V}/include/mm_malloc.h
lib/gcc/${CONFIG}/${V}/include/mmintrin.h
lib/gcc/${CONFIG}/${V}/include/pmmintrin.h
lib/gcc/${CONFIG}/${V}/include/ppc-asm.h
lib/gcc/${CONFIG}/${V}/include/ppu_intrinsics.h
lib/gcc/${CONFIG}/${V}/include/si2vmx.h
lib/gcc/${CONFIG}/${V}/include/smmintrin.h
lib/gcc/${CONFIG}/${V}/include/spu2vmx.h
lib/gcc/${CONFIG}/${V}/include/tgmath.h
lib/gcc/${CONFIG}/${V}/include/tmmintrin.h
lib/gcc/${CONFIG}/${V}/include/unwind.h
lib/gcc/${CONFIG}/${V}/include/vec_types.h
lib/gcc/${CONFIG}/${V}/include/x86intrin.h
lib/gcc/${CONFIG}/${V}/include/xmmintrin.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/dbxelf.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/elfos.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/freebsd-spec.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/gnu-user.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/initfini-array.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/openbsd-libpthread.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/openbsd-stdint.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/openbsd.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/default64.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/openbsd64.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/option-defaults.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000-builtin.def
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000-cpus.def
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000-modes.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000-opts.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000-protos.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/rs6000.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/rs6000/sysv4.h
lib/gcc/${CONFIG}/${V}/plugin/include/config/vxworks-dummy.h

View File

@ -1,4 +1,4 @@
@comment $OpenBSD: PLIST-main,v 1.1.1.1 2021/08/15 18:42:13 pascal Exp $
@comment $OpenBSD: PLIST-main,v 1.2 2021/10/18 00:25:49 gkoehler Exp $
@option is-branch
@conflict gcc-<12
@pkgpath lang/gcc/4.9,-main
@ -109,6 +109,7 @@ lib/gcc/${CONFIG}/${V}/plugin/include/config.h
%%mips64%%
%%mips64el%%
%%powerpc%%
%%powerpc64%%
%%sparc64%%
%%X86%%
lib/gcc/${CONFIG}/${V}/plugin/include/configargs.h