-
Notifications
You must be signed in to change notification settings - Fork 129
Description
https://hackage.haskell.org/package/llvm-hs-9.0.1/docs/LLVM-Target.html#v:withHostTargetMachine is unsafe in a threading context. It uses initializeAllTargets which is, according to llvm documentation, supposed to be in the "main" thread.
I'm unsure about the implementation, but it looks like there is an internal structure (later read by lookupTarget and related functions) which is unsafe to read and initialize at the same time.
I'm unsure what can be done in llvm-hs, either adding a lock, or documenting that it is unsafe.
Here, the concurrent call of initializeAllTargets as well as lookupTarget leads to an infinite loop in lookupTarget eating 100% CPU according to perf top:
74.07% libLLVM-9.so [.] llvm::TargetRegistry::lookupTarget
15.06% libLLVM-9.so [.] llvm::RegisterTarget<(llvm::Triple::ArchType)48, false>::getArchMatch
Note that I found this problem while using the alternate initializeAllTargets implementation from #263