Skip to content

Commit

Permalink
Merge pull request #2572 from clash-lang/workaround-mmap-bug-everywhere
Browse files Browse the repository at this point in the history
Enable ghc mmap crash workaround for every ghc compiled binary
  • Loading branch information
leonschoorl authored Sep 6, 2023
2 parents f645746 + 9b62e21 commit 8ec6e24
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ if [[ "$GHC_HEAD" != "yes" ]]; then
fi
set -u

cabal v2-build clash-prelude --write-ghc-environment-files=always
# Undo mmap crash workaround for clash-cosim, see PR #2572.
# It uses a custom setup, which can't be linked with -rtsopts
GHCRTS="" cabal v2-build clash-cosim --write-ghc-environment-files=always

# Build with default constraints
cabal v2-build all --write-ghc-environment-files=always

Expand Down
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
7 changes: 7 additions & 0 deletions .ci/clash-ffi-example-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -xeu

# See PR #2572. Undo mmap crash workaround for clash-ffi-example.
cd clash-ffi/example
cabal build clash-ffi
GHCRTS="" cabal build clash-ffi-example
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: 4 additions & 0 deletions .ci/gitlab/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ stages:
- export CABAL_DIR=$HOME/.cabal
- export clash_lib_datadir=$(pwd)/clash-lib/
- export clash_cosim_datadir=$(pwd)/clash-cosim/
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then export GHCRTS="-xm20000000"; fi
- export
- tar -xf dist.tar.zst -C /

Expand All @@ -50,6 +51,7 @@ stages:
- export CABAL_DIR=$HOME/.cabal
- export clash_lib_datadir=$(pwd)/clash-lib/
- export clash_cosim_datadir=$(pwd)/clash-cosim/
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then export GHCRTS="-xm20000000"; fi
- export
- tar -xf cache.tar.zst -C / || true
- tar -xf dist.tar.zst -C /
Expand Down Expand Up @@ -167,6 +169,7 @@ ffi:example:
- export clash_cosim_datadir=$(pwd)/clash-cosim/
- export MASKBINS="$(mktemp -d)"
- PATH="$MASKBINS:$PATH"
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then export GHCRTS="-xm20000000"; fi
- export
- tar -xf cache.tar.zst -C / || true
# The iverilog on CI cannot run the example, we only test it builds
Expand All @@ -177,6 +180,7 @@ ffi:example:
# Make sure we get custom cabals setting in the clash-example project too
- cp cabal.project.local clash-ffi/example
script:
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then ./.ci/clash-ffi-example-build.sh; fi
- cd clash-ffi/example && ./run-iverilog.sh
after_script:
- tar -cf - /root/.cabal | zstd -T${THREADS} -3 > cache.tar.zst
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
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ nix-build:
needs: []
stage: test
before_script:
- if [[ "$WORKAROUND_GHC_MMAP_CRASH" == "yes" ]]; then export GHCRTS="-xm20000000"; fi
- nix-env -i gawk
script:
- nix-build -j$(./.ci/effective_cpus.sh)
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
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# We pick a single version of GHC to use by default within nix. This is
# probably cleaner than always having N copies of each package / app and
# being forced to refer to them by their GHC version.
defaultGhcVersion = "ghc902";
defaultGhcVersion = "ghc961";

# Overlays are not per-system, so let's only compute them once.
# For each version of GHC we produce a `pkgs.clashPackages-ghcVER`, e.g.
Expand Down
13 changes: 5 additions & 8 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,10 +135,9 @@ let
};

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

clash-prelude-hedgehog =
Expand Down Expand Up @@ -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
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
4 changes: 1 addition & 3 deletions tests/src/Test/Tasty/Clash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ instance IsTest ClashBinaryTest where
, "-o", oDir </> "out"
, "-i" <> cbSourceDirectory
, "-outputdir", oDir
, "-rtsopts"
] <> cbExtraBuildArgs <>
[ cbSourceDirectory </> cbModName <.> "hs"
]
Expand Down Expand Up @@ -577,9 +578,6 @@ clashLibTest' modName target extraGhcArgs path =
-- the linker to shut up and continue producing an executable, as the
-- undefined references will not be an issue at run-time.
"-optl" : "-Wl,--allow-shlib-undefined" :
#endif
#ifdef CLASH_WORKAROUND_GHC_MMAP_CRASH
"-with-rtsopts=-xm20000000" :
#endif
extraGhcArgs
, cbExtraExecArgs=[]
Expand Down

0 comments on commit 8ec6e24

Please sign in to comment.