Lefteris Karapetsas via llvm-dev
2016-Jun-04 12:01 UTC
[llvm-dev] LLVMLinkModules2() C-API question
Hey all, A quick question about the LLVM C-Api and using LinkModules. In a normal situation where I have 2 LLVM modules and 1 depends on the other using LLVMLinkModules2() works perfectly. LLVMLinkModules2() "Links the source module into the destination module. The source module is destroyed." according to the comment of the function. That is all fine when you only have 2 modules. But how are you supposed to act in a triangulary dependency like below? CommonModule | ----------------- | | ModuleA Module B 1) Create and verify common module. 2) Create ModuleA, Link CommonModule to ModuleA and verify the new module. 3) Now we have a problem. Even though we wanted to repeat step (2) for Module B this fails due to CommonModule being "damaged" as the documentation says. Even though LLVMLinkModules2() function returns success, Module B is lacking structs and functions that were defined in the CommonModule. I am probably doing this the wrong way and am missing something obvious. Any tips on how to do this the right way? Thanks in advance! --- Best Regards, Lefteris(Eleftherios) Karapetsas About me: My Website <http://lefteris.refu.co> Keep in touch: Twitter <https://twitter.com/LefterisJP>, Github <https://github.com/LefterisJP>, Blog <http://blog.refu.co> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160604/a5c518c7/attachment.html>
Alex Denisov via llvm-dev
2016-Jun-04 14:24 UTC
[llvm-dev] LLVMLinkModules2() C-API question
Hi Lefteris, I’m not sure how _right_ my solution is, but it should work, at least as a workaround. To prevent a CommonModule from being destroyed you can make a copy of the module. You can do so using LLVMCloneModule method, so that the code may look like this: let commonModuleForA = LLVMCloneModule(CommonModule) LLVMLinkModule2(commonModuleForA, ModuleA) let commonModuleForB = LLVMCloneModule(CommonModule) LLVMLinkModule2(commonModuleForB, ModuleB) Hope that will help you. Best regards, Alex.> On 04 Jun 2016, at 14:01, Lefteris Karapetsas via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hey all, > > A quick question about the LLVM C-Api and using LinkModules. In a normal situation where I have 2 LLVM modules and 1 depends on the other using LLVMLinkModules2() works perfectly. > > LLVMLinkModules2() "Links the source module into the destination module. The source module is destroyed." according to the comment of the function. That is all fine when you only have 2 modules. > > But how are you supposed to act in a triangulary dependency like below? > > CommonModule > | > ----------------- > | | > ModuleA Module B > > 1) Create and verify common module. > 2) Create ModuleA, Link CommonModule to ModuleA and verify the new module. > 3) Now we have a problem. Even though we wanted to repeat step (2) for Module B this fails due to CommonModule being "damaged" as the documentation says. Even though LLVMLinkModules2() function returns success, Module B is lacking structs and functions that were defined in the CommonModule. > > > I am probably doing this the wrong way and am missing something obvious. > Any tips on how to do this the right way? Thanks in advance! > > --- > > Best Regards, > > Lefteris(Eleftherios) Karapetsas > About me: My Website > > Keep in touch: Twitter, Github, Blog > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- AlexDenisov Software Engineer, http://lowlevelbits.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 496 bytes Desc: Message signed with OpenPGP using GPGMail URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160604/43286733/attachment.sig>
Lefteris Karapetsas via llvm-dev
2016-Jun-05 08:26 UTC
[llvm-dev] LLVMLinkModules2() C-API question
Hello Alex, This sounds like a workaround that should do the trick! I will try it out today. Thank you for the reply. Best Regards, Lefteris(Eleftherios) Karapetsas About me: My Website <http://lefteris.refu.co> Keep in touch: Twitter <https://twitter.com/LefterisJP>, Github <https://github.com/LefterisJP>, Blog <http://blog.refu.co> On Sat, Jun 4, 2016 at 4:24 PM, Alex Denisov <1101.debian at gmail.com> wrote:> Hi Lefteris, > > I’m not sure how _right_ my solution is, but it should work, at least as a > workaround. > > To prevent a CommonModule from being destroyed you can make a copy of the > module. You can do so using LLVMCloneModule method, so that the code may > look like this: > > let commonModuleForA = LLVMCloneModule(CommonModule) > LLVMLinkModule2(commonModuleForA, ModuleA) > > let commonModuleForB = LLVMCloneModule(CommonModule) > LLVMLinkModule2(commonModuleForB, ModuleB) > > Hope that will help you. > > Best regards, > Alex. > > > On 04 Jun 2016, at 14:01, Lefteris Karapetsas via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > > Hey all, > > > > A quick question about the LLVM C-Api and using LinkModules. In a normal > situation where I have 2 LLVM modules and 1 depends on the other using > LLVMLinkModules2() works perfectly. > > > > LLVMLinkModules2() "Links the source module into the destination module. > The source module is destroyed." according to the comment of the function. > That is all fine when you only have 2 modules. > > > > But how are you supposed to act in a triangulary dependency like below? > > > > CommonModule > > | > > ----------------- > > | | > > ModuleA Module B > > > > 1) Create and verify common module. > > 2) Create ModuleA, Link CommonModule to ModuleA and verify the new > module. > > 3) Now we have a problem. Even though we wanted to repeat step (2) for > Module B this fails due to CommonModule being "damaged" as the > documentation says. Even though LLVMLinkModules2() function returns > success, Module B is lacking structs and functions that were defined in the > CommonModule. > > > > > > I am probably doing this the wrong way and am missing something obvious. > > Any tips on how to do this the right way? Thanks in advance! > > > > --- > > > > Best Regards, > > > > Lefteris(Eleftherios) Karapetsas > > About me: My Website > > > > Keep in touch: Twitter, Github, Blog > > _______________________________________________ > > LLVM Developers mailing list > > llvm-dev at lists.llvm.org > > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > -- > AlexDenisov > Software Engineer, http://lowlevelbits.org > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160605/86363a2e/attachment.html>