<div dir="ltr"><div><div><div>Hello Alex,<br><br></div>This sounds like a workaround that should do the trick! I will try it out today.<br><br></div>Thank you for the reply.<br><br></div>Best Regards,<br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><table border="0"><tbody><tr><td>Lefteris(Eleftherios) Karapetsas</td>
</tr>
<tr>
<td>About me: <a href="http://lefteris.refu.co" target="_blank">My Website</a><br></td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td>Keep in touch: <a href="https://twitter.com/LefterisJP" target="_blank">Twitter</a>, <a href="https://github.com/LefterisJP" target="_blank">Github</a>, <a href="http://blog.refu.co" target="_blank">Blog</a><br></td>
</tr>
</tbody></table>
</div></div></div>
<br><div class="gmail_quote">On Sat, Jun 4, 2016 at 4:24 PM, Alex Denisov <span dir="ltr"><<a href="mailto:1101.debian@gmail.com" target="_blank">1101.debian@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Lefteris,<br>
<br>
I’m not sure how _right_ my solution is, but it should work, at least as a workaround.<br>
<br>
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:<br>
<br>
let commonModuleForA = LLVMCloneModule(CommonModule)<br>
LLVMLinkModule2(commonModuleForA, ModuleA)<br>
<br>
let commonModuleForB = LLVMCloneModule(CommonModule)<br>
LLVMLinkModule2(commonModuleForB, ModuleB)<br>
<br>
Hope that will help you.<br>
<br>
Best regards,<br>
Alex.<br>
<div><div class="h5"><br>
> On 04 Jun 2016, at 14:01, Lefteris Karapetsas via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hey all,<br>
><br>
> 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.<br>
><br>
> 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.<br>
><br>
> But how are you supposed to act in a triangulary dependency like below?<br>
><br>
>                                                     CommonModule<br>
>                                                                 |<br>
>                                                         -----------------<br>
>                                                         |               |<br>
>                                                  ModuleA      Module B<br>
><br>
> 1) Create and verify common module.<br>
> 2) Create ModuleA, Link CommonModule to ModuleA and verify the new module.<br>
> 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.<br>
><br>
><br>
> I am probably doing this the wrong way and am missing something obvious.<br>
> Any tips on how to do this the right way? Thanks in advance!<br>
><br>
> ---<br>
><br>
> Best Regards,<br>
><br>
> Lefteris(Eleftherios) Karapetsas<br>
> About me: My Website<br>
><br>
> Keep in touch: Twitter, Github, Blog<br>
</div></div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
--<br>
AlexDenisov<br>
Software Engineer, <a href="http://lowlevelbits.org" rel="noreferrer" target="_blank">http://lowlevelbits.org</a><br>
<br>
</blockquote></div><br></div></div>