Skip to content

Commit

Permalink
Compile with GHC 7.8.3
Browse files Browse the repository at this point in the history
Fixes #31
  • Loading branch information
christiaanb committed Aug 12, 2014
1 parent 0d40cc2 commit 33d3ce8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG-bin.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion clash-ghc.cabal_
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 34 additions & 0 deletions src-bin/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions src-bin/hschooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ in instead of the defaults.
#include <unistd.h>
#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)
{
Expand Down

0 comments on commit 33d3ce8

Please sign in to comment.