Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
leonschoorl committed Aug 29, 2023
1 parent 9b9cf4d commit c8513c8
Showing 15 changed files with 27 additions and 63 deletions.
5 changes: 2 additions & 3 deletions .ci/cabal.project.local
Original file line number Diff line number Diff line change
@@ -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

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

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

package clash-cosim
ghc-options: -Werror
@@ -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
1 change: 1 addition & 0 deletions .ci/gitlab/common.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions benchmark/profiling/prepare/clash-profiling-prepare.cabal
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
4 changes: 2 additions & 2 deletions benchmark/profiling/run/clash-profiling.cabal
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
4 changes: 2 additions & 2 deletions clash-cores/clash-cores.cabal
Original file line number Diff line number Diff line change
@@ -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

@@ -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)
2 changes: 1 addition & 1 deletion clash-cosim/clash-cosim.cabal
Original file line number Diff line number Diff line change
@@ -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
@@ -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
14 changes: 1 addition & 13 deletions clash-ghc/clash-ghc.cabal
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions clash-lib/clash-lib.cabal
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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)
@@ -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)
16 changes: 3 additions & 13 deletions clash-prelude/clash-prelude.cabal
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
@@ -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)
@@ -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
2 changes: 1 addition & 1 deletion clash-term/clash-term.cabal
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 5 additions & 8 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -101,10 +101,9 @@ let
clash-ghc =
let
unmodified =
hprev.callCabal2nixWithOptions
hprev.callCabal2nix
"clash-ghc"
../clash-ghc
"--flag workaround-ghc-mmap-crash" {
../clash-ghc {
inherit (hfinal) clash-lib clash-prelude;
};
in
@@ -136,10 +135,9 @@ let
};

clash-prelude =
hprev.callCabal2nixWithOptions
hprev.callCabal2nix
"clash-prelude"
../clash-prelude
"--flag workaround-ghc-mmap-crash"
{ };

clash-prelude-hedgehog =
@@ -188,10 +186,9 @@ let
clash-testsuite =
let
unmodified =
hprev.callCabal2nixWithOptions
hprev.callCabal2nix
"clash-testsuite"
../tests
"--flag workaround-ghc-mmap-crash" {
../tests {
inherit (hfinal) clash-cores clash-ghc clash-lib clash-prelude;
};
in
10 changes: 1 addition & 9 deletions tests/clash-testsuite.cabal
Original file line number Diff line number Diff line change
@@ -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
@@ -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:
@@ -145,6 +136,7 @@ library
executable clash-testsuite
import: basic-config
main-is: Main.hs
ghc-options: -rtsopts

build-tool-depends:
clash-ghc:clash

0 comments on commit c8513c8

Please sign in to comment.