Skip to content

foreign import in transitive module dependencies cause GHC to panic during TH compilation

Summary

I have a core module in a package that "foreign imports" several symbols defined in C code. This core module is (transitively) imported in modules that include Template Haskell splices. In this scenario the compiler panics with:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.10.7:
        Loading temp shared object failed: /tmp/ghc3868_0/libghc_55.so: undefined symbol: randomFun

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

cabal: Failed to build benchmark-analysis-0.9.0 (which is required by exe:Plot from benchmark-analysis-0.9.0, exe:Model from benchmark-analysis-0.9.0 and others).

Here, randomFun is one of the foreign imported C symbols from my core module. Presumably any C object files are not passed to the linker when generating the temporary TH library, causing it to fail on missing symbols.

Steps to reproduce

I can create a reproducer in my codebase, but that's an unhelpfully big 124 modules in size, I'm trying to get a smaller reproducer.

Expected behavior

What do you expect the reproducer described above to do?

Environment

  • GHC version used: 8.10.7

Optional:

  • Operating System: macOS & Linux
  • System Architecture: x64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information