[llvm-dev] LLVMLinkModules2() C-API question

Alex Denisov via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 4 07:24:37 PDT 2016

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,

> 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

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>

More information about the llvm-dev mailing list