Commit 9e133b9d authored by thoughtpolice's avatar thoughtpolice

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 <aseipp@pobox.com>
parent ba576e55
......@@ -341,8 +341,23 @@ else
compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
endif
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.
ifeq "$(CMM_SINK_BOOTSTRAP_IS_NEEDED)" "YES"
compiler/stage1/build/Parser_HC_OPTS += -fcmm-sink
endif
# 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
__IF_GHC_77__
-- Required on x86 to avoid the register allocator running out of
-- stack slots when compiling this module with -fPIC -dynamic.
{-# OPTIONS_GHC -fcmm-sink #-}
__ENDIF__
module Parser ( parseModule, parseStmt, parseIdentifier, parseType,
parseHeader ) where
......
......@@ -156,6 +156,12 @@ FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[7.5],
GHC_PACKAGE_DB_FLAG=package-db)
AC_SUBST(GHC_PACKAGE_DB_FLAG)
# GHC 7.7+ needs -fcmm-sink when compiling Parser.hs. See #8182
FP_COMPARE_VERSIONS([$GhcVersion],[-gt],[7.7],
CMM_SINK_BOOTSTRAP_IS_NEEDED=YES,
CMM_SINK_BOOTSTRAP_IS_NEEDED=NO)
AC_SUBST(CMM_SINK_BOOTSTRAP_IS_NEEDED)
# GHC is passed to Cabal, so we need a native path
if test "${WithGhc}" != ""
then
......
......@@ -471,6 +471,8 @@ endif
GHC_PACKAGE_DB_FLAG = @GHC_PACKAGE_DB_FLAG@
CMM_SINK_BOOTSTRAP_IS_NEEDED = @CMM_SINK_BOOTSTRAP_IS_NEEDED@
#-----------------------------------------------------------------------------
# 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