From 33d3ce8c835739a1897900921b827b998159dafc Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Tue, 12 Aug 2014 10:03:01 +0200 Subject: [PATCH] Compile with GHC 7.8.3 Fixes #31 --- CHANGELOG-bin.md | 4 ++++ clash-ghc.cabal_ | 2 +- src-bin/Main.hs | 34 ++++++++++++++++++++++++++++++++++ src-bin/hschooks.c | 12 ++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-bin.md b/CHANGELOG-bin.md index a65edb7618..76f114c094 100644 --- a/CHANGELOG-bin.md +++ b/CHANGELOG-bin.md @@ -1,5 +1,9 @@ # Changelog for the [`clash-ghc`](http://hackage.haskell.org/package/clash-ghc) package +## 0.3.3 *August 12th 2014* +* Fixes bugs: + * Compile with GHC 7.8.3 [#31](https://github.com/christiaanb/clash2/issues/31) + ## 0.3.2 *June 5th 2014* * Fixes bugs: diff --git a/clash-ghc.cabal_ b/clash-ghc.cabal_ index c7ccee5062..af8905d1b4 100644 --- a/clash-ghc.cabal_ +++ b/clash-ghc.cabal_ @@ -1,5 +1,5 @@ Name: clash-ghc -Version: 0.3.2 +Version: 0.3.3 Synopsis: CAES Language for Synchronous Hardware Description: CλaSH (pronounced ‘clash’) is a functional hardware description language that diff --git a/src-bin/Main.hs b/src-bin/Main.hs index ebfb775f83..b3b55b0b9c 100644 --- a/src-bin/Main.hs +++ b/src-bin/Main.hs @@ -127,6 +127,9 @@ getDefPrimDir = getDataFileName "primitives" main :: IO () main = do +#if MIN_VERSION_ghc(7,8,3) + initGCStatistics +#endif hSetBuffering stdout LineBuffering hSetBuffering stderr LineBuffering GHC.defaultErrorHandler defaultFatalMessager defaultFlushOut $ do @@ -625,7 +628,11 @@ mode_flags = , Flag "M" (PassFlag (setMode doMkDependHSMode)) , Flag "E" (PassFlag (setMode (stopBeforeMode anyHsc))) , Flag "C" (PassFlag (setMode (stopBeforeMode HCc))) +#if MIN_VERSION_ghc(7,8,3) + , Flag "S" (PassFlag (setMode (stopBeforeMode (As False)))) +#else , Flag "S" (PassFlag (setMode (stopBeforeMode As))) +#endif , Flag "-make" (PassFlag (setMode doMakeMode)) , Flag "-interactive" (PassFlag (setMode doInteractiveMode)) , Flag "-abi-hash" (PassFlag (setMode doAbiHashMode)) @@ -693,7 +700,12 @@ doMake srcs = do haskellish (f,Nothing) = looksLikeModuleName f || isHaskellUserSrcFilename f || '.' `notElem` f haskellish (_,Just phase) = +#if MIN_VERSION_ghc(7,8,3) + phase `notElem` [ As True, As False, Cc, Cobjc, Cobjcpp, CmmCpp, Cmm + , StopLn] +#else phase `notElem` [As, Cc, Cobjc, Cobjcpp, CmmCpp, Cmm, StopLn] +#endif hsc_env <- GHC.getSession @@ -900,3 +912,25 @@ unknownFlagsErr fs = throwGhcException $ UsageError $ concatMap oneError fs (case fuzzyMatch f (nub allFlags) of [] -> "" suggs -> "did you mean one of:\n" ++ unlines (map (" " ++) suggs)) + +{- Note [-Bsymbolic and hooks] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-Bsymbolic is a flag that prevents the binding of references to global +symbols to symbols outside the shared library being compiled (see `man +ld`). When dynamically linking, we don't use -Bsymbolic on the RTS +package: that is because we want hooks to be overridden by the user, +we don't want to constrain them to the RTS package. +Unfortunately this seems to have broken somehow on OS X: as a result, +defaultHooks (in hschooks.c) is not called, which does not initialize +the GC stats. As a result, this breaks things like `:set +s` in GHCi +(#8754). As a hacky workaround, we instead call 'defaultHooks' +directly to initalize the flags in the RTS. +A biproduct of this, I believe, is that hooks are likely broken on OS +X when dynamically linking. But this probably doesn't affect most +people since we're linking GHC dynamically, but most things themselves +link statically. +-} +#if MIN_VERSION_ghc(7,8,3) +foreign import ccall safe "initGCStatistics" + initGCStatistics :: IO () +#endif diff --git a/src-bin/hschooks.c b/src-bin/hschooks.c index ec89537044..873706a6ed 100644 --- a/src-bin/hschooks.c +++ b/src-bin/hschooks.c @@ -15,6 +15,18 @@ in instead of the defaults. #include #endif +void +initGCStatistics(void) +{ + /* Workaround for #8754: if the GC stats aren't enabled because the + compiler couldn't use -Bsymbolic to link the default hooks, then + initialize them sensibly. See Note [-Bsymbolic and hooks] in + Main.hs. */ + if (RtsFlags.GcFlags.giveStats == NO_GC_STATS) { + RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS; + } +} + void defaultsHook (void) {