[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sbcl-devel
Subject:    [Sbcl-devel] Fix build on recent OpenBSD/i386 -current
From:       Josh Elsasser <josh () elsasser ! org>
Date:       2010-07-06 21:51:10
Message-ID: 20100706215110.GB23969 () opal ! elsasser ! org
[Download RAW message or body]

OpenBSD recently moved the fpu state from being hidden someplace where
probably shouldn't have been groveling around for it to right in
struct sigcontext, which of course breaks the SBCL build.

Attached is a patch which adds a small script in tools-for-build/ to
check where the fpu state is at compile-time. Tested on OpenBSD/i386
-current systems from before and after the change.


diff --git make-config.sh make-config.sh
index 84b34f5..8ce35af 100644
--- make-config.sh
+++ make-config.sh
@@ -309,6 +309,10 @@ if [ "$sbcl_arch" = "x86" ]; then
         # roughly-equivalent magic nevertheless.
         printf ' :os-provides-dlopen' >> $ltf
     fi
+    if [ "$sbcl_os" = "openbsd" ]; then
+        rm -f src/runtime/openbsd-sigcontext.h
+        sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
+    fi
 elif [ "$sbcl_arch" = "x86-64" ]; then
     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
     printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
diff --git src/runtime/x86-bsd-os.c src/runtime/x86-bsd-os.c
index d071666..1054659 100644
--- src/runtime/x86-bsd-os.c
+++ src/runtime/x86-bsd-os.c
@@ -20,9 +20,12 @@
 #endif
 
 #if defined(LISP_FEATURE_OPENBSD)
-#include <machine/frame.h>
 #include <machine/npx.h>
 #include <stddef.h>
+#include "openbsd-sigcontext.h"
+#ifdef OS_OPENBSD_FPSTATE_IN_SIGFRAME
+# include <machine/frame.h>
+#endif
 #endif
 
 /* KLUDGE: There is strong family resemblance in the signal context
@@ -248,11 +251,14 @@ os_restore_fp_control(os_context_t *context)
 void
 os_restore_fp_control(os_context_t *context)
 {
-    struct sigframe *frame;
-    union savefpu *fpu;
+#ifdef OS_OPENBSD_FPSTATE_IN_SIGFRAME
+    struct sigframe *frame = (struct sigframe *)((char*)context -
+        offsetof(struct sigframe, sf_sc));
+    union savefpu *fpu = frame->sf_fpstate;
+#elif defined(OS_OPENBSD_FPSTATE_IN_SIGCONTEXT)
+    union savefpu *fpu = context->sc_fpstate;
+#endif
 
-    frame = (struct sigframe *)((char*)context - offsetof(struct sigframe, sf_sc));
-    fpu = frame->sf_fpstate;
     if (openbsd_use_fxsave)
         __asm__ __volatile__ ("fldcw %0" : : "m" (fpu->sv_xmm.sv_env.en_cw));
     else
diff --git tools-for-build/openbsd-sigcontext.sh tools-for-build/openbsd-sigcontext.sh
new file mode 100644
index 0000000..4281bef
--- /dev/null
+++ tools-for-build/openbsd-sigcontext.sh
@@ -0,0 +1,41 @@
+cd ./tools-for-build
+
+base=openbsd-sigcontext
+
+# check for sf_fpstate in struct sigframe (ie: pre July 2010)
+rm -f "${base}.c"
+cat > "${base}.c" <<EOF
+#include <stddef.h>
+#include <stdio.h>
+#include <machine/frame.h>
+int
+main()
+{
+    printf("it works: %d\n", offsetof(struct sigframe, sf_fpstate));
+    return (0);
+}
+EOF
+if $GNUMAKE "${base}" > /dev/null 2>&1 && "./${base}" > /dev/null 2>&1
+then
+    echo '#define OS_OPENBSD_FPSTATE_IN_SIGFRAME'
+fi
+
+# check for sc_fpstate in struct sigcontext (ie: July 2010 and later)
+rm -f "${base}.c"
+cat > "${base}.c" <<EOF
+#include <stddef.h>
+#include <stdio.h>
+#include <signal.h>
+int
+main()
+{
+    printf("it works: %d\n", offsetof(struct sigcontext, sc_fpstate));
+    return (0);
+}
+EOF
+if $GNUMAKE "${base}" > /dev/null 2>&1 && "./${base}" > /dev/null 2>&1
+then
+    echo '#define OS_OPENBSD_FPSTATE_IN_SIGCONTEXT'
+fi
+
+rm -f "${base}.c" "${base}"

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Sbcl-devel mailing list
Sbcl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic