[llvm-dev] LLVM 10 LLJIT runConstructors()

Haoran Xu via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 17 13:57:15 PDT 2020


Hi Lang,

Thanks for the explanation! That makes sense now.

Best,
Haoran

Lang Hames <lhames at gmail.com> 于2020年10月17日周六 上午11:06写道:

> Hi Haoran,
>
> Unfortunately there was a bug in LLVM 10: Constructors from
> llvm.global_ctors were tracked by LLLazyJIT, but not LLJIT. As you've
> discovered you can work around this by recording the destructors manually.
> You can just stick with this workaround while you're on LLVM 10. In LLVM 11
> this API has been fixed and renamed: runConstructors has been changed to
> 'initialize' and runDestructors to 'deinitialize'. Once you upgrade to LLVM
> 11 you can initialize all modules added to a JITDylib JD by running:
>
> J->initialize(JD);
>
> If you're just using the main JITDylib that LLJIT creates for you then
> this will look like:
>
> J->initialize(J->getMainJITDylib());
>
> Regards,
> Lang.
>
>
> On Fri, Oct 16, 2020 at 4:09 AM Haoran Xu via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hello,
>>
>> I have been struggling with making LLJIT runConstructors() working. I saw this
>> email thread
>> <https://lists.llvm.org/pipermail/llvm-dev/2019-March/131057.html> and
>> tried to replicate its logic:
>>
>>> LLJIT LJ;
>>> // Add Modules.
>>> if (auto Err = LJ.runConstructors())
>>>   ... ; // report error.
>>>
>>> But it doesn't seem to work. The global constructors in llvm.global_ctor
>> doesn't seem to run (I added a printf in the constructor and it doesn't
>> seem to get executed).
>>
>> However, the following code seems to work:
>>
>>> CtorDtorRunner RR(J->getMainJITDylib());
>>>
>>> RR.add(getConstructors(*tsm.getModuleUnlocked()));
>>>
>>> exitOnError(J->addIRModule(std::move(tsm)));
>>>
>>> exitOnError(RR.run());
>>
>>
>> But I can't understand what's wrong with my previous approach by calling
>> LLJIT's runConstructor() method.
>> Would anyone kindly help on what part I'm missing? Thanks!
>>
>> Best regards,
>> Haoran
>>
>> _______________________________________________
>> 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/20201017/a1560b9d/attachment.html>


More information about the llvm-dev mailing list