[m-rev.] for review: Support OpenBSD.

Peter Wang novalazy at gmail.com
Thu Mar 1 16:18:40 AEDT 2018


configure.ac:
    Set flags to build Boehm GC with threads support and parallel
    marking.

    Prevent use of "__thread" storage class specifier on OpenBSD;
    it does not work.

    Enable shared libraries on OpenBSD.

README.OpenBSD:
    New file.

.README.in:
README.md:
    Mention README.OpenBSD.

.nocopyright:
    Add README.OpenBSD.
---
 .README.in     |  3 ++-
 .nocopyright   |  1 +
 README.OpenBSD | 12 ++++++++++++
 README.md      |  1 +
 configure.ac   | 27 +++++++++++++++++++++++----
 5 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 README.OpenBSD

diff --git a/.README.in b/.README.in
index 42be38499..576c578ea 100644
--- a/.README.in
+++ b/.README.in
@@ -9,7 +9,7 @@ or particular architectures, so first read the README file for your particular
 platform, if there is one:
 
 	README.AIX		RS/6000 systems running AIX
-	README.FreeBSD		The FreeBSD version of BSD Unix on Intel x86
+	README.FreeBSD		FreeBSD on Intel x86 and x86_64
 	README.HPUX		HPPA systems running HPUX
 	README.Linux		Linux on Intel x86 and x86_64
 	README.Linux-Alpha	Linux on DEC Alpha
@@ -17,6 +17,7 @@ platform, if there is one:
 	README.Linux-m68k	Linux on Motorola 68000
 	README.MacOS		Apple Mac systems running Mac OS X
 	README.MS-Windows	Microsoft Windows
+	README.OpenBSD		OpenBSD on Intel x86_64
 	README.Solaris		Solaris (SunOS) on SPARC or Intel x86.
 
 The documentation sources are in the `doc' subdirectory.  The installation
diff --git a/.nocopyright b/.nocopyright
index 382d7a1c7..251da11f1 100644
--- a/.nocopyright
+++ b/.nocopyright
@@ -34,6 +34,7 @@ README.MinGW-cross
 README.MS-VisualC
 README.MS-Windows
 README.OSF1
+README.OpenBSD
 README.Solaris
 README.ssdebug
 README.CSharp
diff --git a/README.OpenBSD b/README.OpenBSD
new file mode 100644
index 000000000..4df0a1f5c
--- /dev/null
+++ b/README.OpenBSD
@@ -0,0 +1,12 @@
+
+Mercury on OpenBSD
+==================
+
+Tested on OpenBSD 6.2 arm64 with clang 4.0 and gcc 4.9.
+
+The base version of gcc is 4.2.1, but you can install a more recent
+version from ports with "pkg_add gcc", then direct Mercury to use 'egcc'
+by running:
+
+    CC=egcc ./configure <your normal configure arguments>
+
diff --git a/README.md b/README.md
index f95aa1097..11465021e 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ Specific information is contained in individual README files:
         [m68k](README.Linux-m68k))
       * [MacOS X](README.MacOS)
       * [FreeBSD](README.FreeBSD)
+      * [OpenBSD](README.OpenBSD)
       * [AIX](README.AIX)
       * [HP-UX](README.HPUX)
       * [Solaris](README.Solaris)
diff --git a/configure.ac b/configure.ac
index ce4d93ceb..45cc6b334 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3265,7 +3265,15 @@ case "$host" in
         ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
         ;;
 
-    *freebsd*)
+    *-freebsd*)
+        CFLAGS_FOR_THREADS="-DGC_THREADS"
+        THREAD_LIBS="-lpthread"
+        ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
+        ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
+        avoid_sbrk=yes
+        ;;
+
+    *-openbsd*)
         CFLAGS_FOR_THREADS="-DGC_THREADS"
         THREAD_LIBS="-lpthread"
         ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
@@ -3326,12 +3334,11 @@ AC_CACHE_VAL(mercury_cv_thread_local_storage,
 )
 AC_MSG_RESULT($mercury_cv_thread_local_storage)
 
-# Thread-local storage is disabled on Solaris as there is a linker problem
-# with shared objects and TLS.
-
 if test "$mercury_cv_thread_local_storage" = yes; then
     case "$host" in
         *-solaris2.*)
+            # Thread-local storage is disabled on Solaris as there is a linker
+            # problem with shared objects and TLS.
             ;;
         *apple*darwin*)
             # XXX only attempt to use __thread with GCC on Mac OS X.
@@ -3343,6 +3350,14 @@ if test "$mercury_cv_thread_local_storage" = yes; then
                     ;;
             esac
             ;;
+        *-openbsd*)
+            # The above test "passes" but OpenBSD (6.2) does not support TLS
+            # natively, so is emulated by gcc/clang using something like the
+            # pthread thread-specific data API. Moreover, something goes wrong
+            # with the emulation when a Mercury program is dynamically linked
+            # to the Mercury runtime (MR_thread_engine_base is assigned in one
+            # place but remains NULL when read elsewhere).
+            ;;
         *)
             AC_DEFINE([MR_THREAD_LOCAL_STORAGE])
             ;;
@@ -4440,6 +4455,10 @@ case "$host" in
         AC_MSG_RESULT(yes)
         EXT_FOR_SHARED_LIB=so
         ;;
+    *-openbsd*)
+        AC_MSG_RESULT(yes)
+        EXT_FOR_SHARED_LIB=so
+        ;;
     i*86-*-solaris2.*)
         AC_MSG_RESULT(yes)
 
-- 
2.16.2



More information about the reviews mailing list