<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Dibyendu,</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I am not sure the --export-dynamic applies as I am explicitly<br>registering my symbols.<br>llvm::orc::MangleAndInterner mangle(*ES, *this->DL);<br>llvm::orc::SymbolMap Symbols;<br>for (int i = 0; global_syms[i].name != nullptr; i++) {<br>  Symbols.insert({mangle(global_syms[i].name),</blockquote><div><br></div></div><div>Ahh. You're right: If you are managing registration yourself then process symbol visibility should not be an issue.</div><div><br></div><div>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).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">llvm::JITSymbolFlags::FlagNames::Absolute</blockquote><div><br></div><div>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:</div><div><br></div><div><font face="monospace">llvm::JITSymbolFlags Flags;</font></div><div><font face="monospace">Flags |= llvm::</font><span style="font-family:monospace">JITSymbolFlags::Absolute;</span></div><div><font face="monospace">Flags |= llvm::JITSymbolFlags::Exported;</font></div><div><br></div><div>Symbols that are not marked exported are hidden and not visible by default to code in other JITDylibs.</div><div><br></div><div>Regards,</div><div>Lang.</div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 13, 2020 at 1:43 PM Dibyendu Majumdar <<a href="mailto:mobile@majumdar.org.uk">mobile@majumdar.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Lang,<br>
<br>
On Mon, 13 Apr 2020 at 21:22, Lang Hames <<a href="mailto:lhames@gmail.com" target="_blank">lhames@gmail.com</a>> wrote:<br>
<br>
>> Sadly <a href="http://llvm.org/docs/ORCv2.html" rel="noreferrer" target="_blank">http://llvm.org/docs/ORCv2.html</a> is out of date. For example:<br>
>> auto &JD = ES.getMainJITDylib();<br>
>> This api no longer exists.<br>
><br>
><br>
> 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 <a href="http://bugs.llvm.org" rel="noreferrer" target="_blank">bugs.llvm.org</a>.<br>
><br>
>> I did look at OrcV2Examples but did not see any that were trying to set up external symbols. Did I miss something?<br>
><br>
><br>
> No. I usually point people to lli.cpp for that example: <a href="https://github.com/llvm/llvm-project/blob/68cd4f72beae67a9bdbc11c85fd745dec8fc0999/llvm/tools/lli/lli.cpp#L805" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/68cd4f72beae67a9bdbc11c85fd745dec8fc0999/llvm/tools/lli/lli.cpp#L805</a> :<br>
><br>
>     J->getMainJITDylib().addGenerator(<br>
>         ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(<br>
>             J->getDataLayout().getGlobalPrefix(),<br>
>             [MainName = Mangle("main")](const orc::SymbolStringPtr &Name) {<br>
>               return Name != MainName;<br>
>             })));<br>
><br>
> 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.<br>
><br>
> 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.<br>
><br>
<br>
I am not sure the --export-dynamic applies as I am explicitly<br>
registering my symbols.<br>
<br>
llvm::orc::MangleAndInterner mangle(*ES, *this->DL);<br>
llvm::orc::SymbolMap Symbols;<br>
for (int i = 0; global_syms[i].name != nullptr; i++) {<br>
  Symbols.insert({mangle(global_syms[i].name),<br>
<br>
llvm::JITEvaluatedSymbol(llvm::pointerToJITTargetAddress(global_syms[i].address),<br>
<br>
llvm::JITSymbolFlags(llvm::JITSymbolFlags::FlagNames::Absolute))});<br>
}<br>
llvm::cantFail(JD.define(llvm::orc::absoluteSymbols(Symbols)), "Failed<br>
to install extern symbols");<br>
<br>
So the JITDylib should know about the symbols, right?<br>
<br>
BTW ORC v1 works fine in LLVM 10, 9 and 8.<br>
<br>
Thanks and Regards<br>
</blockquote></div></div></div></div></div>