On Tue, 27 Aug 2019 21:04:00 +0200
Otto Moerbeek <[email protected]> wrote:
> A first shot did not work here, so if you can take a closer look please
> do. In the meantime I'll try to do so as well after reading up on the ABI.
I made my own attempt to fix the *ppc32_sysv_elf* assembly code in
lang/boost, but I made some mistake. I believe that I set the stack
pointer %r1 outside MAP_STACK memory. This causes the machine to
freeze, as the macppc kernel gets stuck in an infinite loop, repeatedly
printing a message like
[jump]57834/195711 sp=9421ffc0 inside ffbee000-fffee000: not MAP_STACK
where "jump" is the name of the executable. "jump" is one of the
programs from WRKSRC/libs/context/example
To get the kernel messages to appear, I needed to rcctl stop xenodm,
so xconsole doesn't grab the messages. Then I ran the executable from
the boot console ttyC0 (Ctrl-Meta-F1).
I don't need boost to reproduce this kernel problem; it is enough to
build a program that sets a bad stack pointer, like
$ cat crash.c
#include <stdlib.h>
int
main(void) {
malloc(16384);
__asm__("addi %r1, %r3, 16368");
exit(0);
}
$ gcc -o crash crash.c
$ ./crash
The stuck kernel responds to nothing -- it doesn't answer ping(8) --
so my only way out is to force off the power, by holding the power
button of my PowerBook G4. I need to work around this kernel problem;
I might upgrade to a newer snapshot (my kernel is from Aug 26), report
a bug, or try to build a kernel without the MAP_STACK check.
The rest of this email is the *broken* diff to devel/boost. It
includes your fixes, plus my assembly changes.
Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/boost/Makefile,v
retrieving revision 1.89
diff -u -p -r1.89 Makefile
--- Makefile 9 Aug 2019 11:25:29 -0000 1.89
+++ Makefile 4 Sep 2019 02:39:07 -0000
@@ -17,7 +17,7 @@ EXTRACT_SUFX= .tar.bz2
FIX_EXTRACT_PERMISSIONS = Yes
REVISION-main= 6
-REVISION-md= 1
+REVISION-md= 2
SO_VERSION= 9.0
BOOST_LIBS= boost_atomic-mt \
Index: patches/patch-libs_context_build_Jamfile_v2
===================================================================
RCS file: patches/patch-libs_context_build_Jamfile_v2
diff -N patches/patch-libs_context_build_Jamfile_v2
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libs_context_build_Jamfile_v2 4 Sep 2019 02:39:07 -0000
@@ -0,0 +1,16 @@
+$OpenBSD$
+
+The second "clang" should be "gcc".
+
+Index: libs/context/build/Jamfile.v2
+--- libs/context/build/Jamfile.v2.orig
++++ libs/context/build/Jamfile.v2
+@@ -326,7 +326,7 @@ alias asm_sources
+ <address-model>32
+ <architecture>power
+ <binary-format>elf
+- <toolset>clang
++ <toolset>gcc
+ ;
+
+ alias asm_sources
Index: patches/patch-libs_context_src_asm_jump_ppc32_sysv_elf_gas_S
===================================================================
RCS file: patches/patch-libs_context_src_asm_jump_ppc32_sysv_elf_gas_S
diff -N patches/patch-libs_context_src_asm_jump_ppc32_sysv_elf_gas_S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libs_context_src_asm_jump_ppc32_sysv_elf_gas_S 4 Sep
2019 02:39:07 -0000
@@ -0,0 +1,66 @@
+$OpenBSD$
+
+ELF systems other than Linux use a different convention to return a
+small struct like transfer_t.
+
+Index: libs/context/src/asm/jump_ppc32_sysv_elf_gas.S
+--- libs/context/src/asm/jump_ppc32_sysv_elf_gas.S.orig
++++ libs/context/src/asm/jump_ppc32_sysv_elf_gas.S
+@@ -78,6 +78,9 @@
+ .align 2
+ .type jump_fcontext,@function
+ jump_fcontext:
++ # Linux: jump_fcontext( hidden transfer_t * %r3, %r4, %r5)
++ # Other: transfer_t %r3:%r4 = jump_fcontext( %r3, %r4)
++
+ # reserve space on stack
+ subi %r1, %r1, 244
+
+@@ -121,7 +124,9 @@ jump_fcontext:
+ stw %r29, 216(%r1) # save R29
+ stw %r30, 220(%r1) # save R30
+ stw %r31, 224(%r1) # save R31
++#ifdef __Linux__
+ stw %r3, 228(%r1) # save hidden
++#endif
+
+ # save CR
+ mfcr %r0
+@@ -135,8 +140,12 @@ jump_fcontext:
+ # store RSP (pointing to context-data) in R6
+ mr %r6, %r1
+
+- # restore RSP (pointing to context-data) from R4
++ # restore RSP (pointing to context-data) from R4/R3
++#ifdef __Linux__
+ mr %r1, %r4
++#else
++ mr %r1, %r3
++#endif
+
+ lfd %f14, 0(%r1) # restore F14
+ lfd %f15, 8(%r1) # restore F15
+@@ -178,7 +187,9 @@ jump_fcontext:
+ lwz %r29, 216(%r1) # restore R29
+ lwz %r30, 220(%r1) # restore R30
+ lwz %r31, 224(%r1) # restore R31
++#ifdef __Linux__
+ lwz %r3, 228(%r1) # restore hidden
++#endif
+
+ # restore CR
+ lwz %r0, 232(%r1)
+@@ -195,8 +206,13 @@ jump_fcontext:
+ addi %r1, %r1, 244
+
+ # return transfer_t
++#ifdef __Linux__
+ stw %r6, 0(%r3)
+ stw %r5, 4(%r3)
++#else
++ mr %r3, %r5
++ # %r4, %r4
++#endif
+
+ # jump to context
+ bctr
Index: patches/patch-libs_context_src_asm_make_ppc32_sysv_elf_gas_S
===================================================================
RCS file: patches/patch-libs_context_src_asm_make_ppc32_sysv_elf_gas_S
diff -N patches/patch-libs_context_src_asm_make_ppc32_sysv_elf_gas_S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libs_context_src_asm_make_ppc32_sysv_elf_gas_S 4 Sep
2019 02:39:07 -0000
@@ -0,0 +1,21 @@
+$OpenBSD$
+
+ELF systems other than Linux use a different convention to return a
+small struct like transfer_t.
+
+Index: libs/context/src/asm/make_ppc32_sysv_elf_gas.S
+--- libs/context/src/asm/make_ppc32_sysv_elf_gas.S.orig
++++ libs/context/src/asm/make_ppc32_sysv_elf_gas.S
+@@ -99,10 +99,12 @@ make_fcontext:
+ mffs %f0 # load FPSCR
+ stfd %f0, 144(%r3) # save FPSCR
+
++#ifdef __Linux__
+ # compute address of returned transfer_t
+ addi %r0, %r3, 252
+ mr %r4, %r0
+ stw %r4, 228(%r3)
++#endif
+
+ # load LR
+ mflr %r0
Index: patches/patch-libs_context_src_asm_ontop_ppc32_sysv_elf_gas_S
===================================================================
RCS file: patches/patch-libs_context_src_asm_ontop_ppc32_sysv_elf_gas_S
diff -N patches/patch-libs_context_src_asm_ontop_ppc32_sysv_elf_gas_S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libs_context_src_asm_ontop_ppc32_sysv_elf_gas_S 4 Sep
2019 02:39:07 -0000
@@ -0,0 +1,75 @@
+$OpenBSD$
+
+ELF systems other than Linux use a different convention to return a
+small struct like transfer_t.
+
+Index: libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S
+--- libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S.orig
++++ libs/context/src/asm/ontop_ppc32_sysv_elf_gas.S
+@@ -78,6 +78,9 @@
+ .align 2
+ .type ontop_fcontext,@function
+ ontop_fcontext:
++ # Linux: ontop_fcontext( hidden transfer_t * %r3, %r4, %r5, %r6)
++ # Other: transfer_t %r3:%r4 = ontop_fcontext( %r3, %r4, %r5)
++
+ # reserve space on stack
+ subi %r1, %r1, 244
+
+@@ -121,7 +124,9 @@ ontop_fcontext:
+ stw %r29, 216(%r1) # save R29
+ stw %r30, 220(%r1) # save R30
+ stw %r31, 224(%r1) # save R31
++#ifdef __Linux__
+ stw %r3, 228(%r1) # save hidden
++#endif
+
+ # save CR
+ mfcr %r0
+@@ -135,8 +140,12 @@ ontop_fcontext:
+ # store RSP (pointing to context-data) in R7
+ mr %r7, %r1
+
+- # restore RSP (pointing to context-data) from R4
++ # restore RSP (pointing to context-data) from R4/R3
++#ifdef __Linux__
+ mr %r1, %r4
++#else
++ mr %r1, %r3
++#endif
+
+ lfd %f14, 0(%r1) # restore F14
+ lfd %f15, 8(%r1) # restore F15
+@@ -178,7 +187,9 @@ ontop_fcontext:
+ lwz %r29, 216(%r1) # restore R29
+ lwz %r30, 220(%r1) # restore R30
+ lwz %r31, 224(%r1) # restore R31
++#ifdef __Linux__
+ lwz %r4, 228(%r1) # restore hidden
++#endif
+
+ # restore CR
+ lwz %r0, 232(%r1)
+@@ -191,12 +202,21 @@ ontop_fcontext:
+ # adjust stack
+ addi %r1, %r1, 244
+
+- # return transfer_t
++ # return transfer_t
++#ifdef __Linux__
+ stw %r7, 0(%r4)
+ stw %r5, 4(%r4)
++#else
++ mr %r3, %r7
++ # %r4, %r4
++#endif
+
+ # restore CTR
++#ifdef __Linux__
+ mtctr %r6
++#else
++ mtctr %r5
++#endif
+
+ # jump to ontop-function
+ bctr