RTS linker on Darwin segfaults on 8.10
Summary
I found this segfault when trying to load a module via the GHC API with the LinkInMemory
DynFlag option on Darwin.
The RTS crashes with this log that seems to be related to integer-gmp:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
* frame #0: 0x00000001031e5468 Main`relocateSection(oc=0x000000010570fd60, curSection=0) at MachO.c:680:40
frame #1: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x000000010570fd60) at MachO.c:1529:14
frame #2: 0x00000001031a2c97 Main`ocTryLoad(oc=0x000000010570fd60) at Linker.c:1666:9
frame #3: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmp_binvert_limb_table", pinfo=0x0000000105710240) at Linker.c:886:17
frame #4: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmp_binvert_limb_table") at Linker.c:866:16
frame #5: 0x00000001031e5ca6 Main`relocateSection(oc=0x00000001119594f0, curSection=0) at MachO.c:848:24
frame #6: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x00000001119594f0) at MachO.c:1529:14
frame #7: 0x00000001031a2c97 Main`ocTryLoad(oc=0x00000001119594f0) at Linker.c:1666:9
frame #8: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_pi1_bdiv_q_1", pinfo=0x0000000111959a10) at Linker.c:886:17
frame #9: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_pi1_bdiv_q_1") at Linker.c:866:16
frame #10: 0x00000001031e5ca6 Main`relocateSection(oc=0x000000011194ff00, curSection=0) at MachO.c:848:24
frame #11: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x000000011194ff00) at MachO.c:1529:14
frame #12: 0x00000001031a2c97 Main`ocTryLoad(oc=0x000000011194ff00) at Linker.c:1666:9
frame #13: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_toom_interpolate_16pts", pinfo=0x00000001119505f0) at Linker.c:886:17
frame #14: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_toom_interpolate_16pts") at Linker.c:866:16
frame #15: 0x00000001031e5ca6 Main`relocateSection(oc=0x0000000111948440, curSection=0) at MachO.c:848:24
frame #16: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x0000000111948440) at MachO.c:1529:14
frame #17: 0x00000001031a2c97 Main`ocTryLoad(oc=0x0000000111948440) at Linker.c:1666:9
frame #18: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_toom8h_mul", pinfo=0x0000000111948bb0) at Linker.c:886:17
frame #19: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_toom8h_mul") at Linker.c:866:16
frame #20: 0x00000001031e5ca6 Main`relocateSection(oc=0x0000000106331d10, curSection=0) at MachO.c:848:24
frame #21: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x0000000106331d10) at MachO.c:1529:14
frame #22: 0x00000001031a2c97 Main`ocTryLoad(oc=0x0000000106331d10) at Linker.c:1666:9
frame #23: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_mul_n", pinfo=0x0000000106332460) at Linker.c:886:17
frame #24: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_mul_n") at Linker.c:866:16
frame #25: 0x00000001031e5ca6 Main`relocateSection(oc=0x0000000111942f90, curSection=0) at MachO.c:848:24
frame #26: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x0000000111942f90) at MachO.c:1529:14
frame #27: 0x00000001031a2c97 Main`ocTryLoad(oc=0x0000000111942f90) at Linker.c:1666:9
frame #28: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_toom42_mul", pinfo=0x0000000111943740) at Linker.c:886:17
frame #29: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_toom42_mul") at Linker.c:866:16
frame #30: 0x00000001031e5ca6 Main`relocateSection(oc=0x0000000106330980, curSection=0) at MachO.c:848:24
frame #31: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x0000000106330980) at MachO.c:1529:14
frame #32: 0x00000001031a2c97 Main`ocTryLoad(oc=0x0000000106330980) at Linker.c:1666:9
frame #33: 0x00000001031a2b79 Main`loadSymbol(lbl="___gmpn_mul", pinfo=0x00000001063311f0) at Linker.c:886:17
frame #34: 0x00000001031a2a23 Main`lookupSymbol_(lbl="___gmpn_mul") at Linker.c:866:16
frame #35: 0x00000001031e5ca6 Main`relocateSection(oc=0x0000000105705e40, curSection=0) at MachO.c:848:24
frame #36: 0x00000001031e5185 Main`ocResolve_MachO(oc=0x0000000105705e40) at MachO.c:1529:14
frame #37: 0x00000001031a2c97 Main`ocTryLoad(oc=0x0000000105705e40) at Linker.c:1666:9
frame #38: 0x00000001031a3bb5 Main`resolveObjs_ at Linker.c:1719:13
frame #39: 0x00000001031a3b5d Main`resolveObjs at Linker.c:1738:15
frame #40: 0x0000000102eeb8b0 Main`ghcizm8zi10zi1_GHCiziObjLink_resolveObjs1_info + 24
Steps to reproduce
Please provide a set of concrete steps to reproduce the issue.
Given the program below
import GHC
main = runGhc (Just "/usr/local/opt/ghc/lib/ghc-8.10.1/") $ do
target <- guessTarget "Foo.hs" Nothing
df <- getSessionDynFlags
setSessionDynFlags $ df { ghcLink = LinkInMemory }
setTargets [target]
load LoadAllTargets
where Foo.hs is just
module Foo where
Running ghc -package ghc Main.hs && ./Main
will give the segfault above.
Expected behavior
The program does not segfault
Environment
- GHC version used: 8.10.1 installed from the Darwin binary distribution
This doesn't happen on Linux with 8.10.1, or Darwin with 8.8.3.
Compiling with -dynamic
fixes the segfault, as well as loading Main.hs from ghci
and then calling main
.
Optional:
- Operating System: macOS Darwin
- System Architecture: x86_64