[llvm-dev] New ORC v2 LLJIT - global variables

Lang Hames via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 12 14:32:49 PDT 2019

Hi Chris,

> Thanks so much for the quick help. I was able to find them after changing
> the linkage. Does this new orc JIT follow different standards than the
> MCJitReplacement? We used to set a lot of our functions/globals to internal
> linkage before doing a lookup.

They are different: ORCv2 follows the static linker's lookup rules, whereas
MCJITReplacement mimicked MCJIT's rules which were never clearly spelled
out, but in practice allowed you to search for internal symbols.

The advantage of the new scheme is that if you are compiling/running
something on the command line. E.g.:

$ llc -filetype=obj -o extra.o extra.ll
$ llc -filetype=obj -o prog.o prog.ll
$ clang -o prog prog.o extra.o
$ ./prog

Then you can add the same modules to the JIT and expect the resulting JIT'd
code to behave the same as the statically compiled code. E.g. (omitting
some error handling for clarity):

auto Main = (int(*)())J->lookup("main").getAddress();

If you are generating code specifically for the JIT it is often easiest to
just use external linkage and default visibility for all symbols. However,
for people who want to hook up an existing front-end, or to use more
advanced features in their JIT (duplicate symbol names with internal
linkage, symbols with weak linkage, hidden visibility, etc.) this scheme
has the nice property that "What does linker-feature X do in the JIT?" is
more-or-less equivalent to "What does linker-feature X do in a regular
build". The answer to the latter question is generally more widely known,
and is much easier to test from the command line.

When adding a new module with a single global variable in it, I get an
> error during the addLazyIRModule.

Are you hitting an assertion, or is addLazyIRModule returning a non-success
value? If the latter, what is the error message?
(You can find this by calling 'logAllUnhandledErrors(std::move(Err),
errs(), "")', or, in tool code, using the ExitOnError utility:

Right now we are treating the module as one big single module, and when we
> go to lookup a symbol, I believe we are jitting the entire thing. Once we
> make the switch to LLLazyJIT, we want to start splitting up our modules.

If you are using MCJITReplacement you are definitely JITing the whole
module up-front, and in that case lazy compilation may help reduce your
compile time. I'd love to hear how it works for you!


On Mon, Aug 12, 2019 at 10:26 AM David Blaikie <dblaikie at gmail.com> wrote:

> +Lang Hames <lhames at gmail.com>, Admiral of the Orcish Fleet (Lang's the
> primary developer/creator of the ORC JIT & might have some answers to your
> question)
> On Thu, Aug 8, 2019 at 4:15 PM chris boese via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>> We are trying to switch to the new orc v2 lljit engine at my work with
>> hopes of parallel jitting. We are switching from the ExecutionEngine w/
>> OrcMCJitReplacement. We are having a hard time with global variables. We
>> have found a way to create/emit new globals during jitting by using the old
>> ExecutionEngine::getOrEmitGlobalVariable. Is there an easier way to do this
>> with the new jit engine? We were hoping to create a new ThreadSafeModule,
>> add a GlobalVariable, and then add the module to the JIT engine through
>> addLazyIRModule(), but this doesn't seem to work.
>> 2nd question; Is the lookup function supposed to work with global
>> variables by name? Looking through the CompileOnDemandLayer it seems to
>> change the names of globals to "__orc_lcl.<name><id>". Does this affect the
>> lookup methods? I noticed that all of the globals we are looking for are
>> tagged with Internal linkage and end up getting emitted through
>> extractSubModule().
>> Any help is appreciated.
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://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/20190812/f414b50d/attachment.html>

More information about the llvm-dev mailing list