Skip to content

Commit

Permalink
Enable ghc mmap crash workaround for every ghc compiled binary
Browse files Browse the repository at this point in the history
In PRs #2444 we added the workaround-ghc-mmap-crash flag on
some of our packages.
That flag added `-with-rtsopts=-xm20000000` to some of our binaries.

But other binaries would occasionally still trigger the mmap bug,
most importantly ghc itself.

This commit undoes the previous way of applying the workaround and
applies the same `-xm20000000` RTS option everywhere
via the GHCRTS environment variable.

But for this to work we have to link all binaries with the `-rtsopts`
flag, otherwise they'll just ignore the GHCRTS.
  • Loading branch information
leonschoorl committed Aug 29, 2023
1 parent 9b9cf4d commit bfc677a
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 60 deletions.
5 changes: 2 additions & 3 deletions .ci/cabal.project.local
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package *

package clash-prelude
ghc-options: -Werror
flags: +doctests +multiple-hidden -workaround-ghc-mmap-crash
flags: +doctests +multiple-hidden
tests: True
benchmarks: True

Expand All @@ -24,7 +24,6 @@ package clash-lib

package clash-ghc
ghc-options: -Werror
flags: -workaround-ghc-mmap-crash

package clash-cosim
ghc-options: -Werror
Expand All @@ -48,7 +47,7 @@ package clash-lib-hedgehog
package clash-testsuite
ghc-options: -Werror
-- enable cosim
flags: +cosim +multiple-hidden -workaround-ghc-mmap-crash
flags: +cosim +multiple-hidden

package clash-benchmark
ghc-options: -Werror
Expand Down
1 change: 1 addition & 0 deletions .ci/gitlab/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- export THREADS=$(./.ci/effective_cpus.sh)
- export CABAL_JOBS=$(./.ci/effective_cpus.sh)
- export CABAL_DIR=$HOME/.cabal
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then export GHCRTS="-xm20000000"; fi
- export
- tar -xf cache.tar.zst -C / || true
- .ci/setup.sh
Expand Down
4 changes: 0 additions & 4 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ if [ ! -f cabal.project.local ]; then
fi

set +u
if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then
sed -i 's/-workaround-ghc-mmap-crash/+workaround-ghc-mmap-crash/g' cabal.project.local
fi

if [[ "$GHC_HEAD" == "yes" ]]; then
cat .ci/cabal.project.local.append-HEAD >> cabal.project.local
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
CABAL_JOBS: 2
MULTIPLE_HIDDEN: ${{ matrix.multiple_hidden }}
CI_COMMIT_BRANCH: ${{ github.base_ref }}
WORKAROUND_GHC_MMAP_CRASH: ${{ matrix.workaround_ghc_mmap_crash }}
GHCRTS: ${{ fromJSON('["","-xm20000000"]')[matrix.workaround_ghc_mmap_crash == 'yes'] }}

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions benchmark/profiling/prepare/clash-profiling-prepare.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ library
executable clash-profile-normalization-prepare
main-is: profile-normalization-prepare.hs
default-language: Haskell2010
ghc-options: -Wall -Wcompat
ghc-options: -Wall -Wcompat -rtsopts
build-depends: base,
binary,
bytestring,
Expand All @@ -38,7 +38,7 @@ executable clash-profile-normalization-prepare
executable clash-profile-netlist-prepare
main-is: profile-netlist-prepare.hs
default-language: Haskell2010
ghc-options: -Wall -Wcompat
ghc-options: -Wall -Wcompat -rtsopts
build-depends: base,
binary,
bytestring,
Expand Down
4 changes: 2 additions & 2 deletions benchmark/profiling/run/clash-profiling.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cabal-version: >=1.10
executable clash-profile-normalization-run
main-is: profile-normalization-run.hs
default-language: Haskell2010
ghc-options: -O2 -Wall -Wcompat
ghc-options: -O2 -Wall -Wcompat -rtsopts
build-depends: base,
binary,
bytestring,
Expand All @@ -30,7 +30,7 @@ executable clash-profile-normalization-run
executable clash-profile-netlist-run
main-is: profile-netlist-run.hs
default-language: Haskell2010
ghc-options: -O2 -Wall -Wcompat
ghc-options: -O2 -Wall -Wcompat -rtsopts
build-depends: base,
binary,
bytestring,
Expand Down
4 changes: 2 additions & 2 deletions clash-cores/clash-cores.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test-suite unittests
hs-source-dirs: test
type: exitcode-stdio-1.0
main-is: unittests.hs

ghc-options: -rtsopts
if !flag(unittests)
buildable: False

Expand Down Expand Up @@ -196,7 +196,7 @@ test-suite doctests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: doctests.hs
ghc-options: -Wall -Wcompat -threaded
ghc-options: -Wall -Wcompat -threaded -rtsopts
hs-source-dirs: test

if !flag(doctests)
Expand Down
2 changes: 1 addition & 1 deletion clash-cosim/clash-cosim.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ test-suite test
tasty-hunit,
tasty-quickcheck,
template-haskell
ghc-options: -Wall -Wcompat
ghc-options: -Wall -Wcompat -rtsopts
if flag(pedantic)
ghc-options: -Werror
1 change: 1 addition & 0 deletions clash-ffi/clash-ffi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ executable ffi-interface-tests
ExistentialQuantification
hs-source-dirs: tests
main-is: Main.hs
ghc-options: -rtsopts
other-modules:
Clash.FFI.Test
Clash.FFI.Test.Instances
Expand Down
14 changes: 1 addition & 13 deletions clash-ghc/clash-ghc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,12 @@ flag use-ghc-paths
default: False
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

