You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code from arith in llvm-hs-examples (llvm-hs-12) works fine (either with or without the commented out JIT.loadLibraryPermanently Nothing on linux., when there are external symbols. Is there some guidance on when that call is actually needed?
--| JIT-compile the given 'Expr'ession and use the resulting function.withSimpleJIT::NFDataa=>Expr->--| what to do with the generated function
((Double->Double) ->a) ->IOa
withSimpleJIT expr doFun =doputStrLn"*** Codegen ***"
printCodegen expr
JIT.withContext $\context ->-- (>>) (JIT.loadLibraryPermanently Nothing) $JIT.withModuleFromAST context (codegen expr) $\mod' ->JIT.withHostTargetMachine Reloc.PICCodeModel.DefaultCodeGenOpt.Default$\tm ->JIT.withExecutionSession $\es ->dolet dylibName ="myDylib"
dylib <-JIT.createJITDylib es dylibName
JIT.withClonedThreadSafeModule mod' $\tsm ->do
objectLayer <-JIT.createRTDyldObjectLinkingLayer es
compileLayer <-JIT.createIRCompileLayer es objectLayer tm
JIT.addDynamicLibrarySearchGeneratorForCurrentProcess compileLayer dylib
JIT.addModule tsm dylib compileLayer
asm <-JIT.moduleLLVMAssembly mod'
printExpr expr
printIR asm
optimized <-PM.withPassManager passes $flipPM.runPassManager mod'
when optimized $putStrLn"*** Optimized ***"
optasm <-JIT.moduleLLVMAssembly mod'
printIR optasm
sym <-JIT.lookupSymbol es compileLayer dylib "f"case sym ofLeft (JIT.JITSymbolError err) ->doprint err
error"Execution aborted"Right (JIT.JITSymbol fnAddr _) ->dolet fn = mkDoubleFun . castPtrToFunPtr $ wordPtrToPtr fnAddr
liftIO (putStrLn"*** Result ***\n")
evaluate $ force (doFun fn)
The same code segfaults on macos on the last line (with or without the call to loadLibraryPermenently), because the pointer to fn seems to be invalid, but that is a different issue.
Looking more closely, I see that loadLibraryPermanently produces a success/failure Bool. In the case above, it actually returns false (so it failed to load the process symbols, yet the result of the process succeeds). This still leaves the question of when loadLibraryPermanently is neeeded.
I think addDynamicLibrarySearchGeneratorForCurrentProcess might be doing more or less the same thing in your case as loadLibraryPermanently. Try (a) removing both calls and (b) removing addDynamicLibrarySearchGeneratorForCurrentProcess but leaving loadLibraryPermanently and see if that confirms my hypothesis.
Also,
In the case above, it actually returns false (so it failed to load the process symbols, yet the result of the process succeeds).
Though this does not seem to be documented anywhere, loadLibraryPermanently returns True on failure; see the definition
of static bool LoadLibraryPermanently in llvm/include/llvm/Support/DynamicLibrary.h.
The following code from arith in llvm-hs-examples (llvm-hs-12) works fine (either with or without the commented out
JIT.loadLibraryPermanently Nothing
on linux., when there are external symbols. Is there some guidance on when that call is actually needed?The same code segfaults on macos on the last line (with or without the call to loadLibraryPermenently), because the pointer to fn seems to be invalid, but that is a different issue.
Here's some output from a run
The text was updated successfully, but these errors were encountered: