On Thu, 12 Sep 2019 16:19:18 +0200
Otto Moerbeek <otto@drijf.net> wrote:
> On Thu, Sep 12, 2019 at 12:54:47AM -0400, George Koehler wrote:
> > The broken diff follows.
>
> The good news is that is is not broken for my use-case: PowerDNS
> Recursor. It does not use ontop_fcontext. Thanks a lot for working on
> this! I am wondering if there any users of ontop_fcontext in our tree...
>
> -Otto
Here's a new diff with 3 more fixes:
1. It changes ontop_fcontext, so the fibonacci example now works.
2. It changes make_fcontext to align the stack pointer to 16 bytes.
(Most code can run well or slightly slow with a 4-aligned stack
pointer, but altivec vectors might cause a problem.)
3. Our patch-boost_context_pooled_fixedsize_stack_hpp used a wrong
variable name, so any program that tried to #include
<boost/context/pooled_fixedsize_stack.hpp> would get an error.
The diff changes the variable name and bumps REVISION-main; this
is the only part of the diff to affect arches other than powerpc.
I have no code using pooled_fixedsize_stack, but one of the examples
in boost includes the header via <boost/context/all.hpp>.
I broke the fibonacci example because I caused ontop_fcontext to leave
a stack frame, but didn't provide an .eh_frame for C++ exceptions.
Then fibonacci threw an exception, but the unwinder can't remove the
frame, so it didn't reach the code to catch the exception.
To fix fibonacci, I go back to having ontop_fcontext make a tail call
to the ontop-function without leaving a stack frame, like it does on
Linux. I then cheat by placing an 8-byte transfer_t on the *other*
stack; the existing code uses a similar cheat on Linux. This cheat
will break if the program resumes the other stack before the
ontop-function returns, but this is already broken on Linux.
The diff doesn't fix 2 other bugs:
1. The handling of register %r13 is wrong, but this seems not to
matter on OpenBSD, so I'm not trying to fix it.
2. The call to _exit(0) in make_fcontext is wrong for systems using
the secure PLT, like OpenBSD. I have no code that reaches this
call, but I would expect it to crash because it fails to set r30
to the global offset table.
I have stopped work on this diff. My next task is to report an issue
to GitHub boost/context, about the multiple problems with ppc32.
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 14 Sep 2019 00:56:15 -0000
@@ -16,8 +16,8 @@ MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:
EXTRACT_SUFX= .tar.bz2
FIX_EXTRACT_PERMISSIONS = Yes
-REVISION-main= 6
-REVISION-md= 1
+REVISION-main= 7
+REVISION-md= 2
SO_VERSION= 9.0
BOOST_LIBS= boost_atomic-mt \
Index: patches/patch-boost_context_pooled_fixedsize_stack_hpp
===================================================================
RCS file: /cvs/ports/devel/boost/patches/patch-boost_context_pooled_fixedsize_stack_hpp,v
retrieving revision 1.1
diff -u -p -r1.1 patch-boost_context_pooled_fixedsize_stack_hpp
--- patches/patch-boost_context_pooled_fixedsize_stack_hpp 13 Dec 2018 19:52:46 -0000 1.1
+++ patches/patch-boost_context_pooled_fixedsize_stack_hpp 14 Sep 2019 00:56:15 -0000
@@ -18,7 +18,7 @@ Index: boost/context/pooled_fixedsize_st
stack_context allocate() {
- void * vp = storage_.malloc();
- if ( ! vp) {
-+ void * vp = mmap(NULL, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
++ void * vp = mmap(NULL, stack_size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
+ if ( vp == MAP_FAILED ) {
throw std::bad_alloc();
}
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 14 Sep 2019 00:56:15 -0000
@@ -0,0 +1,17 @@
+$OpenBSD$
+
+ppc32_sysv_elf has 2 instances of "<toolset>clang".
+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 14 Sep 2019 00:56:15 -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
++
No comments:
Post a Comment