Commit 9e133b9d authored by thoughtpolice's avatar thoughtpolice
Browse files

Make sure -fcmm-sink is passed to Parser properly

Parser.hs needs to be compiled with -fcmm-sink on x86 platforms, so the
register allocator doesn't run out of stack slots. Previously, we had to
do some CPP hacks in order to emit an #ifdef into the file - this is
because we preprocess it once up front, and run the preprocessor again
when we compile it.

There's two cases: the boostrap compiler is > 7.8, and the stage1 parser
needs the flag, or the stage1 compiler is compiling the stage2
Parser.hs, and needs the flag..

The previous approach was super fragile with Clang. The more principled
fix is to instead do this through the build system.

This fixes #8182.
Signed-off-by: thoughtpolice's avatarAustin Seipp <>
parent ba576e55
......@@ -341,8 +341,23 @@ else
compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
ifeq "$(GhcProfiled)" "YES"
# If we're bootstrapping the compiler during stage2, or we're being
# built by a GHC whose version is > 7.8, we need -fcmm-sink to be
# passed to the compiler. This is required on x86 to avoid the
# register allocator running out of stack slots when compiling this
# module with -fPIC -dynamic.
compiler/stage1/build/Parser_HC_OPTS += -fcmm-sink
# However, we may be using e.g. 7.6, and thus the bootstrap compiler
# does not need to pass -fcmm-sink, but stage1+ does!
# We pass -fcmm-sink to every stage != 1
# See #8182 for all the details
compiler/stage2/build/Parser_HC_OPTS += -fcmm-sink
compiler/stage3/build/Parser_HC_OPTS += -fcmm-sink
ifeq "$(GhcProfiled)" "YES"
# If we're profiling GHC then we want SCCs. However, adding -auto-all
# everywhere tends to give a hard-to-read profile, and adds lots of
# overhead. A better approach is to proceed top-down; identify the
......@@ -24,24 +24,6 @@ to inline certain key external functions, so we instruct GHC not to
throw away inlinings as it would normally do in -O0 mode.
-- CPP tricks because we want the directives in the output of the
-- first CPP pass.
-- Clang note, 6/17/2013 by aseipp: It is *extremely* important (for
-- some reason) that there be a line of whitespace between the two
-- definitions here, and the subsequent use of __IF_GHC_77__ - this
-- seems to be a bug in clang or something, where having the line of
-- whitespace will make the preprocessor correctly format the rendered
-- lines in the 'two step' CPP pass. No, this is not a joke.
#define __IF_GHC_77__ #if __GLASGOW_HASKELL__ >= 707
#define __ENDIF__ #endif
-- Required on x86 to avoid the register allocator running out of
-- stack slots when compiling this module with -fPIC -dynamic.
{-# OPTIONS_GHC -fcmm-sink #-}
module Parser ( parseModule, parseStmt, parseIdentifier, parseType,
parseHeader ) where
......@@ -156,6 +156,12 @@ FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[7.5],
# GHC 7.7+ needs -fcmm-sink when compiling Parser.hs. See #8182
# GHC is passed to Cabal, so we need a native path
if test "${WithGhc}" != ""
......@@ -471,6 +471,8 @@ endif
# C compiler
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