[llvm-dev] JIT compiler, Windows, external functions like cos

Stefan Gränitz via llvm-dev llvm-dev at lists.llvm.org
Sat Jan 5 08:24:16 PST 2019


Hi Machiel, thanks for sharing your solution and the workarounds for
RTDyldObjectLinkingLayer on Windows!

As in the other "Undefined symbols" thread, you might want to have a
look at symbol generators. They offer an easy way to emit additional
symbols to a Dylib's symbol table. Two examples for this in ORCv2 are:
* DynamicLibrarySearchGenerator in
llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
* ReexportsGenerator in llvm/include/llvm/ExecutionEngine/Orc/Core.h

Of course, depending on your use-case a common runtime Dylib can be a
suitable solution too.

Best
Stefan

Am 02.01.19 um 22:31 schrieb Machiel van Hooren via llvm-dev:
> Hi Marcus,
>
> I ran into the same/similar issue a while ago (and posted the same
> question here) but since I got no response I eventually came up with
> the following solution.
>
> Create a JITDylib containing absolute addresses to all your runtime
> functions like cosf, sinf, etc and then link that JITDylib to each new
> JITDylib that needs those functions.
> This can be done by defining some absolute symbols as follows:
>
> llvm::JITSymbolFlags functionFlags;
> functionFlags |= llvm::JITSymbolFlags::Callable;
> functionFlags |= llvm::JITSymbolFlags::Exported;
> functionFlags |= llvm::JITSymbolFlags::Absolute;
>
> llvm::orc::SymbolMap runtimeSymbols;
> //This will map the "sinf" symbol to the absolute address of std::sinf
> //Do this for every runtime library symbol that you need.
> runtimeSymbols[executionSession->intern("sinf")] =
> llvm::JITEvaluatedSymbol(reinterpret_cast<llvm::JITTargetAddress>(&std::sinf),
> functionFlags);
> runtimeSymbols[executionSession->intern("cosf")] =
> llvm::JITEvaluatedSymbol(reinterpret_cast<llvm::JITTargetAddress>(&std::cosf),
> functionFlags);
>
> //Create your runtime dylib and define the absolute symbols
> llvm::orc::JITDylib& runtimeLibraryDyLib =
> executionSession->createJITDylib("runtimeLibrary", false);
> runtimeLibraryDyLib.define(llvm::orc::absoluteSymbols(runtimeSymbols));
> Then on the JITDylib that you are building:
>
> dylib.addToSearchOrder(runtimeLibraryDyLib, false);
>
> Another crash/issue you may run into on Windows that is related to
> your question is described in this bug report (there is a workaround):
> https://bugs.llvm.org/show_bug.cgi?id=40074
>
> You may already be doing this, but on Windows you also need to enable
> some workarounds on your RTDyldObjectLinkingLayer in order for your
> compiled function symbols to be found at all:
> objectLinkLayer->setAutoClaimResponsibilityForObjectSymbols(true);
> objectLinkLayer->setOverrideObjectFlagsWithResponsibilityFlags(true);
>
> I hope this helps.
>
> Regards,
>
> Machiel van Hooren
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
https://weliveindetail.github.io/blog/
https://cryptup.org/pub/stefan.graenitz@gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190105/7381ce74/attachment.html>


More information about the llvm-dev mailing list