Porting to DragonFly BSD

Goetz Isenmann info at goetz-isenmann.de
Fri Nov 6 18:25:22 EST 2009


On Wed, Nov 04, 2009 at 03:08:27PM +0000, Colin Adams wrote:
> When GHC 6.12.1 is released, I'm going to have a go at porting it to
> DragonFly BSD (32-bit incarnation). Is the porting page on the
> wikiup-to-date?

Maybe you could start with something like:

$ curl -o ghc-6.10.4-3.tar.bz2 \
;   http://www.goetz-isenmann.de/dfly/ghc-6.10.4-3.tar.bz2
$ curl -o cabal http://www.goetz-isenmann.de/dfly/cabal
$ tar xzf ghc-6.10.4-3.tar.bz2 -C /var/tmp/isenmann
$ PATH=/var/tmp/isenmann/ghc-6.10.4-3/bin:$PATH
$ ./cabal update
$ ./cabal install --user cabal-install

I have just recompiled this ghc with itself using the attached
patches and --prefix=/var/tmp/isenmann on dragonfly 2.4.1 (32bit).

The patches are only a stupid "do the same for dragonfly as for
freebsd" with two exceptions AFAIR: (a) use -pthread not -lthr, and
(b) this -D_POSIX_VERSION=199309 in rts/Makefile, that's most probably
the wrong way to fix a (can't remember the details) build problem.

Until now I had no time and energie to dig deeper into the problem
[1], that looks to me, like rts/Linker cannot load any object file
that references errno.

My guess is, that for dragonflys "extern __thread int errno;" we do
not only need to add a new case in rts/Linker.c but also need to
generate different code for this thread local storage access.

Goetz


[1] $ ghci
GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
ghc: /var/tmp/isenmann/ghc-6.10.4-3/lib/ghc-6.10.4/base-4.1.0.0/HSbase-4.1.0.0.o: unhandled ELF relocation(Rel) type 15

Loading package base ... linking ... ghc: unable to load package `base'
-------------- next part --------------
diff -ru ghc-6.10.4-orig/compiler/nativeGen/NCG.h ghc-6.10.4/compiler/nativeGen/NCG.h
--- ghc-6.10.4-orig/compiler/nativeGen/NCG.h	2009-07-14 19:10:51 +0200
+++ ghc-6.10.4/compiler/nativeGen/NCG.h	2009-11-06 21:10:07 +0100
@@ -38,6 +38,12 @@
 # define IF_OS_freebsd(x,y) y
 #endif
 -- - - - - - - - - - - - - - - - - - - - - - 
+#if dragonfly_TARGET_OS
+# define IF_OS_dragonfly(x,y) x
+#else
+# define IF_OS_dragonfly(x,y) y
+#endif
+-- - - - - - - - - - - - - - - - - - - - - - 
 #if netbsd_TARGET_OS
 # define IF_OS_netbsd(x,y) x
 #else
diff -ru ghc-6.10.4-orig/configure ghc-6.10.4/configure
--- ghc-6.10.4-orig/configure	2009-07-14 19:24:26 +0200
+++ ghc-6.10.4/configure	2009-11-06 21:10:07 +0100
@@ -2307,6 +2307,15 @@
         HostVendor_CPP='unknown'
         HostOS_CPP='freebsd'
         ;;
+i[3456]86-*-dragonfly*)
+        HostPlatform=i386-unknown-dragonfly # hack again
+        TargetPlatform=i386-unknown-dragonfly
+        BuildPlatform=i386-unknown-dragonfly
+        HostPlatform_CPP='i386_unknown_dragonfly'
+        HostArch_CPP='i386'
+        HostVendor_CPP='unknown'
+        HostOS_CPP='dragonfly'
+        ;;
 i[3456]86-*-freebsd2*) # Older FreeBSDs are a.out
         HostPlatform=i386-unknown-freebsd2 # hack again
         TargetPlatform=i386-unknown-freebsd2
diff -ru ghc-6.10.4-orig/configure.ac ghc-6.10.4/configure.ac
--- ghc-6.10.4-orig/configure.ac	2009-07-14 19:10:53 +0200
+++ ghc-6.10.4/configure.ac	2009-11-06 21:10:07 +0100
@@ -260,6 +260,15 @@
         HostVendor_CPP='unknown'
         HostOS_CPP='freebsd'
         ;;
+i[[3456]]86-*-dragonfly*)
+        HostPlatform=i386-unknown-dragonfly # hack again
+        TargetPlatform=i386-unknown-dragonfly
+        BuildPlatform=i386-unknown-dragonfly
+        HostPlatform_CPP='i386_unknown_dragonfly'
+        HostArch_CPP='i386'
+        HostVendor_CPP='unknown'
+        HostOS_CPP='dragonfly'
+        ;;
 i[[3456]]86-*-freebsd2*) # Older FreeBSDs are a.out
         HostPlatform=i386-unknown-freebsd2 # hack again
         TargetPlatform=i386-unknown-freebsd2
diff -ru ghc-6.10.4-orig/distrib/configure-bin.ac ghc-6.10.4/distrib/configure-bin.ac
--- ghc-6.10.4-orig/distrib/configure-bin.ac	2009-07-14 19:10:52 +0200
+++ ghc-6.10.4/distrib/configure-bin.ac	2009-11-06 21:10:07 +0100
@@ -42,6 +42,8 @@
 	TargetPlatform=i386-unknown-freebsd2;;
 i[[3456]]86-*-freebsd[[3-9]]*)
 	TargetPlatform=i386-unknown-freebsd;;
+i[[3456]]86-*-dragonfly*)
+	TargetPlatform=i386-unknown-dragonfly;;
 i[[3456]]86-*-netbsd*)
 	TargetPlatform=i386-unknown-netbsd;;
 i[[3456]]86-*-openbsd*)
diff -ru ghc-6.10.4-orig/driver/mangler/ghc-asm.lprl ghc-6.10.4/driver/mangler/ghc-asm.lprl
--- ghc-6.10.4-orig/driver/mangler/ghc-asm.lprl	2009-07-14 19:10:52 +0200
+++ ghc-6.10.4/driver/mangler/ghc-asm.lprl	2009-11-06 21:10:07 +0100
@@ -160,12 +160,12 @@
     $T_HDR_vector   = "\.text\n\t\.align 4\n"; # NB: requires padding
 
     #--------------------------------------------------------#
-    } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|gnu|freebsd|netbsd|openbsd|kfreebsdgnu)$/m ) {
+    } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|gnu|freebsd|dragonfly|netbsd|openbsd|kfreebsdgnu)$/m ) {
 
     $T_STABBY	    = 0; # 1 iff .stab things (usually if a.out format)
     $T_US	    = ''; # _ if symbols have an underscore on the front
     $T_PRE_APP	    = # regexp that says what comes before APP/NO_APP
-		      ($TargetPlatform =~ /-(linux|gnu|freebsd|netbsd|openbsd)$/m) ? '#' : '/' ;
+		      ($TargetPlatform =~ /-(linux|gnu|freebsd|dragonfly|netbsd|openbsd)$/m) ? '#' : '/' ;
     $T_CONST_LBL    = '^\.LC(\d+):$'; # regexp for what such a lbl looks like
     $T_POST_LBL	    = ':';
     $T_X86_PRE_LLBL_PAT = '\.L';
@@ -216,7 +216,7 @@
     $T_HDR_vector   = "\.text\n\t\.align 8\n";
 
     #--------------------------------------------------------#
-    } elsif ( $TargetPlatform =~ /^x86_64-.*-(linux|openbsd|freebsd|netbsd)$/m ) {
+    } elsif ( $TargetPlatform =~ /^x86_64-.*-(linux|openbsd|freebsd|dragonfly|netbsd)$/m ) {
 
     $T_STABBY       = 0; # 1 iff .stab things (usually if a.out format)
     $T_US           = ''; # _ if symbols have an underscore on the front
diff -ru ghc-6.10.4-orig/libraries/unix/System/Posix/Signals.hsc ghc-6.10.4/libraries/unix/System/Posix/Signals.hsc
--- ghc-6.10.4-orig/libraries/unix/System/Posix/Signals.hsc	2009-07-14 19:20:42 +0200
+++ ghc-6.10.4/libraries/unix/System/Posix/Signals.hsc	2009-11-06 21:10:07 +0100
@@ -292,7 +292,7 @@
 raiseSignal :: Signal -> IO ()
 raiseSignal sig = throwErrnoIfMinus1_ "raiseSignal" (c_raise sig)
 
-#if defined(__GLASGOW_HASKELL__) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS))
+#if defined(__GLASGOW_HASKELL__) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS))
 foreign import ccall unsafe "genericRaise"
   c_raise :: CInt -> IO CInt
 #else
diff -ru ghc-6.10.4-orig/mk/config.mk.in ghc-6.10.4/mk/config.mk.in
--- ghc-6.10.4-orig/mk/config.mk.in	2009-07-14 19:10:53 +0200
+++ ghc-6.10.4/mk/config.mk.in	2009-11-06 21:10:07 +0100
@@ -298,7 +298,7 @@
 # Whether to include GHCi in the compiler.  Depends on whether the RTS linker
 # has support for this OS/ARCH combination.
 
-OsSupportsGHCi=$(strip $(patsubst $(HostOS_CPP), YES, $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 freebsd netbsd openbsd darwin)))
+OsSupportsGHCi=$(strip $(patsubst $(HostOS_CPP), YES, $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 freebsd dragonfly netbsd openbsd darwin)))
 ArchSupportsGHCi=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 powerpc sparc sparc64)))
 
 ifeq "$(OsSupportsGHCi)$(ArchSupportsGHCi)" "YESYES"
diff -ru ghc-6.10.4-orig/rts/Linker.c ghc-6.10.4/rts/Linker.c
--- ghc-6.10.4-orig/rts/Linker.c	2009-07-14 19:10:53 +0200
+++ ghc-6.10.4/rts/Linker.c	2009-11-06 21:10:07 +0100
@@ -61,12 +61,12 @@
 #include <sys/wait.h>
 #endif
 
-#if defined(ia64_HOST_ARCH) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
+#if defined(ia64_HOST_ARCH) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
 #define USE_MMAP
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#if defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
+#if defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -74,7 +74,7 @@
 
 #endif
 
-#if defined(linux_HOST_OS) || defined(solaris2_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
+#if defined(linux_HOST_OS) || defined(solaris2_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS)
 #  define OBJFORMAT_ELF
 #elif defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS)
 #  define OBJFORMAT_PEi386
@@ -1327,7 +1327,7 @@
        } else {
            if ((W_)result > 0x80000000) {
                // oops, we were given memory over 2Gb
-#if defined(freebsd_HOST_OS)
+#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)
                // Some platforms require MAP_FIXED.  This is normally
                // a bad idea, because MAP_FIXED will overwrite
                // existing mappings.
diff -ru ghc-6.10.4-orig/rts/Makefile ghc-6.10.4/rts/Makefile
--- ghc-6.10.4-orig/rts/Makefile	2009-07-14 19:10:53 +0200
+++ ghc-6.10.4/rts/Makefile	2009-11-06 21:10:07 +0100
@@ -139,7 +139,7 @@
 
 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
 # COMPILING_RTS is only used when building Win32 DLL support.
-STANDARD_OPTS += -DCOMPILING_RTS
+STANDARD_OPTS += -DCOMPILING_RTS -D_POSIX_VERSION=199309
 
 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
diff -ru ghc-6.10.4-orig/rts/RtsUtils.c ghc-6.10.4/rts/RtsUtils.c
--- ghc-6.10.4-orig/rts/RtsUtils.c	2009-07-14 19:10:52 +0200
+++ ghc-6.10.4/rts/RtsUtils.c	2009-11-06 21:10:07 +0100
@@ -461,7 +461,7 @@
  * genericRaise(), rather than raise(3).
  */
 int genericRaise(int sig) {
-#if defined(THREADED_RTS) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS))
+#if defined(THREADED_RTS) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS))
         return pthread_kill(pthread_self(), sig);
 #else
         return raise(sig);


More information about the Glasgow-haskell-users mailing list