Profiled GHC flavour segfaults when building a target project with TH or GHC plugin
Summary
When I use GHC built with the profiled_ghc
flavour, GHC segfaults when it compiles a target code with TH or with a GHC plugin (with profiling on for the target project).
The segfaults happened in most of time on my machine, but sometimes it passes, so the error happens nondeterministically.
With a smaller probability, it sometimes leads to GHC internal errors showing this is related to code relocation on linking:
ghc: internal error: Relocation out of range for SUBTRACTOR
By the way, this problem happens almost in building many of dependency packages that use TH or GHC plugins in a big private project with library_profiling: True
.
Steps to reproduce
I made a sample project here: https://gist.github.com/wavewave/97c802cb80aecf8146a7d5af21cf4bf1
and one can reproduce it by the following build command:
$ cabal build --project-file=ghcHEAD-cabal-profiledGHC.project
Build profile: -w ghc-9.9.20240115 -O0
In order, the following will be built (use -v for more details):
- myfailure-2.11.0 (lib) (file MyFailure.hs changed)
Preprocessing library for myfailure-2.11.0..
Building library for myfailure-2.11.0..
<no location info>: warning: [GHC-42258] [-Wunused-packages]
The following packages were specified via -package or -package-id flags,
but were not needed for compilation:
- bytestring-0.12.0.2 (exposed by flag -package-id bytestring-0.12.0.2-inplace)
- http-conduit-2.3.8.3 (exposed by flag -package-id http-cndt-2.3.8.3-68b1c994)
- microlens-0.4.13.1 (exposed by flag -package-id mcrlns-0.4.13.1-4239c11e)
- aeson-2.2.0.0 (exposed by flag -package-id sn-2.2.0.0-921d37e9)
[1 of 1] Compiling MyFailure ( MyFailure.hs, /Users/ianwookim/tmp/profiledGHC/hoauth2-2.11.0/dist-newstyle/build/aarch64-osx/ghc-9.9.20240115/myfailure-2.11.0/noopt/build/MyFailure.o ) [Source file changed]
Error: cabal: Failed to build myfailure-2.11.0. The build process segfaulted
(i.e. SIGSEGV).
Note that I intentionally add redundant deps. When I remove one of those deps, the probability of the segfaults got reduced. (probably, another indicator that this bug is related to code relocation offset amount)
Expected behavior
Segfault should not happen in any case. If something is wrong (such as linker couldn't find some symbols etc), it should show that error.
Environment
- GHC version used: GHC master, 9.9.20240115 version (
da908790670cd5161cffc3d83757fb8048bdafda
)
Optional:
- Operating System: macOS Sonoma 14.2.1
- System Architecture: Apple M1 Max (AArch64)