summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dev-lang/ghc/files')
-rw-r--r--dev-lang/ghc/files/ghc-7.0.4-CHOST-prefix.patch17
-rw-r--r--dev-lang/ghc/files/ghc-7.0.4-darwin8.patch18
-rw-r--r--dev-lang/ghc/files/ghc-7.10.1-T10590-dequeue.patch89
-rw-r--r--dev-lang/ghc/files/ghc-7.10.1-rc3-ghc-7.10-bootstrap.patch78
-rw-r--r--dev-lang/ghc/files/ghc-7.2.1-freebsd-CHOST.patch13
-rw-r--r--dev-lang/ghc/files/ghc-7.4-rc2-macos-prefix-respect-gcc.patch23
-rw-r--r--dev-lang/ghc/files/ghc-7.4.1-darwin-CHOST.patch18
-rw-r--r--dev-lang/ghc/files/ghc-7.4.1-ticket-7339-fix-unaligned-unreg.patch28
-rw-r--r--dev-lang/ghc/files/ghc-7.4.2-system-libffi.patch119
-rw-r--r--dev-lang/ghc/files/ghc-7.5.20120505-system-libffi.patch88
-rw-r--r--dev-lang/ghc/files/ghc-7.6.2-integer-simple-div-mod.patch57
-rw-r--r--dev-lang/ghc/files/ghc-7.6.3-preserve-inplace-xattr.patch14
-rw-r--r--dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch387
-rw-r--r--dev-lang/ghc/files/ghc-7.8.1_rc1-libbfd.patch81
-rw-r--r--dev-lang/ghc/files/ghc-7.8.2-cgen-constify.patch34
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-cc-lang.patch129
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-deRefStablePtr.patch38
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-ia64-prim.patch69
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-linker-warn.patch35
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-pic-asm.patch107
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-pic-sparc.patch31
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch351
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-prim-lm.patch12
-rw-r--r--dev-lang/ghc/files/ghc-7.8.3-unreg-lit.patch84
-rw-r--r--dev-lang/ghc/files/ghc-7.8.4-gold.patch27
-rw-r--r--dev-lang/ghc/files/ghc-7.8.4-ia64-CLOSUREs.patch66
-rw-r--r--dev-lang/ghc/files/ghc-bash-completion218
-rw-r--r--dev-lang/ghc/files/terminfo-0.3.2.5-tinfo.patch25
28 files changed, 2256 insertions, 0 deletions
diff --git a/dev-lang/ghc/files/ghc-7.0.4-CHOST-prefix.patch b/dev-lang/ghc/files/ghc-7.0.4-CHOST-prefix.patch
new file mode 100644
index 000000000000..682c573c90a6
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.0.4-CHOST-prefix.patch
@@ -0,0 +1,17 @@
+Strip versioning components from *HOST for Darwin and Solaris
+
+--- aclocal.m4
++++ aclocal.m4
+@@ -1358,6 +1358,12 @@
+ freebsd*)
+ $2="freebsd"
+ ;;
++ darwin*)
++ $2="darwin"
++ ;;
++ solaris2.*)
++ $2="solaris2"
++ ;;
+ *)
+ echo "Unknown OS $1"
+ exit 1
diff --git a/dev-lang/ghc/files/ghc-7.0.4-darwin8.patch b/dev-lang/ghc/files/ghc-7.0.4-darwin8.patch
new file mode 100644
index 000000000000..bfbee41b4f93
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.0.4-darwin8.patch
@@ -0,0 +1,18 @@
+Workaround headers problem in Darwin 8 as well.
+
+--- rts/PosixSource.h
++++ rts/PosixSource.h
+@@ -11,6 +11,13 @@
+
+ #include <ghcplatform.h>
+
++#if defined(darwin_HOST_OS)
++/* unfortunately the hack below only works for Darwin 9 and
++ * above, so as hack include sys/types early (before setting
++ * _POSIX_C_SOURCE) (this obviously obsoletes the hack below) */
++#include <sys/types.h>
++#endif
++
+ #if defined(freebsd_HOST_OS)
+ #define _POSIX_C_SOURCE 200112L
+ #define _XOPEN_SOURCE 600
diff --git a/dev-lang/ghc/files/ghc-7.10.1-T10590-dequeue.patch b/dev-lang/ghc/files/ghc-7.10.1-T10590-dequeue.patch
new file mode 100644
index 000000000000..be0f7a05b1e3
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.10.1-T10590-dequeue.patch
@@ -0,0 +1,89 @@
+diff --git a/rts/RaiseAsync.c b/rts/RaiseAsync.c
+index 3b206ff..08c031c 100644
+--- a/rts/RaiseAsync.c
++++ b/rts/RaiseAsync.c
+@@ -56,7 +56,8 @@ static void throwToSendMsg (Capability *cap USED_IF_THREADS,
+
+ static void
+ throwToSingleThreaded__ (Capability *cap, StgTSO *tso, StgClosure *exception,
+- rtsBool stop_at_atomically, StgUpdateFrame *stop_here)
++ rtsBool stop_at_atomically, StgUpdateFrame *stop_here,
++ rtsBool dequeue)
+ {
+ // Thread already dead?
+ if (tso->what_next == ThreadComplete || tso->what_next == ThreadKilled) {
+@@ -64,7 +65,9 @@ throwToSingleThreaded__ (Capability *cap, StgTSO *tso, StgClosure *exception,
+ }
+
+ // Remove it from any blocking queues
+- removeFromQueues(cap,tso);
++ if (dequeue) {
++ removeFromQueues(cap,tso);
++ }
+
+ raiseAsync(cap, tso, exception, stop_at_atomically, stop_here);
+ }
+@@ -72,20 +75,26 @@ throwToSingleThreaded__ (Capability *cap, StgTSO *tso, StgClosure *exception,
+ void
+ throwToSingleThreaded (Capability *cap, StgTSO *tso, StgClosure *exception)
+ {
+- throwToSingleThreaded__(cap, tso, exception, rtsFalse, NULL);
++ throwToSingleThreaded__(cap, tso, exception, rtsFalse, NULL, rtsTrue);
++}
++
++void
++throwToSingleThreadedNoDequeue (Capability *cap, StgTSO *tso, StgClosure *exception)
++{
++ throwToSingleThreaded__(cap, tso, exception, rtsFalse, NULL, rtsFalse);
+ }
+
+ void
+ throwToSingleThreaded_ (Capability *cap, StgTSO *tso, StgClosure *exception,
+ rtsBool stop_at_atomically)
+ {
+- throwToSingleThreaded__ (cap, tso, exception, stop_at_atomically, NULL);
++ throwToSingleThreaded__ (cap, tso, exception, stop_at_atomically, NULL, rtsTrue);
+ }
+
+ void // cannot return a different TSO
+ suspendComputation (Capability *cap, StgTSO *tso, StgUpdateFrame *stop_here)
+ {
+- throwToSingleThreaded__ (cap, tso, NULL, rtsFalse, stop_here);
++ throwToSingleThreaded__ (cap, tso, NULL, rtsFalse, stop_here, rtsTrue);
+ }
+
+ /* -----------------------------------------------------------------------------
+diff --git a/rts/RaiseAsync.h b/rts/RaiseAsync.h
+index 6bfed8d..2e8a7a3 100644
+--- a/rts/RaiseAsync.h
++++ b/rts/RaiseAsync.h
+@@ -23,6 +23,10 @@ void throwToSingleThreaded (Capability *cap,
+ StgTSO *tso,
+ StgClosure *exception);
+
++void throwToSingleThreadedNoDequeue (Capability *cap,
++ StgTSO *tso,
++ StgClosure *exception);
++
+ void throwToSingleThreaded_ (Capability *cap,
+ StgTSO *tso,
+ StgClosure *exception,
+diff --git a/rts/posix/Select.c b/rts/posix/Select.c
+index 4b19235..6889499 100644
+--- a/rts/posix/Select.c
++++ b/rts/posix/Select.c
+@@ -412,8 +412,12 @@ awaitEvent(rtsBool wait)
+ IF_DEBUG(scheduler,
+ debugBelch("Killing blocked thread %lu on bad fd=%i\n",
+ (unsigned long)tso->id, fd));
+- throwToSingleThreaded(&MainCapability, tso,
+- (StgClosure *)blockedOnBadFD_closure);
++ /*
++ * We can't use throwToSingleThreaded() here
++ * as 'RTS_FD_IS_READY' breaks blocked_queue_hd list
++ */
++ throwToSingleThreadedNoDequeue(&MainCapability, tso,
++ (StgClosure *)blockedOnBadFD_closure);
+ break;
+ case RTS_FD_IS_READY:
+ IF_DEBUG(scheduler,
diff --git a/dev-lang/ghc/files/ghc-7.10.1-rc3-ghc-7.10-bootstrap.patch b/dev-lang/ghc/files/ghc-7.10.1-rc3-ghc-7.10-bootstrap.patch
new file mode 100644
index 000000000000..60db34b8b362
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.10.1-rc3-ghc-7.10-bootstrap.patch
@@ -0,0 +1,78 @@
+--- ghc-7.10.0.20150316-orig/compiler/utils/Pair.hs 2015-03-10 05:43:13.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/utils/Pair.hs 2015-03-17 09:50:48.491115080 +1100
+@@ -15,6 +15,8 @@
+ import Data.Foldable
+ import Data.Monoid
+ import Data.Traversable
++#else
++import Control.Applicative ((<$>))
+ #endif
+
+ data Pair a = Pair { pFst :: a, pSnd :: a }
+--- ghc-7.10.0.20150316-orig/compiler/types/Coercion.hs 2015-03-10 05:43:13.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/types/Coercion.hs 2015-03-17 10:11:21.636047380 +1100
+@@ -104,6 +104,8 @@
+ #if __GLASGOW_HASKELL__ < 709
+ import Control.Applicative hiding ( empty )
+ import Data.Traversable (traverse, sequenceA)
++#else
++import Control.Applicative ((<$>))
+ #endif
+ import FastString
+ import ListSetOps
+--- ghc-7.10.0.20150316-orig/compiler/typecheck/TcEvidence.hs 2015-03-14 08:48:57.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/typecheck/TcEvidence.hs 2015-03-17 10:26:03.251433371 +1100
+@@ -50,6 +50,8 @@
+ #if __GLASGOW_HASKELL__ < 709
+ import Control.Applicative
+ import Data.Traversable (traverse, sequenceA)
++#else
++import Control.Applicative ((<$>))
+ #endif
+ import qualified Data.Data as Data
+ import Outputable
+--- ghc-7.10.0.20150316-orig/compiler/hsSyn/HsBinds.hs 2015-03-10 05:43:13.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/hsSyn/HsBinds.hs 2015-03-17 10:42:21.459519033 +1100
+@@ -47,6 +47,8 @@
+ import Data.Traversable ( Traversable(..) )
+ import Data.Monoid ( mappend )
+ import Control.Applicative hiding (empty)
++#else
++import Control.Applicative ((<$>))
+ #endif
+
+ {-
+--- ghc-7.10.0.20150316-orig/compiler/parser/RdrHsSyn.hs 2015-03-10 05:43:13.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/parser/RdrHsSyn.hs 2015-03-17 11:17:48.950929542 +1100
+@@ -91,9 +91,7 @@
+ import Util
+ import ApiAnnotation
+
+-#if __GLASGOW_HASKELL__ < 709
+ import Control.Applicative ((<$>))
+-#endif
+ import Control.Monad
+
+ import Text.ParserCombinators.ReadP as ReadP
+--- ghc-7.10.0.20150316-orig/compiler/typecheck/TcGenDeriv.hs 2015-03-14 08:48:57.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/typecheck/TcGenDeriv.hs 2015-03-17 11:30:39.106508173 +1100
+@@ -59,6 +59,8 @@
+ import Var
+ #if __GLASGOW_HASKELL__ < 709
+ import MonadUtils
++#else
++import Control.Applicative ((<$>))
+ #endif
+ import Outputable
+ import Lexeme
+--- ghc-7.10.0.20150316-orig/compiler/vectorise/Vectorise/Exp.hs 2015-03-10 05:43:13.000000000 +1100
++++ ghc-7.10.0.20150316/compiler/vectorise/Vectorise/Exp.hs 2015-03-17 11:46:41.829481669 +1100
+@@ -46,6 +46,8 @@
+ import Util
+ #if __GLASGOW_HASKELL__ < 709
+ import MonadUtils
++#else
++import Control.Applicative ((<$>))
+ #endif
+
+ import Control.Monad
diff --git a/dev-lang/ghc/files/ghc-7.2.1-freebsd-CHOST.patch b/dev-lang/ghc/files/ghc-7.2.1-freebsd-CHOST.patch
new file mode 100644
index 000000000000..da59cd789f99
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.2.1-freebsd-CHOST.patch
@@ -0,0 +1,13 @@
+diff --git a/aclocal.m4 b/aclocal.m4
+index 11bb003..52df243 100644
+--- a/aclocal.m4
++++ b/aclocal.m4
+@@ -1545,7 +1545,7 @@ case "$1" in
+ freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
+ $2="$1"
+ ;;
+- freebsd8) # like i686-gentoo-freebsd8
++ freebsd*) # like i686-gentoo-freebsd8 or i686-gentoo-freebsd8.2
+ $2="freebsd"
+ ;;
+ darwin*)
diff --git a/dev-lang/ghc/files/ghc-7.4-rc2-macos-prefix-respect-gcc.patch b/dev-lang/ghc/files/ghc-7.4-rc2-macos-prefix-respect-gcc.patch
new file mode 100644
index 000000000000..770fd650606b
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.4-rc2-macos-prefix-respect-gcc.patch
@@ -0,0 +1,23 @@
+diff --git a/aclocal.m4 b/aclocal.m4
+index a377cb9..4f8fd69 100644
+--- a/aclocal.m4
++++ b/aclocal.m4
+@@ -1950,17 +1950,7 @@ AC_DEFUN([XCODE_VERSION],[
+ # --------------------------------
+ # Finds where gcc is
+ AC_DEFUN([FIND_GCC],[
+- if test "$TargetOS_CPP" = "darwin" &&
+- test "$XCodeVersion1" -eq 4 &&
+- test "$XCodeVersion2" -lt 2
+- then
+- # In Xcode 4.1, 'gcc-4.2' is the gcc legacy backend (rather
+- # than the LLVM backend). We prefer the legacy gcc, but in
+- # Xcode 4.2 'gcc-4.2' was removed.
+- FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc-4.2])
+- else
+- FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
+- fi
++ FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
+ export CC
+ WhatGccIsCalled="$CC"
+ AC_SUBST(WhatGccIsCalled)
diff --git a/dev-lang/ghc/files/ghc-7.4.1-darwin-CHOST.patch b/dev-lang/ghc/files/ghc-7.4.1-darwin-CHOST.patch
new file mode 100644
index 000000000000..348158882aaf
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.4.1-darwin-CHOST.patch
@@ -0,0 +1,18 @@
+like the other CHOST patches, but this one catches another case where
+$host is used (instead of the cannonicalised variables)
+
+--- aclocal.m4
++++ aclocal.m4
+@@ -93,10 +93,10 @@
+ exeext='.exe'
+ soext='.dll'
+ ;;
+- i386-apple-darwin|powerpc-apple-darwin)
++ i386-apple-darwin*|powerpc-apple-darwin*)
+ soext='.dylib'
+ ;;
+- x86_64-apple-darwin)
++ x86_64-apple-darwin*)
+ soext='.dylib'
+ ;;
+ esac
diff --git a/dev-lang/ghc/files/ghc-7.4.1-ticket-7339-fix-unaligned-unreg.patch b/dev-lang/ghc/files/ghc-7.4.1-ticket-7339-fix-unaligned-unreg.patch
new file mode 100644
index 000000000000..f2f19f1bbab4
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.4.1-ticket-7339-fix-unaligned-unreg.patch
@@ -0,0 +1,28 @@
+From 26f8466507bd9383e0a7d1e62e397eca4a13822a Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Tue, 13 Nov 2012 01:39:14 +0300
+Subject: [PATCH] Fix unaligned access on alpha and friends (ticket #7339)
+
+Assume unknown arch (alpha and mips) an alignment sensitive target.
+Otherwise on alpha it causes ghc-7.4.1 to generate invalud lexers.
+
+Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+---
+ compiler/cmm/PprC.hs | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
+index 21826f8..8cdcde6 100644
+--- a/compiler/cmm/PprC.hs
++++ b/compiler/cmm/PprC.hs
+@@ -963,6 +963,7 @@ cLoad platform expr rep
+ | otherwise
+ = char '*' <> parens (cCast platform (machRepPtrCType rep) expr)
+ where -- On these platforms, unaligned loads are known to cause problems
++ bewareLoadStoreAlignment ArchUnknown = True -- like alpha or mips
+ bewareLoadStoreAlignment (ArchARM {}) = True
+ bewareLoadStoreAlignment _ = False
+
+--
+1.8.0
+
diff --git a/dev-lang/ghc/files/ghc-7.4.2-system-libffi.patch b/dev-lang/ghc/files/ghc-7.4.2-system-libffi.patch
new file mode 100644
index 000000000000..73c4aa278dd8
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.4.2-system-libffi.patch
@@ -0,0 +1,119 @@
+Make ghc use the libffi installed on the system instead of the bundled one.
+
+This patch is based on the one used by Debian and Fedora, but was
+augmented by additional lines to identify the libffi include directory
+using pkg-config, as libffi on Gentoo installs into a subdirectory of
+the system include directory.
+
+2012-04-24 Martin von Gagern
+
+References:
+https://bugs.gentoo.org/411925
+http://hackage.haskell.org/trac/ghc/ticket/5743
+
+Index: ghc-7.4.1/ghc.mk
+===================================================================
+--- ghc-7.4.1.orig/ghc.mk
++++ ghc-7.4.1/ghc.mk
+@@ -579,7 +579,6 @@ BUILD_DIRS += \
+ driver/ghci \
+ driver/ghc \
+ driver/haddock \
+- libffi \
+ includes \
+ rts
+
+Index: ghc-7.4.1/rts/ghc.mk
+===================================================================
+--- ghc-7.4.1.orig/rts/ghc.mk
++++ ghc-7.4.1/rts/ghc.mk
+@@ -86,8 +86,7 @@
+ ALL_RTS_DEF_LIBNAMES = base ghc-prim
+ ALL_RTS_DEF_LIBS = \
+ rts/dist/build/win32/libHSbase.dll.a \
+- rts/dist/build/win32/libHSghc-prim.dll.a \
+- libffi/build/inst/lib/libffi.dll.a
++ rts/dist/build/win32/libHSghc-prim.dll.a
+
+ # -- import libs for the regular Haskell libraries
+ define make-importlib-def # args $1 = lib name
+@@ -172,12 +171,12 @@
+ # Making a shared library for the RTS.
+ ifneq "$$(findstring dyn, $1)" ""
+ ifeq "$$(HOSTPLATFORM)" "i386-unknown-mingw32"
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/build/libffi-5.dll
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
+ "$$(RM)" $$(RM_OPTS) $$@
+ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
+ -no-auto-link-packages -Lrts/dist/build -lffi-5 `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
+ else
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend rts/dist/build/libffi$$(soext)
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend
+ "$$(RM)" $$(RM_OPTS) $$@
+ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
+ -no-auto-link-packages -Lrts/dist/build -lffi `cat rts/libs.depend` $$(rts_$1_OBJS) \
+@@ -188,9 +187,9 @@
+ endif
+ endif
+ else
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_ffi_objs_stamp)
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
+ "$$(RM)" $$(RM_OPTS) $$@
+- echo $$(rts_ffi_objs) $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
++ echo $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
+ $$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
+ endif
+
+@@ -403,6 +402,12 @@
+ rts/dist/build/sm/Evac_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
+ rts/dist/build/sm/Scav_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
+
++# Use system libffi
++libffi_include_flags:=$(shell pkg-config --cflags-only-I libffi)
++rts/Adjustor_CC_OPTS += $(libffi_include_flags)
++rts/Interpreter_CC_OPTS += $(libffi_include_flags)
++rts/sm/Storage_CC_OPTS += $(libffi_include_flags)
++
+ #-----------------------------------------------------------------------------
+ # Add PAPI library if needed
+
+@@ -504,10 +509,8 @@
+ # installing
+
+ INSTALL_LIBS += $(ALL_RTS_LIBS)
+-INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
+-INSTALL_LIBS += $(wildcard rts/dist/build/libffi-5.dll)
+
+-install: install_libffi_headers
++install:
+
+ .PHONY: install_libffi_headers
+ install_libffi_headers :
+Index: ghc-7.4.1/rts/package.conf.in
+===================================================================
+--- ghc-7.4.1.orig/rts/package.conf.in
++++ ghc-7.4.1/rts/package.conf.in
+@@ -24,8 +24,9 @@
+ hs-libraries: "HSrts"
+
+ extra-libraries:
++ "ffi"
+ #ifdef HAVE_LIBM
+- "m" /* for ldexp() */
++ , "m" /* for ldexp() */
+ #endif
+ #ifdef HAVE_LIBRT
+ , "rt"
+Index: ghc-7.4.1/compiler/ghc.mk
+===================================================================
+--- ghc-7.4.1.orig/compiler/ghc.mk
++++ ghc-7.4.1/compiler/ghc.mk
+@@ -260,6 +260,8 @@
+
+ compiler_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
+ compiler_CPP_OPTS += ${GhcCppOpts}
++libffi_include_flags := $(shell pkg-config --cflags-only-I libffi)
++compiler/ghci/LibFFI_HSC2HS_OPTS += $(addprefix --cflag=,$(libffi_include_flags))
+
+ $(PRIMOPS_TXT) compiler/parser/Parser.y: %: %.pp compiler/stage1/$(PLATFORM_H)
+ $(CPP) $(RAWCPP_FLAGS) -P $(compiler_CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
diff --git a/dev-lang/ghc/files/ghc-7.5.20120505-system-libffi.patch b/dev-lang/ghc/files/ghc-7.5.20120505-system-libffi.patch
new file mode 100644
index 000000000000..f3b0c71c5454
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.5.20120505-system-libffi.patch
@@ -0,0 +1,88 @@
+--- ghc-7.5.20120505-orig/ghc.mk 2012-05-06 03:01:29.000000000 +1000
++++ ghc-7.5.20120505/ghc.mk 2012-05-06 17:22:01.023416003 +1000
+@@ -584,7 +584,6 @@
+ $(MAYBE_GHCI) \
+ driver/ghc \
+ driver/haddock \
+- libffi \
+ includes \
+ rts
+
+--- ghc-7.5.20120505-orig/rts/ghc.mk 2012-05-06 03:01:30.000000000 +1000
++++ ghc-7.5.20120505/rts/ghc.mk 2012-05-06 17:28:31.925897226 +1000
+@@ -171,12 +171,12 @@
+ # Making a shared library for the RTS.
+ ifneq "$$(findstring dyn, $1)" ""
+ ifeq "$$(HostOS_CPP)" "mingw32"
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/build/$$(LIBFFI_DLL)
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
+ "$$(RM)" $$(RM_OPTS) $$@
+ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
+ -no-auto-link-packages -Lrts/dist/build -l$(LIBFFI_WINDOWS_LIB) `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
+ else
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend rts/dist/build/libffi$$(soext)
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend
+ "$$(RM)" $$(RM_OPTS) $$@
+ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
+ -no-auto-link-packages -Lrts/dist/build -lffi `cat rts/libs.depend` $$(rts_$1_OBJS) \
+@@ -187,9 +187,9 @@
+ endif
+ endif
+ else
+-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_ffi_objs_stamp)
++$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
+ "$$(RM)" $$(RM_OPTS) $$@
+- echo $$(rts_ffi_objs) $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
++ echo $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
+ $$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
+ endif
+
+@@ -407,6 +407,12 @@
+ rts/dist/build/sm/Evac_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
+ rts/dist/build/sm/Scav_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
+
++# Use system libffi
++libffi_include_flags:=$(shell pkg-config --cflags-only-I libffi)
++rts/Adjustor_CC_OPTS += $(libffi_include_flags)
++rts/Interpreter_CC_OPTS += $(libffi_include_flags)
++rts/sm/Storage_CC_OPTS += $(libffi_include_flags)
++
+ #-----------------------------------------------------------------------------
+ # Add PAPI library if needed
+
+@@ -508,10 +514,8 @@
+ # installing
+
+ INSTALL_LIBS += $(ALL_RTS_LIBS)
+-INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
+-INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL))
+
+-install: install_libffi_headers
++install:
+
+ .PHONY: install_libffi_headers
+ install_libffi_headers :
+--- ghc-7.5.20120505-orig/rts/package.conf.in 2012-05-06 03:01:30.000000000 +1000
++++ ghc-7.5.20120505/rts/package.conf.in 2012-05-06 17:22:01.025416056 +1000
+@@ -24,8 +24,9 @@
+ hs-libraries: "HSrts"
+
+ extra-libraries:
++ "ffi"
+ #ifdef HAVE_LIBM
+- "m" /* for ldexp() */
++ , "m" /* for ldexp() */
+ #endif
+ #ifdef HAVE_LIBRT
+ , "rt"
+--- ghc-7.5.20120505-orig/compiler/ghc.mk 2012-05-06 03:01:29.000000000 +1000
++++ ghc-7.5.20120505/compiler/ghc.mk 2012-05-06 17:22:01.026416083 +1000
+@@ -260,6 +260,8 @@
+
+ compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
+ compiler_CPP_OPTS += ${GhcCppOpts}
++libffi_include_flags := $(shell pkg-config --cflags-only-I libffi)
++compiler/ghci/LibFFI_HSC2HS_OPTS += $(addprefix --cflag=,$(libffi_include_flags))
+
+ $(PRIMOPS_TXT) compiler/parser/Parser.y: %: %.pp compiler/stage1/$(PLATFORM_H)
+ $(CPP) $(RAWCPP_FLAGS) -P $(compiler_CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
diff --git a/dev-lang/ghc/files/ghc-7.6.2-integer-simple-div-mod.patch b/dev-lang/ghc/files/ghc-7.6.2-integer-simple-div-mod.patch
new file mode 100644
index 000000000000..0dc5391678f2
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.6.2-integer-simple-div-mod.patch
@@ -0,0 +1,57 @@
+commit de13417726b90b0945aaaf0b9cfbaf8ab975d8b5
+Author: Gabor Greif <ggreif@gmail.com>
+Date: Tue Jul 24 14:31:36 2012 +0200
+
+ track integer-gmp and add 'divInteger', 'modInteger'
+
+diff --git a/libraries/integer-simple/GHC/Integer.hs b/libraries/integer-simple/GHC/Integer.hs
+index c9b50a7..4122d38 100644
+--- a/libraries/integer-simple/GHC/Integer.hs
++++ b/libraries/integer-simple/GHC/Integer.hs
+@@ -4,7 +4,7 @@
+ -----------------------------------------------------------------------------
+ -- |
+ -- Module : GHC.Integer
+--- Copyright : (c) Ian Lynagh 2007-2008
++-- Copyright : (c) Ian Lynagh 2007-2012
+ -- License : BSD3
+ --
+ -- Maintainer : igloo@earth.li
+@@ -27,6 +27,7 @@ module GHC.Integer (
+ plusInteger, minusInteger, timesInteger, negateInteger,
+ eqInteger, neqInteger, absInteger, signumInteger,
+ leInteger, gtInteger, ltInteger, geInteger, compareInteger,
++ divInteger, modInteger,
+ divModInteger, quotRemInteger, quotInteger, remInteger,
+ encodeFloatInteger, decodeFloatInteger, floatFromInteger,
+ encodeDoubleInteger, decodeDoubleInteger, doubleFromInteger,
+diff --git a/libraries/integer-simple/GHC/Integer/Type.hs b/libraries/integer-simple/GHC/Integer/Type.hs
+index c3d812c..67ed19c 100644
+--- a/libraries/integer-simple/GHC/Integer/Type.hs
++++ b/libraries/integer-simple/GHC/Integer/Type.hs
+@@ -7,7 +7,7 @@
+ -----------------------------------------------------------------------------
+ -- |
+ -- Module : GHC.Integer.Type
+--- Copyright : (c) Ian Lynagh 2007-2008
++-- Copyright : (c) Ian Lynagh 2007-2012
+ -- License : BSD3
+ --
+ -- Maintainer : igloo@earth.li
+@@ -370,6 +370,16 @@ n `divModInteger` d =
+ then (# q `minusInteger` oneInteger, r `plusInteger` d #)
+ else (# q, r #)
+
++{-# NOINLINE divInteger #-}
++divInteger :: Integer -> Integer -> Integer
++n `divInteger` d = quotient
++ where (# quotient, _ #) = n `divModInteger` d
++
++{-# NOINLINE modInteger #-}
++modInteger :: Integer -> Integer -> Integer
++n `modInteger` d = modulus
++ where (# _, modulus #) = n `divModInteger` d
++
+ {-# NOINLINE quotRemInteger #-}
+ quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
+ Naught `quotRemInteger` (!_) = (# Naught, Naught #)
diff --git a/dev-lang/ghc/files/ghc-7.6.3-preserve-inplace-xattr.patch b/dev-lang/ghc/files/ghc-7.6.3-preserve-inplace-xattr.patch
new file mode 100644
index 000000000000..08410fa0cd9b
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.6.3-preserve-inplace-xattr.patch
@@ -0,0 +1,14 @@
+On hardened 'cp' drops out XT-pax parking.
+perfinion suggested using 'install', where portage
+might have a chance to save our marking.
+
+Reported-by: Jay Yang
+Gentoo-bug: https://bugs.gentoo.org/518734
+diff --git a/rules/build-prog.mk b/rules/build-prog.mk
+index 399369e..2ee9cd5 100644
+--- a/rules/build-prog.mk
++++ b/rules/build-prog.mk
+@@ -288,3 +288,3 @@ endif
+ $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG_INPLACE) | $$$$(dir $$$$@)/.
+- "$$(CP)" -p $$< $$@
++ $$(INSTALL) -m 755 $$< $$@
diff --git a/dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch b/dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch
new file mode 100644
index 000000000000..c3184a68c1e7
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch
@@ -0,0 +1,387 @@
+The patch set adds support for weak symbols to ghci.
+
+For gentoo it fixes nonworking ghci / template haskell
+for package base.
+
+Steps to reproduce:
+ 1. CFLAGS=-Os emerge ghc
+ 2. ghci -package base
+ Loading package base ... linking ... ghc: /usr/lib64/ghc-7.6.3/base-4.6.0.1/HSbase-4.6.0.1.o: unknown symbol `stat'
+
+When built with -O2 weak 'stat' resolved to '__xstat' and we don't see any errors.
+But on olwer optimization levels 'stat' remains.
+
+Patches-by: akio
+Gentoo-bug: http://bugs.gentoo.org/452442
+Upstream-bug: http://ghc.haskell.org/trac/ghc/ticket/3333
+
+From 500d57d3a18412c78cab5abc4d91f1564edc964d Mon Sep 17 00:00:00 2001
+From: Takano Akio <aljee@hyper.cx>
+Date: Sat, 29 Dec 2012 11:47:22 +0900
+Subject: [PATCH 1/3] Linker.c: remove stablehash, which is no longer used
+
+---
+ includes/rts/Linker.h | 3 ---
+ rts/Linker.c | 31 ++-----------------------------
+ 2 files changed, 2 insertions(+), 32 deletions(-)
+
+diff --git a/includes/rts/Linker.h b/includes/rts/Linker.h
+index e900e85..d20ebc2 100644
+--- a/includes/rts/Linker.h
++++ b/includes/rts/Linker.h
+@@ -23,9 +23,6 @@ typedef char pathchar;
+ /* initialize the object linker */
+ void initLinker( void );
+
+-/* insert a stable symbol in the hash table */
+-void insertStableSymbol(pathchar* obj_name, char* key, StgPtr data);
+-
+ /* insert a symbol in the hash table */
+ void insertSymbol(pathchar* obj_name, char* key, void* data);
+
+diff --git a/rts/Linker.c b/rts/Linker.c
+index fa1de89..513fe3f 100644
+--- a/rts/Linker.c
++++ b/rts/Linker.c
+@@ -30,1 +30,0 @@
+-#include "Stable.h"
+@@ -150,9 +149,6 @@ int dynamicByDefault = 0;
+ /* Hash table mapping symbol names to Symbol */
+ static /*Str*/HashTable *symhash;
+
+-/* Hash table mapping symbol names to StgStablePtr */
+-static /*Str*/HashTable *stablehash;
+-
+ /* List of currently loaded objects */
+ ObjectCode *objects = NULL; /* initially empty */
+
+@@ -1126,1 +1126,0 @@ typedef struct _RtsSymbolVal {
+- SymI_HasProto(insertStableSymbol) \
+@@ -1488,7 +1483,6 @@ initLinker( void )
+ #if defined(THREADED_RTS) && (defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO))
+ initMutex(&dl_mutex);
+ #endif
+- stablehash = allocStrHashTable();
+ symhash = allocStrHashTable();
+
+ /* populate the symbol table with stuff from the RTS */
+@@ -1817,17 +1811,6 @@ error:
+ }
+
+ /* -----------------------------------------------------------------------------
+- * insert a stable symbol in the hash table
+- */
+-
+-void
+-insertStableSymbol(pathchar* obj_name, char* key, StgPtr p)
+-{
+- ghciInsertStrHashTable(obj_name, stablehash, key, getStablePtr(p));
+-}
+-
+-
+-/* -----------------------------------------------------------------------------
+ * insert a symbol in the hash table
+ */
+ void
+@@ -4749,8 +4732,6 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
+ #ifdef i386_HOST_ARCH
+ Elf_Addr value;
+ #endif
+- StgStablePtr stablePtr;
+- StgPtr stableVal;
+ #ifdef arm_HOST_ARCH
+ int is_target_thm=0, T=0;
+ #endif
+@@ -4773,16 +4754,8 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
+
+ } else {
+ symbol = strtab + sym.st_name;
+- stablePtr = (StgStablePtr)lookupHashTable(stablehash, (StgWord)symbol);
+- if (NULL == stablePtr) {
+- /* No, so look up the name in our global table. */
+- S_tmp = lookupSymbol( symbol );
+- S = (Elf_Addr)S_tmp;
+- } else {
+- stableVal = deRefStablePtr( stablePtr );
+- S_tmp = stableVal;
+- S = (Elf_Addr)S_tmp;
+- }
++ S_tmp = lookupSymbol( symbol );
++ S = (Elf_Addr)S_tmp;
+ }
+ if (!S) {
+ errorBelch("%s: unknown symbol `%s'", oc->fileName, symbol);
+--
+1.7.9.5
+
+From 2e5e0f7a90dd390adc5ae5fb2a3bc6e879aa42d6 Mon Sep 17 00:00:00 2001
+From: Takano Akio <aljee@hyper.cx>
+Date: Sat, 29 Dec 2012 11:59:34 +0900
+Subject: [PATCH 2/3] ghci: add support for ELF weak symbols
+
+---
+ rts/Linker.c | 102 ++++++++++++++++++++++++++++++++++++++++++++--------------
+ 1 file changed, 78 insertions(+), 24 deletions(-)
+
+diff --git a/rts/Linker.c b/rts/Linker.c
+index 513fe3f..5105085 100644
+--- a/rts/Linker.c
++++ b/rts/Linker.c
+@@ -146,7 +146,13 @@ int dynamicByDefault = 1;
+ int dynamicByDefault = 0;
+ #endif
+
+-/* Hash table mapping symbol names to Symbol */
++typedef struct _RtsSymbolInfo {
++ void *value;
++ const ObjectCode *owner;
++ HsBool weak;
++} RtsSymbolInfo;
++
++/* Hash table mapping symbol names to RtsSymbolInfo */
+ static /*Str*/HashTable *symhash;
+
+ /* List of currently loaded objects */
+@@ -1415,15 +1421,31 @@ static RtsSymbolVal rtsSyms[] = {
+ * Insert symbols into hash tables, checking for duplicates.
+ */
+
+-static void ghciInsertStrHashTable ( pathchar* obj_name,
+- HashTable *table,
+- char* key,
+- void *data
+- )
++static void ghciInsertSymbolTable(
++ pathchar* obj_name,
++ HashTable *table,
++ char* key,
++ void *data,
++ HsBool weak,
++ ObjectCode *owner)
+ {
+- if (lookupHashTable(table, (StgWord)key) == NULL)
++ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key);
++ if (!pinfo) /* new entry */
++ {
++ pinfo = stgMallocBytes(sizeof (*pinfo), "ghciInsertToSymbolTable");
++ pinfo->value = data;
++ pinfo->owner = owner;
++ pinfo->weak = weak;
++ insertStrHashTable(table, key, pinfo);
++ return;
++ } else if ((!pinfo->weak || pinfo->value) && weak) {
++ return; /* duplicate weak symbol, throw it away */
++ } else if (pinfo->weak) /* weak symbol is in the table */
+ {
+- insertStrHashTable(table, (StgWord)key, data);
++ /* override the weak definition with the non-weak one */
++ pinfo->value = data;
++ pinfo->owner = owner;
++ pinfo->weak = HS_BOOL_FALSE;
+ return;
+ }
+ debugBelch(
+@@ -1444,6 +1466,32 @@ static void ghciInsertStrHashTable ( pathchar* obj_name,
+ );
+ stg_exit(1);
+ }
++
++static HsBool ghciLookupSymbolTable(HashTable *table,
++ const char *key, void **result)
++{
++ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key);
++ if (!pinfo) {
++ *result = NULL;
++ return HS_BOOL_FALSE;
++ }
++ if (pinfo->weak)
++ IF_DEBUG(linker, debugBelch("lookup: promoting %s\n", key));
++ /* Once it's looked up, it can no longer be overridden */
++ pinfo->weak = HS_BOOL_FALSE;
++
++ *result = pinfo->value;
++ return HS_BOOL_TRUE;
++}
++
++static void ghciRemoveSymbolTable(HashTable *table, const char *key,
++ ObjectCode *owner)
++{
++ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key);
++ if (!pinfo || owner != pinfo->owner) return;
++ removeStrHashTable(table, key, NULL);
++ stgFree(pinfo);
++}
+ /* -----------------------------------------------------------------------------
+ * initialize the object linker
+ */
+@@ -1487,8 +1535,8 @@ initLinker( void )
+
+ /* populate the symbol table with stuff from the RTS */
+ for (sym = rtsSyms; sym->lbl != NULL; sym++) {
+- ghciInsertStrHashTable(WSTR("(GHCi built-in symbols)"),
+- symhash, sym->lbl, sym->addr);
++ ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
++ symhash, sym->lbl, sym->addr, HS_BOOL_FALSE, NULL);
+ IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
+ }
+ # if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH)
+@@ -1816,7 +1864,7 @@ error:
+ void
+ insertSymbol(pathchar* obj_name, char* key, void* data)
+ {
+- ghciInsertStrHashTable(obj_name, symhash, key, data);
++ ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE, NULL);
+ }
+
+ /* -----------------------------------------------------------------------------
+@@ -1829,9 +1877,8 @@ lookupSymbol( char *lbl )
+ IF_DEBUG(linker, debugBelch("lookupSymbol: looking up %s\n", lbl));
+ initLinker() ;
+ ASSERT(symhash != NULL);
+- val = lookupStrHashTable(symhash, lbl);
+
+- if (val == NULL) {
++ if (!ghciLookupSymbolTable(symhash, lbl, &val)) {
+ IF_DEBUG(linker, debugBelch("lookupSymbol: symbol not found\n"));
+ # if defined(OBJFORMAT_ELF)
+ return internal_dlsym(dl_prog_handle, lbl);
+@@ -1903,7 +1950,7 @@ void ghci_enquire ( char* addr )
+ if (sym == NULL) continue;
+ a = NULL;
+ if (a == NULL) {
+- a = lookupStrHashTable(symhash, sym);
++ ghciLookupSymbolTable(symhash, sym, (void **)&a);
+ }
+ if (a == NULL) {
+ // debugBelch("ghci_enquire: can't find %s\n", sym);
+@@ -2715,7 +2762,7 @@ unloadObj( pathchar *path )
+ int i;
+ for (i = 0; i < oc->n_symbols; i++) {
+ if (oc->symbols[i] != NULL) {
+- removeStrHashTable(symhash, oc->symbols[i], NULL);
++ ghciRemoveSymbolTable(symhash, oc->symbols[i], oc);
+ }
+ }
+ }
+@@ -3802,7 +3849,8 @@ ocGetNames_PEi386 ( ObjectCode* oc )
+ ASSERT(i >= 0 && i < oc->n_symbols);
+ /* cstring_from_COFF_symbol_name always succeeds. */
+ oc->symbols[i] = (char*)sname;
+- ghciInsertStrHashTable(oc->fileName, symhash, (char*)sname, addr);
++ ghciInsertSymbolTable(oc->fileName, symhash, (char*)sname, addr,
++ HS_BOOL_FALSE, oc);
+ } else {
+ # if 0
+ debugBelch(
+@@ -4595,6 +4643,7 @@ ocGetNames_ELF ( ObjectCode* oc )
+ for (j = 0; j < nent; j++) {
+
+ char isLocal = FALSE; /* avoids uninit-var warning */
++ HsBool isWeak = HS_BOOL_FALSE;
+ char* ad = NULL;
+ char* nm = strtab + stab[j].st_name;
+ int secno = stab[j].st_shndx;
+@@ -4615,6 +4664,7 @@ ocGetNames_ELF ( ObjectCode* oc )
+ else
+ if ( ( ELF_ST_BIND(stab[j].st_info)==STB_GLOBAL
+ || ELF_ST_BIND(stab[j].st_info)==STB_LOCAL
++ || ELF_ST_BIND(stab[j].st_info)==STB_WEAK
+ )
+ /* and not an undefined symbol */
+ && stab[j].st_shndx != SHN_UNDEF
+@@ -4638,7 +4688,8 @@ ocGetNames_ELF ( ObjectCode* oc )
+ ad = ehdrC + shdr[ secno ].sh_offset + stab[j].st_value;
+ if (ELF_ST_BIND(stab[j].st_info)==STB_LOCAL) {
+ isLocal = TRUE;
+- } else {
++ isWeak = FALSE;
++ } else { /* STB_GLOBAL or STB_WEAK */
+ #ifdef ELF_FUNCTION_DESC
+ /* dlsym() and the initialisation table both give us function
+ * descriptors, so to be consistent we store function descriptors
+@@ -4649,6 +4700,7 @@ ocGetNames_ELF ( ObjectCode* oc )
+ IF_DEBUG(linker,debugBelch( "addOTabName(GLOB): %10p %s %s\n",
+ ad, oc->fileName, nm ));
+ isLocal = FALSE;
++ isWeak = (ELF_ST_BIND(stab[j].st_info)==STB_WEAK);
+ }
+ }
+
+@@ -4661,7 +4713,7 @@ ocGetNames_ELF ( ObjectCode* oc )
+ if (isLocal) {
+ /* Ignore entirely. */
+ } else {
+- ghciInsertStrHashTable(oc->fileName, symhash, nm, ad);
++ ghciInsertSymbolTable(oc->fileName, symhash, nm, ad, isWeak, oc);
+ }
+ } else {
+ /* Skip. */
+@@ -6306,11 +6358,13 @@ ocGetNames_MachO(ObjectCode* oc)
+ else
+ {
+ IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting %s\n", nm));
+- ghciInsertStrHashTable(oc->fileName, symhash, nm,
++ ghciInsertSymbolTable(oc->fileName, symhash, nm,
+ image
+ + sections[nlist[i].n_sect-1].offset
+ - sections[nlist[i].n_sect-1].addr
+- + nlist[i].n_value);
++ + nlist[i].n_value,
++ HS_BOOL_FALSE,
++ oc);
+ oc->symbols[curSymbol++] = nm;
+ }
+ }
+@@ -6341,8 +6395,8 @@ ocGetNames_MachO(ObjectCode* oc)
+ nlist[i].n_value = commonCounter;
+
+ IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm));
+- ghciInsertStrHashTable(oc->fileName, symhash, nm,
+- (void*)commonCounter);
++ ghciInsertSymbolTable(oc->fileName, symhash, nm,
++ (void*)commonCounter, HS_BOOL_FALSE, oc);
+ oc->symbols[curSymbol++] = nm;
+
+ commonCounter += sz;
+@@ -6466,7 +6520,7 @@ machoInitSymbolsWithoutUnderscore(void)
+
+ #undef SymI_NeedsProto
+ #define SymI_NeedsProto(x) \
+- ghciInsertStrHashTable("(GHCi built-in symbols)", symhash, #x, *p++);
++ ghciInsertSymbolTable("(GHCi built-in symbols)", symhash, #x, *p++, HS_BOOL_FALSE, NULL);
+
+ RTS_MACHO_NOUNDERLINE_SYMBOLS
+
+--
+1.7.9.5
+
+From 916d7713b34b529ae7ec24eaa836a4eaca7724fc Mon Sep 17 00:00:00 2001
+From: Takano Akio <aljee@hyper.cx>
+Date: Sun, 6 Jan 2013 17:51:19 +0900
+Subject: [PATCH 3/3] Linker.c: add dso_handle to the symbol table
+
+---
+ rts/Linker.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/rts/Linker.c b/rts/Linker.c
+index 5105085..0b2bf63 100644
+--- a/rts/Linker.c
++++ b/rts/Linker.c
+@@ -1542,6 +1542,13 @@ initLinker( void )
+ # if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH)
+ machoInitSymbolsWithoutUnderscore();
+ # endif
++ /* GCC defines a special symbol __dso_handle which is resolved to NULL if
++ referenced from a statically linked module. We need to mimic this, but
++ we cannot use NULL because we use it to mean nonexistent symbols. So we
++ use an arbitrary (hopefully unique) address here.
++ */
++ ghciInsertSymbolTable(WSTR("(GHCi special symbols)"),
++ symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL);
+
+ # if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)
+ # if defined(RTLD_DEFAULT)
+--
+1.7.9.5
+
diff --git a/dev-lang/ghc/files/ghc-7.8.1_rc1-libbfd.patch b/dev-lang/ghc/files/ghc-7.8.1_rc1-libbfd.patch
new file mode 100644
index 000000000000..d01cb49affbd
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.1_rc1-libbfd.patch
@@ -0,0 +1,81 @@
+commit bb5953484579968c984d074ca1af5d21e1c9e7a0
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Mon Feb 10 12:45:58 2014 +0300
+
+ rts: unrust 'libbfd' debug symbols parser
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/configure.ac b/configure.ac
+index e7fbc7f..e47979c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -801,7 +801,8 @@ fi
+ dnl ** check whether this machine has BFD and libiberty installed (used for debugging)
+ dnl the order of these tests matters: bfd needs libiberty
+ AC_CHECK_LIB(iberty, xmalloc)
+-AC_CHECK_LIB(bfd, bfd_uncompress_section_contents)
++dnl 'bfd_init' is a rare non-macro in libbfd
++AC_CHECK_LIB(bfd, bfd_init)
+
+ dnl ################################################################
+ dnl Check for libraries
+diff --git a/rts/Printer.c b/rts/Printer.c
+index ca9ca49..ce02b02 100644
+--- a/rts/Printer.c
++++ b/rts/Printer.c
+@@ -48,6 +48,9 @@ void printPtr( StgPtr p )
+ raw = lookupGHCName(p);
+ if (raw != NULL) {
+ printZcoded(raw);
++ /* it can be just a C symbol, like 'stg_returnToStackTop' */
++ debugBelch("<%s>", raw);
++ debugBelch("[%p]", p);
+ } else {
+ debugBelch("%p", p);
+ }
+@@ -794,7 +797,7 @@ static void printZcoded( const char *raw )
+ disabling this for now.
+ */
+ #ifdef USING_LIBBFD
+-
++#include "../mk/config.h" /* silly BFD's requirement */
+ #include <bfd.h>
+
+ /* Fairly ad-hoc piece of code that seems to filter out a lot of
+@@ -863,7 +866,10 @@ extern void DEBUG_LoadSymbols( char *name )
+ for( i = 0; i != number_of_symbols; ++i ) {
+ symbol_info info;
+ bfd_get_symbol_info(abfd,symbol_table[i],&info);
+- /*debugBelch("\t%c\t0x%x \t%s\n",info.type,(nat)info.value,info.name); */
++ if (0)
++ {
++ debugBelch("\t%c\t0x%x \t%s\n",info.type,(nat)info.value,info.name);
++ }
+ if (isReal(info.type, info.name)) {
+ num_real_syms += 1;
+ }
+diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c
+index aa7306f..5bdef94 100644
+--- a/rts/RtsStartup.c
++++ b/rts/RtsStartup.c
+@@ -19,6 +19,7 @@
+ #include "RtsFlags.h"
+ #include "RtsUtils.h"
+ #include "Prelude.h"
++#include "Printer.h" /* DEBUG_LoadSymbols */
+ #include "Schedule.h" /* initScheduler */
+ #include "Stats.h" /* initStats */
+ #include "STM.h" /* initSTM */
+@@ -162,6 +163,11 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
+ rts_config.rts_opts_enabled, rts_config.rts_opts, rts_config.rts_hs_main);
+ }
+
++#ifdef DEBUG
++ /* load debugging symbols */
++ DEBUG_LoadSymbols((*argv)[0]);
++#endif /* DEBUG */
++
+ /* Initialise the stats department, phase 1 */
+ initStats1();
+
diff --git a/dev-lang/ghc/files/ghc-7.8.2-cgen-constify.patch b/dev-lang/ghc/files/ghc-7.8.2-cgen-constify.patch
new file mode 100644
index 000000000000..efdd54fbf3fb
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.2-cgen-constify.patch
@@ -0,0 +1,34 @@
+commit b0cf3ab7a69b878a4335d21a347b56e4b0ca0b7b
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Mon Apr 14 19:06:24 2014 +0300
+
+ compiler/cmm/PprC.hs: constify local string literals
+
+ Consider one-line module
+ module B (v) where v = "hello"
+ in -fvia-C mode it generates code like
+ static char gibberish_str[] = "hello";
+
+ It uselessly eats data section (precious resource on ia64!).
+ The patch switches genrator to emit:
+ static const char gibberish_str[] = "hello";
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
+index 2398981..fdb578d 100644
+--- a/compiler/cmm/PprC.hs
++++ b/compiler/cmm/PprC.hs
+@@ -112,6 +112,12 @@ pprTop (CmmProc infos clbl _ graph) =
+
+ -- We only handle (a) arrays of word-sized things and (b) strings.
+
++pprTop (CmmData ReadOnlyData (Statics lbl [CmmString str])) =
++ hcat [
++ pprLocalness lbl, ptext (sLit "const char "), ppr lbl,
++ ptext (sLit "[] = "), pprStringInCStyle str, semi
++ ]
++
+ pprTop (CmmData _section (Statics lbl [CmmString str])) =
+ hcat [
+ pprLocalness lbl, ptext (sLit "char "), ppr lbl,
diff --git a/dev-lang/ghc/files/ghc-7.8.3-cc-lang.patch b/dev-lang/ghc/files/ghc-7.8.3-cc-lang.patch
new file mode 100644
index 000000000000..032dc9a67624
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-cc-lang.patch
@@ -0,0 +1,129 @@
+commit 4d4d07704ee78221607a18b8118294b0aea1bac4
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Tue Sep 2 00:06:56 2014 +0300
+
+ systools: fix gcc version detecton on non-english locale
+
+ Summary:
+ ghc runs 'gcc -v' to check if we run under vanilla gcc
+ or disaguised clang by checking for string
+
+ "gcc version <something>"
+
+ But this check does not always work as gcc has that string
+ localized via gettext mechanism:
+
+ (some gcc's locale strings)
+ be.po-msgstr "версія gcc %s\n"
+ da.po-msgstr "GCC version %s\n"
+ de.po-msgstr "gcc-Version %s %s\n"
+ el.po-msgstr "έκδοση gcc %s\n"
+ ...
+
+ To ping gcc to English locale we now override environment
+ variable with 'LANGUAGE=en' value.
+
+ Fixes Issue #8825
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ Test Plan: validate
+
+ Reviewers: austin
+
+ Reviewed By: austin
+
+ Subscribers: simonmar, ezyang, carter
+
+ Differential Revision: https://phabricator.haskell.org/D185
+
+ GHC Trac Issues: #8825
+
+diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
+index 72fa19b..67926f5 100644
+--- a/compiler/main/SysTools.lhs
++++ b/compiler/main/SysTools.lhs
+@@ -492,6 +492,51 @@ readCreateProcess proc = do
+
+ return (ex, output)
+
++readProcessEnvWithExitCode
++ :: String -- ^ program path
++ -> [String] -- ^ program args
++ -> [(String, String)] -- ^ environment to override
++ -> IO (ExitCode, String, String) -- ^ (exit_code, stdout, stderr)
++readProcessEnvWithExitCode prog args env_update = do
++ current_env <- getEnvironment
++ let new_env = env_update ++ [ (k, v)
++ | let overriden_keys = map fst env_update
++ , (k, v) <- current_env
++ , k `notElem` overriden_keys
++ ]
++ p = proc prog args
++
++ (_stdin, Just stdoh, Just stdeh, pid) <-
++ createProcess p{ std_out = CreatePipe
++ , std_err = CreatePipe
++ , env = Just new_env
++ }
++
++ outMVar <- newEmptyMVar
++ errMVar <- newEmptyMVar
++
++ _ <- forkIO $ do
++ stdo <- hGetContents stdoh
++ _ <- evaluate (length stdo)
++ putMVar outMVar stdo
++
++ _ <- forkIO $ do
++ stde <- hGetContents stdeh
++ _ <- evaluate (length stde)
++ putMVar errMVar stde
++
++ out <- takeMVar outMVar
++ hClose stdoh
++ err <- takeMVar errMVar
++ hClose stdeh
++
++ ex <- waitForProcess pid
++
++ return (ex, out, err)
++
++-- Don't let gcc localize version info string, #8825
++en_locale_env :: [(String, String)]
++en_locale_env = [("LANGUAGE", "en")]
+
+ -- If the -B<dir> option is set, add <dir> to PATH. This works around
+ -- a bug in gcc on Windows Vista where it can't find its auxiliary
+@@ -746,8 +791,9 @@ getLinkerInfo' dflags = do
+ _ -> do
+ -- In practice, we use the compiler as the linker here. Pass
+ -- -Wl,--version to get linker version info.
+- (exitc, stdo, stde) <- readProcessWithExitCode pgm
+- ["-Wl,--version"] ""
++ (exitc, stdo, stde) <- readProcessEnvWithExitCode pgm
++ ["-Wl,--version"]
++ en_locale_env
+ -- Split the output by lines to make certain kinds
+ -- of processing easier. In particular, 'clang' and 'gcc'
+ -- have slightly different outputs for '-Wl,--version', but
+@@ -802,7 +848,8 @@ getCompilerInfo' dflags = do
+
+ -- Process the executable call
+ info <- catchIO (do
+- (exitc, stdo, stde) <- readProcessWithExitCode pgm ["-v"] ""
++ (exitc, stdo, stde) <-
++ readProcessEnvWithExitCode pgm ["-v"] en_locale_env
+ -- Split the output by lines to make certain kinds
+ -- of processing easier.
+ parseCompilerInfo (lines stdo) (lines stde) exitc
+@@ -952,7 +999,8 @@ readElfSection _dflags section exe = do
+ prog = "readelf"
+ args = [Option "-p", Option section, FileOption "" exe]
+ --
+- r <- readProcessWithExitCode prog (filter notNull (map showOpt args)) ""
++ r <- readProcessEnvWithExitCode prog (filter notNull (map showOpt args))
++ en_locale_env
+ case r of
+ (ExitSuccess, out, _err) -> return (doFilter (lines out))
+ _ -> return Nothing
diff --git a/dev-lang/ghc/files/ghc-7.8.3-deRefStablePtr.patch b/dev-lang/ghc/files/ghc-7.8.3-deRefStablePtr.patch
new file mode 100644
index 000000000000..8deec21edc5c
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-deRefStablePtr.patch
@@ -0,0 +1,38 @@
+commit 104a66a461f4f89b8e5ad9c829923bb7ca8ceddb
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sat Aug 23 13:11:23 2014 +0300
+
+ rts/Linker.c: declare 'deRefStablePtr' as an exported 'rts' symbol
+
+ $ inplace/bin/ghc-stage2 -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -optc-fno-builtin -fno-ghci-history \
+ testsuite/tests/ffi/should_run/T4038.hs --interactive -v0 -ignore-dot-ghci +RTS -I0.1 -RTS
+
+ *Main> main
+ <interactive>: /tmp/ghc16668_0/ghc16668_5.o: unknown symbol `deRefStablePtr'
+
+ The reference to 'deRefStablePtr' is generated by 'compiler/deSugar/DsForeign.lhs':
+ the_cfun
+ = case maybe_target of
+ Nothing -> text "(StgClosure*)deRefStablePtr(the_stableptr)"
+ Just hs_fn -> char '&' <> ppr hs_fn <> text "_closure"
+
+ Patch fixes all broken tests using 'import wrapper':
+ TEST="ffi013 ffi010 ffi011 ffi005 ffi020 ffi006 ffi019 fed001 T1679 T4038"
+
+ Tests manifested as broken only in DYNAMIC_GHC_PROGRAMS=NO builds,
+ where GHCi's custom linker is used instead of system's linker.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/rts/Linker.c b/rts/Linker.c
+index e97580d..b24be58 100644
+--- a/rts/Linker.c
++++ b/rts/Linker.c
+@@ -1092,6 +1092,7 @@ typedef struct _RtsSymbolVal {
+ SymI_HasProto(__word_encodeFloat) \
+ SymI_HasProto(stg_atomicallyzh) \
+ SymI_HasProto(barf) \
++ SymI_HasProto(deRefStablePtr) \
+ SymI_HasProto(debugBelch) \
+ SymI_HasProto(errorBelch) \
+ SymI_HasProto(sysErrorBelch) \
diff --git a/dev-lang/ghc/files/ghc-7.8.3-ia64-prim.patch b/dev-lang/ghc/files/ghc-7.8.3-ia64-prim.patch
new file mode 100644
index 000000000000..9026ecfdf4b1
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-ia64-prim.patch
@@ -0,0 +1,69 @@
+commit e2a8801b9779949010f30db6f6ef66f3c3a70776
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Thu Sep 4 17:50:45 2014 +0300
+
+ pprC: declare extern cmm primitives as functions, not data
+
+ Summary:
+ The commit fixes incorrect code generation of
+ integer-gmp package on ia64 due to C prototype mismatch.
+ Before patch prototype was
+ StgWord poizh[];
+ After patch it became
+ StgFunPtr poizh();
+
+ Long story:
+
+ Consider the following simple example:
+
+ {-# LANGUAGE MagicHash, GHCForeignImportPrim, UnliftedFFITypes #-}
+ module M where
+ import GHC.Prim -- Int#
+ foreign import prim "poizh" poi# :: Int# -> Int#
+
+ Before the patch Unregisterised build generated the
+ following 'poizh' reference:
+ EI_(poizh); /* StgWord poizh[]; */
+ FN_(M_poizh_entry) {
+ // ...
+ JMP_((W_)&poizh);
+ }
+
+ After the patch it looks this way:
+ EF_(poizh); /* StgFunPtr poizh(); */
+ FN_(M_poizh_entry) {
+ // ...
+ JMP_((W_)&poizh);
+ }
+
+ On ia64 it leads to different relocation types being generated:
+ incorrect one:
+ addl r14 = @ltoffx(poizh#)
+ ld8.mov r14 = [r14], poizh#
+ correct one:
+ addl r14 = @ltoff(@fptr(poizh#)), gp
+ ld8 r14 = [r14]
+
+ '@fptr(poizh#)' basically instructs assembler to creates
+ another obect consisting of real address to 'poizh' instructions
+ and module address. That '@fptr' object is used as a function "address".
+ This object is different for every module referencing 'poizh' symbol.
+
+ All indirect function calls expect '@fptr' object. That way
+ call site can read real destination address and set destination
+ module address in 'gp' register.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
+index 02ad026..0f2c0ae 100644
+--- a/compiler/cmm/CLabel.hs
++++ b/compiler/cmm/CLabel.hs
+@@ -813,6 +813,7 @@ labelType (CmmLabel _ _ CmmClosure) = GcPtrLabel
+ labelType (CmmLabel _ _ CmmCode) = CodeLabel
+ labelType (CmmLabel _ _ CmmInfo) = DataLabel
+ labelType (CmmLabel _ _ CmmEntry) = CodeLabel
++labelType (CmmLabel _ _ CmmPrimCall) = CodeLabel
+ labelType (CmmLabel _ _ CmmRetInfo) = DataLabel
+ labelType (CmmLabel _ _ CmmRet) = CodeLabel
+ labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
diff --git a/dev-lang/ghc/files/ghc-7.8.3-linker-warn.patch b/dev-lang/ghc/files/ghc-7.8.3-linker-warn.patch
new file mode 100644
index 000000000000..c8570c06940b
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-linker-warn.patch
@@ -0,0 +1,35 @@
+commit 326046739801a380c5457ef4c87bce8fb95497ba
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sun Aug 10 22:12:28 2014 +0300
+
+ systools info: fix warning about C compiler (message said about linker)
+
+ Summary: Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ Test Plan: build-tested
+
+ Reviewers: austin
+
+ Reviewed By: austin
+
+ Subscribers: phaskell, simonmar, relrod, ezyang, carter
+
+ Differential Revision: https://phabricator.haskell.org/D132
+
+diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
+index 1c1c52c..72fa19b 100644
+--- a/compiler/main/SysTools.lhs
++++ b/compiler/main/SysTools.lhs
+@@ -809,10 +809,10 @@ getCompilerInfo' dflags = do
+ )
+ (\err -> do
+ debugTraceMsg dflags 2
+- (text "Error (figuring out compiler information):" <+>
++ (text "Error (figuring out C compiler information):" <+>
+ text (show err))
+ errorMsg dflags $ hang (text "Warning:") 9 $
+- text "Couldn't figure out linker information!" $$
++ text "Couldn't figure out C compiler information!" $$
+ text "Make sure you're using GNU gcc, or clang"
+ return UnknownCC)
+ return info
diff --git a/dev-lang/ghc/files/ghc-7.8.3-pic-asm.patch b/dev-lang/ghc/files/ghc-7.8.3-pic-asm.patch
new file mode 100644
index 000000000000..10c41d5b29f6
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-pic-asm.patch
@@ -0,0 +1,107 @@
+commit a93ab43ab5f40cadbedea2f6342b93c245e91434
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Wed Aug 27 22:19:52 2014 +0300
+
+ driver: pass '-fPIC' option to assembler as well
+
+ Summary:
+ Before the patch '-fPIC' was passed only to C compiler,
+ but not to assembler itself.
+
+ It led to runtime crash in GHC_DYNAMIC_PROGRAMS=YES mode
+ on sparc32.
+
+ Technical details are in 'Note [-fPIC for assembler]'.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ Test Plan: validate on sparc
+
+ Reviewers: simonmar, austin, kgardas
+
+ Reviewed By: austin
+
+ Subscribers: simonmar, ezyang, carter
+
+ Differential Revision: https://phabricator.haskell.org/D177
+
+diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
+index 183f435..5a18e6e 100644
+--- a/compiler/main/DriverPipeline.hs
++++ b/compiler/main/DriverPipeline.hs
+@@ -1199,6 +1199,7 @@ runPhase (RealPhase (As with_cpp)) input_fn dflags
+
+ as_prog <- whichAsProg
+ let cmdline_include_paths = includePaths dflags
++ let pic_c_flags = picCCOpts dflags
+
+ next_phase <- maybeMergeStub
+ output_fn <- phaseOutputFilename next_phase
+@@ -1212,6 +1213,9 @@ runPhase (RealPhase (As with_cpp)) input_fn dflags
+ = liftIO $ as_prog dflags
+ ([ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
+
++ -- See Note [-fPIC for assembler]
++ ++ map SysTools.Option pic_c_flags
++
+ -- We only support SparcV9 and better because V8 lacks an atomic CAS
+ -- instruction so we have to make sure that the assembler accepts the
+ -- instruction set. Note that the user can still override this
+@@ -1253,6 +1257,8 @@ runPhase (RealPhase SplitAs) _input_fn dflags
+ osuf = objectSuf dflags
+ split_odir = base_o ++ "_" ++ osuf ++ "_split"
+
++ let pic_c_flags = picCCOpts dflags
++
+ -- this also creates the hierarchy
+ liftIO $ createDirectoryIfMissing True split_odir
+
+@@ -1286,6 +1292,9 @@ runPhase (RealPhase SplitAs) _input_fn dflags
+ then [SysTools.Option "-mcpu=v9"]
+ else []) ++
+
++ -- See Note [-fPIC for assembler]
++ map SysTools.Option pic_c_flags ++
++
+ [ SysTools.Option "-c"
+ , SysTools.Option "-o"
+ , SysTools.FileOption "" (split_obj n)
+@@ -2203,3 +2212,38 @@ haveRtsOptsFlags dflags =
+ isJust (rtsOpts dflags) || case rtsOptsEnabled dflags of
+ RtsOptsSafeOnly -> False
+ _ -> True
++
++-- Note [-fPIC for assembler]
++-- When compiling .c source file GHC's driver pipeline basically
++-- does the following two things:
++-- 1. ${CC} -S 'PIC_CFLAGS' source.c
++-- 2. ${CC} -x assembler -c 'PIC_CFLAGS' source.S
++--
++-- Why do we need to pass 'PIC_CFLAGS' both to C compiler and assembler?
++-- Because on some architectures (at least sparc32) assembler also choses
++-- relocation type!
++-- Consider the following C module:
++--
++-- /* pic-sample.c */
++-- int v;
++-- void set_v (int n) { v = n; }
++-- int get_v (void) { return v; }
++--
++-- $ gcc -S -fPIC pic-sample.c
++-- $ gcc -c pic-sample.s -o pic-sample.no-pic.o # incorrect binary
++-- $ gcc -c -fPIC pic-sample.s -o pic-sample.pic.o # correct binary
++--
++-- $ objdump -r -d pic-sample.pic.o > pic-sample.pic.o.od
++-- $ objdump -r -d pic-sample.no-pic.o > pic-sample.no-pic.o.od
++-- $ diff -u pic-sample.pic.o.od pic-sample.no-pic.o.od
++--
++-- Most of architectures won't show any difference in this test, but on sparc32
++-- the following assembly snippet:
++--
++-- sethi %hi(_GLOBAL_OFFSET_TABLE_-8), %l7
++--
++-- generates two kinds or relocations, only 'R_SPARC_PC22' is correct:
++--
++-- 3c: 2f 00 00 00 sethi %hi(0), %l7
++-- - 3c: R_SPARC_PC22 _GLOBAL_OFFSET_TABLE_-0x8
++-- + 3c: R_SPARC_HI22 _GLOBAL_OFFSET_TABLE_-0x8
diff --git a/dev-lang/ghc/files/ghc-7.8.3-pic-sparc.patch b/dev-lang/ghc/files/ghc-7.8.3-pic-sparc.patch
new file mode 100644
index 000000000000..16a552fdd4be
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-pic-sparc.patch
@@ -0,0 +1,31 @@
+commit 78863edbb0751f5c9694ea10c6132a87cfd0ee10
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Wed Aug 27 22:20:33 2014 +0300
+
+ Revert "disable shared libs on sparc (linux/solaris) (fixes #8857)"
+
+ This reverts commit 623883f1ed0ee11cc925c4590fb09565403fd231.
+
+ The commit a93ab43ab5f40cadbedea2f6342b93c245e91434
+ driver: pass '-fPIC' option to assembler as well
+ fixes shared libraries on sparc at least on linux.
+
+ Properly fixes Issue #8857
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index c210cd3..392237f 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -97,9 +97,7 @@ endif
+ # Some platforms don't support shared libraries
+ NoSharedLibsPlatformList = powerpc-unknown-linux \
+ x86_64-unknown-mingw32 \
+- i386-unknown-mingw32 \
+- sparc-sun-solaris2 \
+- sparc-unknown-linux
++ i386-unknown-mingw32
+
+ ifeq "$(SOLARIS_BROKEN_SHLD)" "YES"
+ NoSharedLibsPlatformList += i386-unknown-solaris2
diff --git a/dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch b/dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch
new file mode 100644
index 000000000000..434be8b1bdad
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch
@@ -0,0 +1,351 @@
+commit fa31e8f4a0f853848d96549a429083941877bf8d
+Author: Sergei Trofimovich <siarheit@google.com>
+Date: Sun Dec 14 14:30:12 2014 +0000
+
+ powerpc: fix and enable shared libraries by default on linux
+
+ Summary:
+ And fix things all the way down to it. Namely:
+ - remove 'r30' from free registers, it's an .LCTOC1 register
+ for gcc. generated .plt stubs expect it to be initialised.
+ - fix PicBase computation, which originally forgot to use 'tmp'
+ reg in 'initializePicBase_ppc.fetchPC'
+ - mark 'ForeighTarget's as implicitly using 'PicBase' register
+ (see comment for details)
+ - add 64-bit MO_Sub and test on alloclimit3/4 regtests
+ - fix dynamic label offsets to match with .LCTOC1 offset
+
+ Signed-off-by: Sergei Trofimovich <siarheit@google.com>
+
+ Test Plan: validate passes equal amount of vanilla/dyn tests
+
+ Reviewers: simonmar, erikd, austin
+
+ Reviewed By: erikd, austin
+
+ Subscribers: carter, thomie
+
+ Differential Revision: https://phabricator.haskell.org/D560
+
+ GHC Trac Issues: #8024, #9831
+
+diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
+index 0f2c0ae..37b8ada 100644
+--- a/compiler/cmm/CLabel.hs
++++ b/compiler/cmm/CLabel.hs
+@@ -1170,7 +1170,8 @@ pprDynamicLinkerAsmLabel platform dllInfo lbl
+ else if osElfTarget (platformOS platform)
+ then if platformArch platform == ArchPPC
+ then case dllInfo of
+- CodeStub -> ppr lbl <> text "@plt"
++ CodeStub -> -- See Note [.LCTOC1 in PPC PIC code]
++ ppr lbl <> text "+32768@plt"
+ SymbolPtr -> text ".LC_" <> ppr lbl
+ _ -> panic "pprDynamicLinkerAsmLabel"
+ else if platformArch platform == ArchX86_64
+diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs
+index 9b5c080..6326a8b 100644
+--- a/compiler/nativeGen/PIC.hs
++++ b/compiler/nativeGen/PIC.hs
+@@ -54,7 +54,6 @@ import qualified X86.Instr as X86
+
+ import Platform
+ import Instruction
+-import Size
+ import Reg
+ import NCGMonad
+
+@@ -468,11 +467,8 @@ pprGotDeclaration dflags ArchX86 OSDarwin
+ pprGotDeclaration _ _ OSDarwin
+ = empty
+
+--- pprGotDeclaration
++-- Emit GOT declaration
+ -- Output whatever needs to be output once per .s file.
+--- The .LCTOC1 label is defined to point 32768 bytes into the table,
+--- to make the most of the PPC's 16-bit displacements.
+--- Only needed for PIC.
+ pprGotDeclaration dflags arch os
+ | osElfTarget os
+ , arch /= ArchPPC_64
+@@ -482,6 +478,7 @@ pprGotDeclaration dflags arch os
+ | osElfTarget os
+ , arch /= ArchPPC_64
+ = vcat [
++ -- See Note [.LCTOC1 in PPC PIC code]
+ ptext (sLit ".section \".got2\",\"aw\""),
+ ptext (sLit ".LCTOC1 = .+32768") ]
+
+@@ -688,12 +685,7 @@ pprImportedSymbol _ _ _
+
+
+ -- Get a pointer to our own fake GOT, which is defined on a per-module basis.
+--- This is exactly how GCC does it, and it's quite horrible:
+--- We first fetch the address of a local label (mkPicBaseLabel).
+--- Then we add a 16-bit offset to that to get the address of a .long that we
+--- define in .text space right next to the proc. This .long literal contains
+--- the (32-bit) offset from our local label to our global offset table
+--- (.LCTOC1 aka gotOffLabel).
++-- This is exactly how GCC does it in linux.
+
+ initializePicBase_ppc
+ :: Arch -> OS -> Reg
+@@ -704,18 +696,9 @@ initializePicBase_ppc ArchPPC os picReg
+ (CmmProc info lab live (ListGraph blocks) : statics)
+ | osElfTarget os
+ = do
+- dflags <- getDynFlags
+- gotOffLabel <- getNewLabelNat
+- tmp <- getNewRegNat $ intSize (wordWidth dflags)
+ let
+- gotOffset = CmmData Text $ Statics gotOffLabel [
+- CmmStaticLit (CmmLabelDiffOff gotLabel
+- mkPicBaseLabel
+- 0)
+- ]
+- offsetToOffset
+- = PPC.ImmConstantDiff
+- (PPC.ImmCLbl gotOffLabel)
++ gotOffset = PPC.ImmConstantDiff
++ (PPC.ImmCLbl gotLabel)
+ (PPC.ImmCLbl mkPicBaseLabel)
+
+ blocks' = case blocks of
+@@ -726,15 +709,23 @@ initializePicBase_ppc ArchPPC os picReg
+ | bID `mapMember` info = fetchPC b
+ | otherwise = b
+
++ -- GCC does PIC prologs thusly:
++ -- bcl 20,31,.L1
++ -- .L1:
++ -- mflr 30
++ -- addis 30,30,.LCTOC1-.L1@ha
++ -- addi 30,30,.LCTOC1-.L1@l
++ -- TODO: below we use it over temporary register,
++ -- it can and should be optimised by picking
++ -- correct PIC reg.
+ fetchPC (BasicBlock bID insns) =
+ BasicBlock bID (PPC.FETCHPC picReg
+- : PPC.ADDIS tmp picReg (PPC.HI offsetToOffset)
+- : PPC.LD PPC.archWordSize tmp
+- (PPC.AddrRegImm tmp (PPC.LO offsetToOffset))
+- : PPC.ADD picReg picReg (PPC.RIReg picReg)
++ : PPC.ADDIS picReg picReg (PPC.HA gotOffset)
++ : PPC.ADDI picReg picReg (PPC.LO gotOffset)
++ : PPC.MR PPC.r30 picReg
+ : insns)
+
+- return (CmmProc info lab live (ListGraph blocks') : gotOffset : statics)
++ return (CmmProc info lab live (ListGraph blocks') : statics)
+
+
+ initializePicBase_ppc ArchPPC OSDarwin picReg
+diff --git a/compiler/nativeGen/PPC/CodeGen.hs b/compiler/nativeGen/PPC/CodeGen.hs
+index ddf483a..c1c4a74 100644
+--- a/compiler/nativeGen/PPC/CodeGen.hs
++++ b/compiler/nativeGen/PPC/CodeGen.hs
+@@ -54,7 +54,7 @@ import Outputable
+ import Unique
+ import DynFlags
+
+-import Control.Monad ( mapAndUnzipM )
++import Control.Monad ( mapAndUnzipM, when )
+ import Data.Bits
+ import Data.Word
+
+@@ -355,6 +355,19 @@ iselExpr64 (CmmMachOp (MO_Add _) [e1,e2]) = do
+ ADDE rhi r1hi r2hi ]
+ return (ChildCode64 code rlo)
+
++iselExpr64 (CmmMachOp (MO_Sub _) [e1,e2]) = do
++ ChildCode64 code1 r1lo <- iselExpr64 e1
++ ChildCode64 code2 r2lo <- iselExpr64 e2
++ (rlo,rhi) <- getNewRegPairNat II32
++ let
++ r1hi = getHiVRegFromLo r1lo
++ r2hi = getHiVRegFromLo r2lo
++ code = code1 `appOL`
++ code2 `appOL`
++ toOL [ SUBFC rlo r2lo r1lo,
++ SUBFE rhi r2hi r1hi ]
++ return (ChildCode64 code rlo)
++
+ iselExpr64 (CmmMachOp (MO_UU_Conv W32 W64) [expr]) = do
+ (expr_reg,expr_code) <- getSomeReg expr
+ (rlo, rhi) <- getNewRegPairNat II32
+@@ -918,8 +931,12 @@ genCCall' dflags gcp target dest_regs args0
+ (toOL []) []
+
+ (labelOrExpr, reduceToFF32) <- case target of
+- ForeignTarget (CmmLit (CmmLabel lbl)) _ -> return (Left lbl, False)
+- ForeignTarget expr _ -> return (Right expr, False)
++ ForeignTarget (CmmLit (CmmLabel lbl)) _ -> do
++ uses_pic_base_implicitly
++ return (Left lbl, False)
++ ForeignTarget expr _ -> do
++ uses_pic_base_implicitly
++ return (Right expr, False)
+ PrimTarget mop -> outOfLineMachOp mop
+
+ let codeBefore = move_sp_down finalStack `appOL` passArgumentsCode
+@@ -940,6 +957,13 @@ genCCall' dflags gcp target dest_regs args0
+ where
+ platform = targetPlatform dflags
+
++ uses_pic_base_implicitly = do
++ -- See Note [implicit register in PPC PIC code]
++ -- on why we claim to use PIC register here
++ when (gopt Opt_PIC dflags) $ do
++ _ <- getPicBaseNat archWordSize
++ return ()
++
+ initialStackOffset = case gcp of
+ GCPDarwin -> 24
+ GCPLinux -> 8
+@@ -1431,3 +1455,21 @@ coerceFP2Int _ toRep x = do
+ -- read low word of value (high word is undefined)
+ LD II32 dst (spRel dflags 3)]
+ return (Any (intSize toRep) code')
++
++-- Note [.LCTOC1 in PPC PIC code]
++-- The .LCTOC1 label is defined to point 32768 bytes into the GOT table
++-- to make the most of the PPC's 16-bit displacements.
++-- As 16-bit signed offset is used (usually via addi/lwz instructions)
++-- first element will have '-32768' offset against .LCTOC1.
++
++-- Note [implicit register in PPC PIC code]
++-- PPC generates calls by labels in assembly
++-- in form of:
++-- bl puts+32768@plt
++-- in this form it's not seen directly (by GHC NCG)
++-- that r30 (PicBaseReg) is used,
++-- but r30 is a required part of PLT code setup:
++-- puts+32768@plt:
++-- lwz r11,-30484(r30) ; offset in .LCTOC1
++-- mtctr r11
++-- bctr
+diff --git a/compiler/nativeGen/PPC/Instr.hs b/compiler/nativeGen/PPC/Instr.hs
+index f5b9506..b7081f9 100644
+--- a/compiler/nativeGen/PPC/Instr.hs
++++ b/compiler/nativeGen/PPC/Instr.hs
+@@ -205,8 +205,11 @@ data Instr
+ | ADD Reg Reg RI -- dst, src1, src2
+ | ADDC Reg Reg Reg -- (carrying) dst, src1, src2
+ | ADDE Reg Reg Reg -- (extend) dst, src1, src2
++ | ADDI Reg Reg Imm -- Add Immediate dst, src1, src2
+ | ADDIS Reg Reg Imm -- Add Immediate Shifted dst, src1, src2
+ | SUBF Reg Reg Reg -- dst, src1, src2 ; dst = src2 - src1
++ | SUBFC Reg Reg Reg -- (carrying) dst, src1, src2 ; dst = src2 - src1
++ | SUBFE Reg Reg Reg -- (extend) dst, src1, src2 ; dst = src2 - src1
+ | MULLW Reg Reg RI
+ | DIVW Reg Reg Reg
+ | DIVWU Reg Reg Reg
+@@ -284,8 +287,11 @@ ppc_regUsageOfInstr platform instr
+ ADD reg1 reg2 ri -> usage (reg2 : regRI ri, [reg1])
+ ADDC reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
+ ADDE reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
++ ADDI reg1 reg2 _ -> usage ([reg2], [reg1])
+ ADDIS reg1 reg2 _ -> usage ([reg2], [reg1])
+ SUBF reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
++ SUBFC reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
++ SUBFE reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
+ MULLW reg1 reg2 ri -> usage (reg2 : regRI ri, [reg1])
+ DIVW reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
+ DIVWU reg1 reg2 reg3 -> usage ([reg2,reg3], [reg1])
+@@ -358,8 +364,11 @@ ppc_patchRegsOfInstr instr env
+ ADD reg1 reg2 ri -> ADD (env reg1) (env reg2) (fixRI ri)
+ ADDC reg1 reg2 reg3 -> ADDC (env reg1) (env reg2) (env reg3)
+ ADDE reg1 reg2 reg3 -> ADDE (env reg1) (env reg2) (env reg3)
++ ADDI reg1 reg2 imm -> ADDI (env reg1) (env reg2) imm
+ ADDIS reg1 reg2 imm -> ADDIS (env reg1) (env reg2) imm
+ SUBF reg1 reg2 reg3 -> SUBF (env reg1) (env reg2) (env reg3)
++ SUBFC reg1 reg2 reg3 -> SUBFC (env reg1) (env reg2) (env reg3)
++ SUBFE reg1 reg2 reg3 -> SUBFE (env reg1) (env reg2) (env reg3)
+ MULLW reg1 reg2 ri -> MULLW (env reg1) (env reg2) (fixRI ri)
+ DIVW reg1 reg2 reg3 -> DIVW (env reg1) (env reg2) (env reg3)
+ DIVWU reg1 reg2 reg3 -> DIVWU (env reg1) (env reg2) (env reg3)
+diff --git a/compiler/nativeGen/PPC/Ppr.hs b/compiler/nativeGen/PPC/Ppr.hs
+index 6851769..f59d51f 100644
+--- a/compiler/nativeGen/PPC/Ppr.hs
++++ b/compiler/nativeGen/PPC/Ppr.hs
+@@ -525,6 +525,16 @@ pprInstr (BCTRL _) = hcat [
+ ptext (sLit "bctrl")
+ ]
+ pprInstr (ADD reg1 reg2 ri) = pprLogic (sLit "add") reg1 reg2 ri
++pprInstr (ADDI reg1 reg2 imm) = hcat [
++ char '\t',
++ ptext (sLit "addi"),
++ char '\t',
++ pprReg reg1,
++ ptext (sLit ", "),
++ pprReg reg2,
++ ptext (sLit ", "),
++ pprImm imm
++ ]
+ pprInstr (ADDIS reg1 reg2 imm) = hcat [
+ char '\t',
+ ptext (sLit "addis"),
+@@ -539,6 +549,8 @@ pprInstr (ADDIS reg1 reg2 imm) = hcat [
+ pprInstr (ADDC reg1 reg2 reg3) = pprLogic (sLit "addc") reg1 reg2 (RIReg reg3)
+ pprInstr (ADDE reg1 reg2 reg3) = pprLogic (sLit "adde") reg1 reg2 (RIReg reg3)
+ pprInstr (SUBF reg1 reg2 reg3) = pprLogic (sLit "subf") reg1 reg2 (RIReg reg3)
++pprInstr (SUBFC reg1 reg2 reg3) = pprLogic (sLit "subfc") reg1 reg2 (RIReg reg3)
++pprInstr (SUBFE reg1 reg2 reg3) = pprLogic (sLit "subfe") reg1 reg2 (RIReg reg3)
+ pprInstr (MULLW reg1 reg2 ri@(RIReg _)) = pprLogic (sLit "mullw") reg1 reg2 ri
+ pprInstr (MULLW reg1 reg2 ri@(RIImm _)) = pprLogic (sLit "mull") reg1 reg2 ri
+ pprInstr (DIVW reg1 reg2 reg3) = pprLogic (sLit "divw") reg1 reg2 (RIReg reg3)
+diff --git a/compiler/nativeGen/PPC/Regs.hs b/compiler/nativeGen/PPC/Regs.hs
+index 0f636bf..69e69c0 100644
+--- a/compiler/nativeGen/PPC/Regs.hs
++++ b/compiler/nativeGen/PPC/Regs.hs
+@@ -37,7 +37,8 @@ module PPC.Regs (
+ fits16Bits,
+ makeImmediate,
+ fReg,
+- sp, r3, r4, r27, r28, f1, f20, f21,
++ sp, r3, r4, r27, r28, r30,
++ f1, f20, f21,
+
+ allocatableRegs
+
+@@ -295,12 +296,13 @@ point registers.
+ fReg :: Int -> RegNo
+ fReg x = (32 + x)
+
+-sp, r3, r4, r27, r28, f1, f20, f21 :: Reg
++sp, r3, r4, r27, r28, r30, f1, f20, f21 :: Reg
+ sp = regSingle 1
+ r3 = regSingle 3
+ r4 = regSingle 4
+ r27 = regSingle 27
+ r28 = regSingle 28
++r30 = regSingle 30
+ f1 = regSingle $ fReg 1
+ f20 = regSingle $ fReg 20
+ f21 = regSingle $ fReg 21
+diff --git a/includes/CodeGen.Platform.hs b/includes/CodeGen.Platform.hs
+index 9916e0e..1d46a01 100644
+--- a/includes/CodeGen.Platform.hs
++++ b/includes/CodeGen.Platform.hs
+@@ -881,6 +881,8 @@ freeReg 1 = fastBool False -- The Stack Pointer
+ # if !MACHREGS_darwin
+ -- most non-darwin powerpc OSes use r2 as a TOC pointer or something like that
+ freeReg 2 = fastBool False
++-- at least linux in -fPIC relies on r30 in PLT stubs
++freeReg 30 = fastBool False
+ # endif
+ # ifdef REG_Base
+ freeReg REG_Base = fastBool False
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index 0f5820f..8f134bc 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -95,7 +95,7 @@ TargetElf = YES
+ endif
+
+ # Some platforms don't support shared libraries
+-NoSharedLibsPlatformList = powerpc-unknown-linux \
++NoSharedLibsPlatformList = \
+ x86_64-unknown-mingw32 \
+ i386-unknown-mingw32
+
diff --git a/dev-lang/ghc/files/ghc-7.8.3-prim-lm.patch b/dev-lang/ghc/files/ghc-7.8.3-prim-lm.patch
new file mode 100644
index 000000000000..3ef2313fcec1
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-prim-lm.patch
@@ -0,0 +1,12 @@
+Fix underlinking on ghc-prim.
+Fixes ghc-stage2 crahs on hardened toolchain.
+Reported-by: aranea
+diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal
+index ffb32af..0431380 100644
+--- a/libraries/ghc-prim/ghc-prim.cabal
++++ b/libraries/ghc-prim/ghc-prim.cabal
+@@ -68,0 +68,4 @@ Library
++
++ -- ghc 'sin' (and other) primops generate 'libm' calls,
++ -- but ghc itself does not add '-lm'
++ extra-libraries: m
diff --git a/dev-lang/ghc/files/ghc-7.8.3-unreg-lit.patch b/dev-lang/ghc/files/ghc-7.8.3-unreg-lit.patch
new file mode 100644
index 000000000000..632696d6fde7
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.3-unreg-lit.patch
@@ -0,0 +1,84 @@
+commit a6ea05e21e175407dc9e45f18c56c1d727fd0f26
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Fri Aug 22 23:24:32 2014 +0300
+
+ UNREG: fix emission of large Integer literals in C codegen
+
+ Summary:
+ On amd64/UNREG build there is many failing tests trying
+ to deal with 'Integer' types.
+
+ Looking at 'overflow1' test I've observed invalid C code generated by
+ GHC.
+
+ Cmm code
+ CInt a = -1; (a == -1)
+ yields 'False' with optimisations enabled via the following C code:
+ StgWord64 a = (StgWord32)0xFFFFffffFFFFffffu; (a == 0xFFFFffffFFFFffffu)
+
+ The patch fixes it by shrinking emitted literals to required sizes:
+ StgWord64 a = (StgWord32)0xFFFFffffu; (a == 0xFFFFffffu)
+
+ Thanks to Reid Barton for tracking down and fixing the issue.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ Test Plan: validate on UNREG build (amd64)
+
+ Reviewers: simonmar, rwbarton, austin
+
+ Subscribers: simonmar, ezyang, carter
+
+ Differential Revision: https://phabricator.haskell.org/D173
+
+diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
+index 93a5d06..8605988 100644
+--- a/compiler/cmm/PprC.hs
++++ b/compiler/cmm/PprC.hs
+@@ -1221,8 +1221,9 @@ commafy xs = hsep $ punctuate comma xs
+ pprHexVal :: Integer -> Width -> SDoc
+ pprHexVal 0 _ = ptext (sLit "0x0")
+ pprHexVal w rep
+- | w < 0 = parens (char '-' <> ptext (sLit "0x") <> go (-w) <> repsuffix rep)
+- | otherwise = ptext (sLit "0x") <> go w <> repsuffix rep
++ | w < 0 = parens (char '-' <>
++ ptext (sLit "0x") <> intToDoc (-w) <> repsuffix rep)
++ | otherwise = ptext (sLit "0x") <> intToDoc w <> repsuffix rep
+ where
+ -- type suffix for literals:
+ -- Integer literals are unsigned in Cmm/C. We explicitly cast to
+@@ -1237,10 +1238,33 @@ pprHexVal w rep
+ else panic "pprHexVal: Can't find a 64-bit type"
+ repsuffix _ = char 'U'
+
++ intToDoc :: Integer -> SDoc
++ intToDoc i = go (truncInt i)
++
++ -- We need to truncate value as Cmm backend does not drop
++ -- redundant bits to ease handling of negative values.
++ -- Thus the following Cmm code on 64-bit arch, like amd64:
++ -- CInt v;
++ -- v = {something};
++ -- if (v == %lobits32(-1)) { ...
++ -- leads to the following C code:
++ -- StgWord64 v = (StgWord32)({something});
++ -- if (v == 0xFFFFffffFFFFffffU) { ...
++ -- Such code is incorrect as it promotes both operands to StgWord64
++ -- and the whole condition is always false.
++ truncInt :: Integer -> Integer
++ truncInt i =
++ case rep of
++ W8 -> i `rem` (2^(8 :: Int))
++ W16 -> i `rem` (2^(16 :: Int))
++ W32 -> i `rem` (2^(32 :: Int))
++ W64 -> i `rem` (2^(64 :: Int))
++ _ -> panic ("pprHexVal/truncInt: C backend can't encode "
++ ++ show rep ++ " literals")
++
+ go 0 = empty
+ go w' = go q <> dig
+ where
+ (q,r) = w' `quotRem` 16
+ dig | r < 10 = char (chr (fromInteger r + ord '0'))
+ | otherwise = char (chr (fromInteger r - 10 + ord 'a'))
+-
diff --git a/dev-lang/ghc/files/ghc-7.8.4-gold.patch b/dev-lang/ghc/files/ghc-7.8.4-gold.patch
new file mode 100644
index 000000000000..a8e9b1e6c857
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.4-gold.patch
@@ -0,0 +1,27 @@
+Gentoo-bug: https://bugs.gentoo.org/536426
+Reported-by: Eric Siegel
+commit 021b7978d14799bae779907faf7490cfd21b3f46
+Author: Austin Seipp <austin@well-typed.com>
+Date: Sun Jul 20 10:13:15 2014 -0500
+
+ driver: use absolute paths in ld scripts (#7452)
+
+ Patch contributed by slowmo.
+
+ Signed-off-by: Austin Seipp <austin@well-typed.com>
+
+diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
+index 11427e2..49126fe 100644
+--- a/compiler/main/DriverPipeline.hs
++++ b/compiler/main/DriverPipeline.hs
+@@ -2166,7 +2166,9 @@ joinObjectFiles dflags o_files output_fn = do
+ if ldIsGnuLd
+ then do
+ script <- newTempName dflags "ldscript"
+- writeFile script $ "INPUT(" ++ unwords o_files ++ ")"
++ cwd <- getCurrentDirectory
++ let o_files_abs = map (cwd </>) o_files
++ writeFile script $ "INPUT(" ++ unwords o_files_abs ++ ")"
+ ld_r [SysTools.FileOption "" script] ccInfo
+ else if sLdSupportsFilelist mySettings
+ then do
diff --git a/dev-lang/ghc/files/ghc-7.8.4-ia64-CLOSUREs.patch b/dev-lang/ghc/files/ghc-7.8.4-ia64-CLOSUREs.patch
new file mode 100644
index 000000000000..9d50792bcf45
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-7.8.4-ia64-CLOSUREs.patch
@@ -0,0 +1,66 @@
+From b677ba51cf8131a6f6ddcdfee8dd2a8c4c2b4ac7 Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <siarheit@google.com>
+Date: Sat, 17 Jan 2015 14:27:13 +0000
+Subject: [PATCH 1/3] CMM: add a mechanism to import C data labels
+
+Fixes threaded runtime on ia64.
+sm_mutex there was not referenced correctly.
+
+Signed-off-by: Sergei Trofimovich <siarheit@google.com>
+---
+ compiler/cmm/CmmParse.y | 4 ++++
+ rts/Exception.cmm | 2 +-
+ rts/PrimOps.cmm | 6 +++---
+ 3 files changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/compiler/cmm/CmmParse.y.source b/compiler/cmm/CmmParse.y.source
+index 6b51e51..fd9489b 100644
+--- a/compiler/cmm/CmmParse.y.source
++++ b/compiler/cmm/CmmParse.y.source
+@@ -575,6 +575,10 @@ importName
+ : NAME
+ { ($1, mkForeignLabel $1 Nothing ForeignLabelInExternalPackage IsFunction) }
+
++ -- as previous 'NAME', but 'IsData'
++ | 'CLOSURE' NAME
++ { ($2, mkForeignLabel $2 Nothing ForeignLabelInExternalPackage IsData) }
++
+ -- A label imported with an explicit packageId.
+ | STRING NAME
+ { ($2, mkCmmCodeLabel (fsToPackageKey (mkFastString $1)) $2) }
+diff --git a/rts/Exception.cmm b/rts/Exception.cmm
+index 5007ef3..8d19c14 100644
+--- a/rts/Exception.cmm
++++ b/rts/Exception.cmm
+@@ -13,7 +13,7 @@
+ #include "Cmm.h"
+ #include "RaiseAsync.h"
+
+-import ghczmprim_GHCziTypes_True_closure;
++import CLOSURE ghczmprim_GHCziTypes_True_closure;
+
+ /* -----------------------------------------------------------------------------
+ Exception Primitives
+diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
+index 3e8612c..2e6ca46 100644
+--- a/rts/PrimOps.cmm
++++ b/rts/PrimOps.cmm
+@@ -28,12 +28,12 @@
+ import pthread_mutex_lock;
+ import pthread_mutex_unlock;
+ #endif
+-import base_ControlziExceptionziBase_nestedAtomically_closure;
++import CLOSURE base_ControlziExceptionziBase_nestedAtomically_closure;
+ import EnterCriticalSection;
+ import LeaveCriticalSection;
+-import ghczmprim_GHCziTypes_False_closure;
++import CLOSURE ghczmprim_GHCziTypes_False_closure;
+ #if defined(USE_MINIINTERPRETER) || !defined(mingw32_HOST_OS)
+-import sm_mutex;
++import CLOSURE sm_mutex;
+ #endif
+
+ /*-----------------------------------------------------------------------------
+--
+2.2.1
+
diff --git a/dev-lang/ghc/files/ghc-bash-completion b/dev-lang/ghc/files/ghc-bash-completion
new file mode 100644
index 000000000000..0ee2149cd81b
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-bash-completion
@@ -0,0 +1,218 @@
+# ghc-pkg command line completion for bash
+#
+# Copyright 2006-2007 Lennart Kolmodin <kolmodin@dtek.chalmers.se>
+
+_ghc-pkg-get-ghc-pkg()
+{
+ echo ghc-pkg
+}
+
+_ghc-pkg-pkg-fields()
+{
+ # usage: _ghc-pkg-pkg-fields pkg-id
+ #
+ # list all fields of the pkg-id
+
+ # same fields for all packages but different in different versions of
+ # ghc-pkg? this can probably be done better/faster
+
+ if [[ -z "$1" ]]; then
+ echo "usage: _ghc-pkg-pkg-fields pkg-id"
+ return 1
+ fi
+
+ local fields
+
+ fields="$( $(_ghc-pkg-get-ghc-pkg) describe $1 )"
+
+ #if [[ fields != *"cannot find package"* ]]; then
+ echo "$fields" | grep ".*:.*" | sed "s/^\(.*\):.*\$/\1/"
+ #fi
+}
+
+_ghc-pkg-pkg-ids()
+{
+ # usage: _ghc-pkg-pkg-ids
+ #
+ # simply lists all package ids known by ghc-pkg.
+ $(_ghc-pkg-get-ghc-pkg) list --simple-output
+}
+
+_ghc-pkg-pkgs()
+{
+ # usage: _ghc-pkg-pkgs [include-pkgs] [include-ids]
+ #
+ # with optional parameter include-pkgs it will list all packages known
+ # to ghc-pkg.
+ # with optional parameter include-ids it will list all package-ids known
+ # to ghc-pkg.
+ local pkgs
+ local result
+ pkgs=( $( _ghc-pkg-pkg-ids ) )
+ result=( )
+
+ local withPkgs="no" withIds="no"
+ while [[ -n "$1" ]]; do
+ case "$1" in
+ include-pkgs)
+ withPkgs="yes" ;;
+ include-ids)
+ withIds="yes" ;;
+ *)
+ echo "unknown parameter '$1' to _ghc-pkg-pkgs"
+ return 1 ;;
+ esac
+ shift
+ done
+
+ # user must supply either include-pkgs, include-ids or both
+ if [[ $withPkgs != "yes" && $withIds != "yes" ]]; then
+ echo "usage: _ghc-pkg-pkgs [include-pkgs] [include-ids]"
+ return 1
+ fi
+
+ # find all packages if the user requested them
+ if [[ $withPkgs == "yes" ]]; then
+ # O(n^2) algorithm to exclude duplicates
+ for p in ${pkgs[*]}; do
+ p="${p//-[0-9.]*/}"
+ for existing in ${result[*]}; do
+ if [[ "$existing" == "$p" ]]; then
+ continue 2
+ fi
+ done
+ result=( "${result[@]}" "${p}" )
+ done
+ fi
+
+ # include all pkg-ids if requested
+ if [[ $withIds == "yes" ]]; then
+ result=( "${result[@]}" "${pkgs[@]}" )
+ fi
+
+ # we are finished, echo the result
+ echo "${result[*]}"
+
+ # happy ending
+ return 0
+}
+
+_ghc-pkg()
+{
+ local cur
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ COMPREPLY=()
+
+ local actions flags
+ actions='register update unregister expose hide list latest describe field'
+ dbflags="--user \
+ --global \
+ -f --package-conf= \
+ --global-conf="
+ registerflags="--force \
+ -g --auto-ghci-libs \
+ -D --define-name="
+ listflags="--simple-output"
+ flags="$dbflags \
+ $registerflags \
+ $listflags \
+ -? --help \
+ -V --version"
+
+ # if it's the users first word; complete it and return
+ if (($COMP_CWORD == 1)); then
+ COMPREPLY=( $( compgen -W "$actions $flags" -- $cur ) )
+ return 0
+ fi
+
+ # now we know we have at least one word written
+
+ local action="unknown" \
+ prev numwords \
+ cword act
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ numwords=${#COMP_WORDS[@]}
+
+ # find the action with O(n*m) algorithm
+ # where n = ${#COMP_WORDS[*]}
+ # m = number of actions
+ for cword in ${COMP_WORDS[*]}; do
+ for act in $actions; do
+ if [[ "$cword" == "$act" ]]; then
+ action=$cword
+ fi
+ done
+ done
+
+ case $action in
+ register|update)
+ # we want to complete both flags and paths, how?
+ # we do it by checking if the user has started to write a flag
+ # or a path, and then decide what to complete.
+ # that is, to complete a flag, the user must start to write a '-'
+ if [[ "$cur" == -* ]]; then
+ # (we assume) it's the start of a flag
+ # set COMPREPLY to flags relevant to these actions
+ COMPREPLY=( $( compgen -W "$dbflags $registerflags" -- $cur ) )
+ fi
+ ;;
+ unregister|expose|hide|list|describe)
+ # all these actions can be completed with exactly one argument,
+ # a pkg-id.
+ COMPREPLY=( $( compgen -W "$dbflags" -- $cur ) )
+
+ # add special flags for some actions
+ if [[ "$action" == "list" ]]; then
+ COMPREPLY+=( $( compgen -W "$listflags" -- $cur ) )
+ fi
+
+ COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkgs include-ids )" -- $cur ) )
+ ;;
+ latest)
+ # complete only packages, not package ids
+ COMPREPLY=( $( compgen -W "$( _ghc-pkg-pkgs include-pkgs )" -- $cur ) )
+ ;;
+ field)
+ # we should always complete on the flags...
+ COMPREPLY=( $( compgen -W "$dbflags" -- $cur ) )
+
+ # then, we should either complete the package name or the field
+ # lets find out which one
+
+ # find the number of words in COMP_WORDS before COMP_CWORD that
+ # isn't flags. it should be 2 or 3 for us to complete it,
+ # exactly 2 if we should complete the package name
+ # exactly 3 if we should complete the field name
+ # otherwise, don't do any additional completion except the
+ # flags
+
+ # count the number of non flags up till the current word
+ local numnonflags=0 lastword i
+ for (( i=0 ; $i < $COMP_CWORD ; i++ )); do
+ if [[ ${COMP_WORDS[$i]} != -* ]]; then
+ lastword=${COMP_WORDS[$i]}
+ numnonflags=$(( ++numnonflags ))
+ fi
+ done
+
+ case $numnonflags in
+ 2)
+ # complete on pkg-ids
+ COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkgs include-ids )" -- $cur ) ) ;;
+ 3)
+ # complete on fields
+ COMPREPLY+=( $( compgen -W "$( _ghc-pkg-pkg-fields $lastword )" -- $cur ) ) ;;
+ esac
+ ;;
+ *)
+ # unknown action, not yet given by the user
+ # return all possible completions
+ COMPREPLY=( $( compgen -W "$actions $flags" -- $cur ) )
+ ;;
+ esac
+}
+
+complete -F _ghc-pkg -o default ghc-pkg
+
+# vim: set ft=sh tw=80 sw=4 et :
diff --git a/dev-lang/ghc/files/terminfo-0.3.2.5-tinfo.patch b/dev-lang/ghc/files/terminfo-0.3.2.5-tinfo.patch
new file mode 100644
index 000000000000..ca10da2e03ae
--- /dev/null
+++ b/dev-lang/ghc/files/terminfo-0.3.2.5-tinfo.patch
@@ -0,0 +1,25 @@
+http://bugs.gentoo.org/454216
+
+Mon Jan 7 16:34:47 FET 2013 Judah Jacobson <judah.jacobson@gmail.com>
+ * Search for terminfo in libtinfo; fixes GHC #7281.
+
+ Patch from Paul Johnson.
+diff -rN -u old-terminfo/configure.ac new-terminfo/configure.ac
+--- old-terminfo/configure.ac 2013-02-14 00:16:11.816111434 +0300
++++ new-terminfo/configure.ac 2013-02-14 00:16:11.819111434 +0300
+@@ -39,10 +39,11 @@
+ TERMINFO_INCLUDES="$CursesIncludes term.h"
+ fi
+
+-AC_CHECK_LIB(ncursesw, setupterm, HaveLibCurses=YES; LibCurses=ncursesw,
+- [AC_CHECK_LIB(ncurses, setupterm, HaveLibCurses=YES; LibCurses=ncurses,
+- [AC_CHECK_LIB(curses, setupterm, HaveLibCurses=YES; LibCurses=curses,
+- HaveLibCurses=NO; LibCurses=not-installed)])])
++AC_CHECK_LIB(tinfo, setupterm, HaveLibCurses=YES; LibCurses=tinfo,
++ [AC_CHECK_LIB(ncursesw, setupterm, HaveLibCurses=YES; LibCurses=ncursesw,
++ [AC_CHECK_LIB(ncurses, setupterm, HaveLibCurses=YES; LibCurses=ncurses,
++ [AC_CHECK_LIB(curses, setupterm, HaveLibCurses=YES; LibCurses=curses,
++ HaveLibCurses=NO; LibCurses=not-installed)])])])
+
+ if test "x$HaveLibCurses" = "xNO" ; then
+ AC_MSG_FAILURE([curses library not found, so this package cannot be built])