[llvm-dev] LLVM 10 ORC2 issue with symbol resolution

Lang Hames via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 13 14:00:08 PDT 2020


Hi Dibyendu,

I am not sure the --export-dynamic applies as I am explicitly
> registering my symbols.
> llvm::orc::MangleAndInterner mangle(*ES, *this->DL);
> llvm::orc::SymbolMap Symbols;
> for (int i = 0; global_syms[i].name != nullptr; i++) {
>   Symbols.insert({mangle(global_syms[i].name),


Ahh. You're right: If you are managing registration yourself then process
symbol visibility should not be an issue.

In this case the first thing that I would do to diagnose the problem is
dump the content of your Symbols map and ensure that there really is an
entry in there for the symbols that generated the missing-symbols error
(luaV_tointeger_ and luaG_runerror).

llvm::JITSymbolFlags::FlagNames::Absolute


This can just be written as llvm::JITSymbolFlags::Absolute. If the JITDylib
you are putting this in is different from the one that you're adding JIT'd
code to you will also need to make sure that the symbol is exported:

llvm::JITSymbolFlags Flags;
Flags |= llvm::JITSymbolFlags::Absolute;
Flags |= llvm::JITSymbolFlags::Exported;

Symbols that are not marked exported are hidden and not visible by default
to code in other JITDylibs.

Regards,
Lang.

On Mon, Apr 13, 2020 at 1:43 PM Dibyendu Majumdar <mobile at majumdar.org.uk>
wrote:

> Hi Lang,
>
> On Mon, 13 Apr 2020 at 21:22, Lang Hames <lhames at gmail.com> wrote:
>
> >> Sadly http://llvm.org/docs/ORCv2.html is out of date. For example:
> >> auto &JD = ES.getMainJITDylib();
> >> This api no longer exists.
> >
> >
> > Thanks for spotting that. I have fixed it in 840a23b0b5c. If you see any
> other issues with the documentation please let me know, or file a bug at
> bugs.llvm.org.
> >
> >> I did look at OrcV2Examples but did not see any that were trying to set
> up external symbols. Did I miss something?
> >
> >
> > No. I usually point people to lli.cpp for that example:
> https://github.com/llvm/llvm-project/blob/68cd4f72beae67a9bdbc11c85fd745dec8fc0999/llvm/tools/lli/lli.cpp#L805
> :
> >
> >     J->getMainJITDylib().addGenerator(
> >
>  ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
> >             J->getDataLayout().getGlobalPrefix(),
> >             [MainName = Mangle("main")](const orc::SymbolStringPtr
> &Name) {
> >               return Name != MainName;
> >             })));
> >
> > The second argument (the lambda) is an optional predicate to filter out
> some process symbols. Here it is filtering lookups for main to ensure that
> we don't call the process main and overflow the stack when JIT'd code
> doesn't define a main function.
> >
> > To ensure this works you must (1) use the correct global prefix for your
> target for both the generator and for any modules that you add to the JIT,
> and (2) ensure that process symbols have to be exported. On Darwin this
> happens by default. On Linux you need to add --export-dynamic to your
> linker line. I assume there is a similar option on Windows but I am not
> familiar with it.
> >
>
> I am not sure the --export-dynamic applies as I am explicitly
> registering my symbols.
>
> llvm::orc::MangleAndInterner mangle(*ES, *this->DL);
> llvm::orc::SymbolMap Symbols;
> for (int i = 0; global_syms[i].name != nullptr; i++) {
>   Symbols.insert({mangle(global_syms[i].name),
>
>
> llvm::JITEvaluatedSymbol(llvm::pointerToJITTargetAddress(global_syms[i].address),
>
> llvm::JITSymbolFlags(llvm::JITSymbolFlags::FlagNames::Absolute))});
> }
> llvm::cantFail(JD.define(llvm::orc::absoluteSymbols(Symbols)), "Failed
> to install extern symbols");
>
> So the JITDylib should know about the symbols, right?
>
> BTW ORC v1 works fine in LLVM 10, 9 and 8.
>
> Thanks and Regards
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200413/5a62deee/attachment.html>


More information about the llvm-dev mailing list