StaticPtr related linker error
I often encounter a difficult-to-localize linker error that occurs in conjunction with the use of StaticPointers. The error can go away or reappear after simple code transformations that should be trivial, like for example replacing
\(_,_) -> undefined with
\_ -> undefined.
Steps to reproduce
This git repository:
contains the smallest program I could make that exhibits the error. Tiny changes that shouldn't matter can make the error go away, and for this reason I have been unable to shrink the code further. You should be able to clone and run
stack build to see the issue.
When I run
stack build, I see the output
.stack-work/dist/x86_64-linux/Cabal-18.104.22.168/build/linker-error-exec/linker-error-exec-tmp/Main.o:ghc_5.c:function hs_spt_init_Main: error: undefined reference to 'rcs4_closure' collect2: error: ld returned 1 exit status `gcc' failed in phase `Linker'. (Exit code: 1) -- While building custom Setup.hs for package static-ptr-linker-error-0.1.0.0 using: /central/home/dssimmon/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_22.214.171.124_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-126.96.36.199 build exe:linker-error-exec --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always" Process exited with code: ExitFailure 1
One can make the code compile by making small changes, for example
closure = undefined
\(_,_) -> undefinedwith
\_ -> undefinedin line 83
- replacing other subexpressions with
applyRemoteStatic k a = k 'bindRemoteStatic' awith
applyRemoteStatic = bindRemoteStaticin line 47 (those are supposed to be backticks, but I can't figure out how to escape them)
- turning on -O2
- many other ways
- GHC version used: 8.2.2 (via lts-11.13, listed in stack.yaml)
I have also observed this issue with GHC 8.4.4 (lts-12.18).
- Operating System:
- System Architecture: