[llvm-dev] getSymbolAddressInProcess returning null

Russell Wallace via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 2 07:19:44 PDT 2016


Thanks! Comparing your code to Kaleidoscope, they are superficially very
different but when you boil it down, you can see the common elements. I
think the most significant difference is that where you have

auto compiler = std::make_unique<SimpleOrcJit>(*targetMachine);
compiler->addGlobalMapping("myAlloc", (void*)myAlloc);

Kaleidoscope has

  auto resolver = createLambdaResolver(
      [&](const std::string &name) {
        if (auto sym = compileLayer->findSymbol(name, false))
          return RuntimeDyld::SymbolInfo(sym.getAddress(), sym.getFlags());
        return RuntimeDyld::SymbolInfo(nullptr);
      },
      [](const std::string &S) { return nullptr; });
  compileLayer->addModuleSet(std::vector<Module *>(1, module),
                             new SectionMemoryManager(),
std::move(resolver));

I'm going to guess the reason for this difference is something along the
lines of:

Orc provides a way to supply your own custom code for resolving symbols -
for some reason this is packaged with parameters for memory manager and a
set of modules rather than a single module - maybe they figured instead of
providing various custom options and complicating the API, best to just
provide one big function that lets you customise everything, you can always
supply basic default parameters for things you don't want to customise -
which makes sense - and that's what Kaleidoscope uses.

Orc also provides a class that contains a basic system for resolving
symbols if you don't want to customise, and that works by just supplying it
with each symbol you're going to want to look up, together with the
associated function pointer - and that's what you used.

Is that a more or less accurate summary of the situation?


On Sat, Apr 2, 2016 at 12:53 PM, Stefan Gränitz <llvm-dev at lists.llvm.org>
wrote:

> Hi Russel, I guess you're using ORC? Then you need a mapping layer. Have a
> look at this line:
>
> https://github.com/weliveindetail/JitFromScratch/blob/example/own-externals/JitFromScratch.cpp#L38
>
> Best,
> Stefan
>
> Am 02.04.16 um 11:43 schrieb Russell Wallace via llvm-dev:
>
> Tried that, still didn't work. Then I tried making a direct API call,
>
> GetProcAddress(GetModuleHandle(0),"foo")
>
> And this works if and only if __declspec(dllexport) is supplied. So it
> looks like we were both right.
>
> On Sat, Apr 2, 2016 at 9:29 AM, NAKAMURA Takumi <geek4civic at gmail.com>
> wrote:
>
>> Have you tried to add dllexport?
>>
>> On Sat, Apr 2, 2016 at 4:23 PM Russell Wallace via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>>> I've finally managed to extract from Kaleidoscope one particular thing
>>> that it seems to me should be working and isn't. Given the global
>>> declaration
>>>
>>> extern "C" void foo() {}
>>>
>>> within the same program I have
>>>
>>> RTDyldMemoryManager::getSymbolAddressInProcess("foo")
>>>
>>> And it's returning null. (LLVM 3.8, Windows 7 x64.) What am I missing?
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>>
>
>
> _______________________________________________
> LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160402/ec9232b7/attachment.html>


More information about the llvm-dev mailing list