executable clash
Main-Is: src-ghc/Batch.hs
Build-Depends: base, clash-ghc
GHC-Options: -Wall -Wcompat -threaded -rtsopts
GHC-Options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-A128m
if flag(dynamic)
GHC-Options: -dynamic
-- Note that multiple -with-rtsopts are not cumulative, so we can't add the
-- common RTS options in the unconditional GHC-Options
if flag(workaround-ghc-mmap-crash)
GHC-Options: "-with-rtsopts=-A128m -xm20000000"
else
GHC-Options: -with-rtsopts=-A128m
extra-libraries: pthread
default-language: Haskell2010

Expand Down
8 changes: 4 additions & 4 deletions clash-lib/clash-lib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ executable v16-upgrade-primitives
directory,
stringsearch,
Glob
GHC-Options: -Wall -Wcompat
GHC-Options: -Wall -Wcompat -rtsopts
default-language: Haskell2010

executable static-files
Expand All @@ -352,7 +352,7 @@ executable static-files
extra,
filepath
Other-Modules: Paths_clash_lib
GHC-Options: -Wall -Wcompat
GHC-Options: -Wall -Wcompat -rtsopts
default-language: Haskell2010
if impl(ghc >= 9.2.0)
buildable: False
Expand All @@ -362,7 +362,7 @@ test-suite doctests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: doctests.hs
ghc-options: -Wall -Wcompat -threaded
ghc-options: -Wall -Wcompat -threaded -rtsopts
hs-source-dirs: tests

if !flag(doctests)
Expand All @@ -379,7 +379,7 @@ test-suite unittests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: unittests.hs
ghc-options: -Wall -Wcompat -threaded -with-rtsopts=-N
ghc-options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-N
hs-source-dirs: tests

if !flag(unittests)
Expand Down
16 changes: 3 additions & 13 deletions clash-prelude/clash-prelude.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ flag benchmarks
default: True
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

common common-options
default-language: Haskell2010
default-extensions: BangPatterns
Expand Down Expand Up @@ -376,7 +370,7 @@ test-suite doctests
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: doctests.hs
ghc-options: -Wall -Wcompat -threaded
ghc-options: -Wall -Wcompat -threaded -rtsopts
hs-source-dirs: tests

if !flag(doctests)
Expand All @@ -388,15 +382,11 @@ test-suite doctests
doctest-parallel >= 0.2 && < 0.4,
filepath

if flag(workaround-ghc-mmap-crash)
ghc-options: -with-rtsopts=-xm20000000


test-suite unittests
import: common-options
type: exitcode-stdio-1.0
main-is: unittests.hs
ghc-options: -Wall -Wcompat -threaded -with-rtsopts=-N
ghc-options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-N
hs-source-dirs: tests

if !flag(unittests)
Expand Down Expand Up @@ -462,7 +452,7 @@ benchmark benchmark-clash-prelude
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: benchmark-main.hs
ghc-options: -O2 -Wall
ghc-options: -O2 -Wall -rtsopts
hs-source-dirs: benchmarks

ghc-options: -with-rtsopts=-T
Expand Down
2 changes: 1 addition & 1 deletion clash-term/clash-term.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ executable clash-term
bytestring >= 0.10.0.2 && < 0.12,
rewrite-inspector == 0.1.0.11

GHC-Options: -Wall -Wcompat -threaded
GHC-Options: -Wall -Wcompat -threaded -rtsopts
extra-libraries: pthread
default-language: Haskell2010
if os(windows)
Expand Down
7 changes: 2 additions & 5 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ let
unmodified =
hprev.callCabal2nixWithOptions
"clash-ghc"
../clash-ghc
"--flag workaround-ghc-mmap-crash" {
../clash-ghc {
inherit (hfinal) clash-lib clash-prelude;
};
in
Expand Down Expand Up @@ -139,7 +138,6 @@ let
hprev.callCabal2nixWithOptions
"clash-prelude"
../clash-prelude
"--flag workaround-ghc-mmap-crash"
{ };

clash-prelude-hedgehog =
Expand Down Expand Up @@ -190,8 +188,7 @@ let
unmodified =
hprev.callCabal2nixWithOptions
"clash-testsuite"
../tests
"--flag workaround-ghc-mmap-crash" {
../tests {
inherit (hfinal) clash-cores clash-ghc clash-lib clash-prelude;
};
in
Expand Down
10 changes: 1 addition & 9 deletions tests/clash-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ flag multiple-hidden
default: True
manual: True

flag workaround-ghc-mmap-crash
description:
Only use this flag when hit by GHC bug #19421. See clash-compiler PR #2444.
default: False
manual: True

common basic-config
default-language: Haskell2010
ghc-options: -Wall -Wcompat
Expand Down Expand Up @@ -92,9 +86,6 @@ common basic-config
if flag(multiple-hidden)
cpp-options: -DCLASH_MULTIPLE_HIDDEN

if flag(workaround-ghc-mmap-crash)
cpp-options: -DCLASH_WORKAROUND_GHC_MMAP_CRASH

library
import: basic-config
hs-source-dirs:
Expand Down Expand Up @@ -145,6 +136,7 @@ library
executable clash-testsuite
import: basic-config
main-is: Main.hs
ghc-options: -rtsopts

build-tool-depends:
clash-ghc:clash
Expand Down

0 comments on commit bfc677a

Please sign in to comment.