Skip to content

segfault in when including leveldb as library

Summary

Using leveldb as a native library leads to a segfault in interpreted code. I hit this behaviour in TemplateHaskell, but I believe this may be easier to debug.

Steps to reproduce

Using any Haskell-File, the following command will result in a segmentation fault:

% ghci -v -I/opt/homebrew/include -lleveldb -L/opt/homebrew/lib Test.hs                                                                                     :(
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Glasgow Haskell Compiler, Version 8.10.7, stage 2 booted by GHC version 8.10.7
*** initializing package database:
Using binary package database: /opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/package.conf.d/package.cache
package flags []
loading package database /opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.6.1
wired-in package integer-wired-in mapped to integer-gmp-1.0.3.0
wired-in package base mapped to base-4.14.3.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.16.0.0
wired-in package ghc mapped to ghc-8.10.7
!!! initializing package database: finished in 12.40 milliseconds, allocated 8.378 megabytes
*** initializing package database:
package flags []
loading package database /opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.6.1
wired-in package integer-wired-in mapped to integer-gmp-1.0.3.0
wired-in package base mapped to base-4.14.3.0
wired-in package rts mapped to rts-1.0.1
wired-in package template-haskell mapped to template-haskell-2.16.0.0
wired-in package ghc mapped to ghc-8.10.7
!!! initializing package database: finished in 9.64 milliseconds, allocated 3.278 megabytes
*** Desugar:
*** Simplify [expr]:
!!! Simplify [expr]: finished in 0.10 milliseconds, allocated 0.061 megabytes
*** CorePrep [expr]:
!!! CorePrep [expr]: finished in 1.28 milliseconds, allocated 1.715 megabytes
*** ByteCodeGen [Ghci1]:
!!! ByteCodeGen [Ghci1]: finished in 0.06 milliseconds, allocated 0.035 megabytes
Loading package ghc-prim-0.6.1 ... linking ... done.
Loading package integer-gmp-1.0.3.0 ... linking ... done.
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name libiconv.dylib
!!! systool:linker: finished in 0.48 milliseconds, allocated 0.059 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name liblibiconv.dylib
!!! systool:linker: finished in 0.44 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name iconv.lib
!!! systool:linker: finished in 0.51 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name libiconv.lib
!!! systool:linker: finished in 0.92 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name libiconv.dll.a
!!! systool:linker: finished in 0.86 milliseconds, allocated 0.057 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name iconv.dll.a
!!! systool:linker: finished in 0.38 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name libiconv.a
!!! systool:linker: finished in 1.30 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name iconv.a
!!! systool:linker: finished in 0.53 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name libiconv
!!! systool:linker: finished in 0.88 milliseconds, allocated 0.056 megabytes
*** systool:linker:
*** gcc:
clang -B/opt/homebrew/Cellar/ghc/8.10.7_1/lib/ghc-8.10.7/base-4.14.3.0 --print-file-name iconv
!!! systool:linker: finished in 0.88 milliseconds, allocated 0.056 megabytes
Loading package base-4.14.3.0 ... linking ... done.
Search directories (user):
  /opt/homebrew/lib
Search directories (gcc):
Loading object (dynamic) /opt/homebrew/lib/libleveldb.dylib ... done
final link ... done
*** Desugar:
*** Simplify [expr]:
!!! Simplify [expr]: finished in 0.07 milliseconds, allocated 0.049 megabytes
*** CorePrep [expr]:
!!! CorePrep [expr]: finished in 0.02 milliseconds, allocated 0.019 megabytes
*** ByteCodeGen [Ghci1]:
!!! ByteCodeGen [Ghci1]: finished in 0.04 milliseconds, allocated 0.033 megabytes
*** Desugar:
[1]    18702 segmentation fault  ghci -v -I/opt/homebrew/include -lleveldb -L/opt/homebrew/lib Test.hs

Expected behavior

The code should compile.

Environment

I am running the following

  • GHC version used: 8.10.7
  • Operating System: MacOS Monterey
  • System Architecture: aarch64

I have, however, also seen this on MacOS Monterey with Intel hardware. Big Sur on Intel works however.

Edited by Timo von Holtz
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information