Commit c72e8898 authored by Austin Seipp's avatar Austin Seipp

Fix #8754 again.

This time, we carefully initialize the GC stats only if they're not
already initialized - this way the user can override them (e.g. `+RTS -t
--machine-readable`).
Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 5a576754
{-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-}
{-# LANGUAGE ForeignFunctionInterface #-}
-----------------------------------------------------------------------------
--
......@@ -76,6 +77,7 @@ import Data.Maybe
main :: IO ()
main = do
initGCStatistics -- See Note [-Bsymbolic and hooks]
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering
GHC.defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
......@@ -818,3 +820,26 @@ 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.
-}
foreign import ccall safe "initGCStatistics"
initGCStatistics :: IO ()
......@@ -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)
{
......@@ -28,7 +40,8 @@ defaultsHook (void)
#endif
RtsFlags.GcFlags.maxStkSize = 512*1024*1024 / sizeof(W_);
RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
initGCStatistics();
// See #3408: the default idle GC time of 0.3s is too short on
// Windows where we receive console events once per second or so.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment