Dibyendu Majumdar via llvm-dev
2020-Apr-13 17:05 UTC
[llvm-dev] LLVM 10 ORC2 issue with symbol resolution
Hi, I updated my project to LLVM 10.0 today and I am getting JIT symbol resolution errors. I could not find any example or updated tutorial or documentation that describes the new api - as all documentation seems out of date. I paste below some code snippets that show what I am doing: /* global syms is a array mapping names to function addresses */ ES->createJITDylib("<main>"); MainJD = ES->getJITDylibByName("<main>"); MainJD->addGenerator( cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess( DL->getGlobalPrefix()))); auto &JD = *MainJD; 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"); FYI - my previous post on similar issue. Basically I haven't been able to get ORC v2 working - tried in 8, 9 and now 10. http://llvm.1065342.n5.nabble.com/llvm-dev-ORC-v2-question-tp130489p130601.html Thanks and Regards Dibyendu
Lang Hames via llvm-dev
2020-Apr-13 18:12 UTC
[llvm-dev] LLVM 10 ORC2 issue with symbol resolution
Hi Dibyendu, I updated my project to LLVM 10.0 today and I am getting JIT> symbol resolution errors. > I could not find any example or updated tutorial or documentation > that describes the new api - as all documentation seems out of date.The doxygen comments should be up-to-date, as should http://llvm.org/docs/ORCv2.html. You can find up-to-date example code for LLJIT in llvm/examples/LLJITExamples (LLVM 10) or llvm/examples/OrcV2Examples (master). If you come across any documentation in master that appears to be out of date please let me know and I will fix it. The BuildingAJIT tutorial series is known to be out of date. I'm hoping to have that fixed by LLVM 11 but there is some feature work that I need to complete first. Can you share the specific errors that you're getting back? I would recommend replacing cantFail(callToFailingFunc(...)); with logAllUnhandledErrors(callToFailingFunc(...), errs(), "callToFailingFunc(...) failed:"); Regards, Lang. On Mon, Apr 13, 2020 at 10:06 AM Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:> Hi, > > I updated my project to LLVM 10.0 today and I am getting JIT symbol > resolution errors. > I could not find any example or updated tutorial or documentation that > describes the new api - as all documentation seems out of date. > > I paste below some code snippets that show what I am doing: > > /* global syms is a array mapping names to function addresses */ > > ES->createJITDylib("<main>"); > MainJD = ES->getJITDylibByName("<main>"); > MainJD->addGenerator( > > cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess( > DL->getGlobalPrefix()))); > auto &JD = *MainJD; > 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"); > > FYI - my previous post on similar issue. > Basically I haven't been able to get ORC v2 working - tried in 8, 9 and > now 10. > > > http://llvm.1065342.n5.nabble.com/llvm-dev-ORC-v2-question-tp130489p130601.html > > Thanks and Regards > Dibyendu >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200413/149a8c30/attachment.html>
Dibyendu Majumdar via llvm-dev
2020-Apr-13 19:13 UTC
[llvm-dev] LLVM 10 ORC2 issue with symbol resolution
Hi Lang, On Mon, 13 Apr 2020 at 19:12, Lang Hames <lhames at gmail.com> wrote:> >> I updated my project to LLVM 10.0 today and I am getting JIT symbol resolution errors. >> I could not find any example or updated tutorial or documentation that describes the new api - as all documentation seems out of date. > > > The doxygen comments should be up-to-date, as should http://llvm.org/docs/ORCv2.html. You can find up-to-date example code for LLJIT in llvm/examples/LLJITExamples (LLVM 10) or llvm/examples/OrcV2Examples (master). If you come across any documentation in master that appears to be out of date please let me know and I will fix it. >Sadly http://llvm.org/docs/ORCv2.html is out of date. For example: auto &JD = ES.getMainJITDylib(); This api no longer exists. I did look at OrcV2Examples but did not see any that were trying to set up external symbols. Did I miss something?> The BuildingAJIT tutorial series is known to be out of date. I'm hoping to have that fixed by LLVM 11 but there is some feature work that I need to complete first. > > Can you share the specific errors that you're getting back? I would recommend replacing > > cantFail(callToFailingFunc(...)); > > with > > logAllUnhandledErrors(callToFailingFunc(...), errs(), "callToFailingFunc(...) failed:"); >Okay thank you - I will do that and report back.> On Mon, Apr 13, 2020 at 10:06 AM Dibyendu Majumdar <mobile at majumdar.org.uk> wrote: >> >> Hi, >> >> I updated my project to LLVM 10.0 today and I am getting JIT symbol >> resolution errors. >> I could not find any example or updated tutorial or documentation that >> describes the new api - as all documentation seems out of date. >> >> I paste below some code snippets that show what I am doing: >> >> /* global syms is a array mapping names to function addresses */ >> >> ES->createJITDylib("<main>"); >> MainJD = ES->getJITDylibByName("<main>"); >> MainJD->addGenerator( >> cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess( >> DL->getGlobalPrefix()))); >> auto &JD = *MainJD; >> 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"); >> >> FYI - my previous post on similar issue. >> Basically I haven't been able to get ORC v2 working - tried in 8, 9 and now 10. >> >> http://llvm.1065342.n5.nabble.com/llvm-dev-ORC-v2-question-tp130489p130601.html >> >> Thanks and Regards >> Dibyendu
Lang Hames via llvm-dev
2020-Apr-13 21:00 UTC
[llvm-dev] LLVM 10 ORC2 issue with symbol resolution
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>
Dibyendu Majumdar via llvm-dev
2020-Apr-13 21:34 UTC
[llvm-dev] LLVM 10 ORC2 issue with symbol resolution
Hi Lang, On Mon, 13 Apr 2020 at 22:00, Lang Hames <lhames at gmail.com> wrote:>> 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 >Looks like you are right - I wasn't registering all the functions I thought I was. So it is a user error. Thanks for the help. Regards Dibyendu