<div dir="ltr">I'm pretty sure module linking is expected to occur in the same LLVM context. IIRC Duncan had some proposal for how ld64 could do something clever with multiple contexts, but I've totally forgotten what it was.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 29, 2015 at 5:18 PM, Yuri <span dir="ltr"><<a href="mailto:yuri@rawbw.com" target="_blank">yuri@rawbw.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I get a crash when I try to link multiple modules registered in their individual contexts.<br>
Documentation for Linker::LinkModules doesn't mention anything about contexts, and the first link succeeds. But the second link crashes.<br>
<br>
Is this not the right way to merge such modules? If not, then what is the right way?<br>
<br>
In any case, documentation for Linker::LinkModules should say if contexts are or aren't expected to be the same.<br>
<br>
Yuri<br>
<br>
<br>
---testcase---<br>
#include "llvm/IR/LLVMContext.h"<br>
#include "llvm/IR/Module.h"<br>
#include "llvm/Linker/Linker.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include "llvm/IR/DiagnosticPrinter.h"<br>
#include <string><br>
#include <iostream><br>
<br>
using namespace llvm;<br>
using namespace std;<br>
<br>
int main() {<br>
// vars<br>
string Message;<br>
raw_string_ostream Stream(Message);<br>
DiagnosticPrinterRawOStream DP(Stream);<br>
LLVMBool Result;<br>
// create blank modules and contexts<br>
LLVMContext *ctx1 = new LLVMContext;<br>
Module* module1 = new Module("module1", *ctx1);<br>
LLVMContext *ctx2 = new LLVMContext;<br>
Module* module2 = new Module("module2", *ctx2);<br>
LLVMContext *ctx3 = new LLVMContext;<br>
Module* module3 = new Module("module3", *ctx3);<br>
// fill modules<br>
llvm::Function::Create(llvm::FunctionType::get(Type::getInt32Ty(*ctx1), false), llvm::Function::ExternalLinkage, "f1", module1);<br>
llvm::Function::Create(llvm::FunctionType::get(Type::getInt32Ty(*ctx2), false), llvm::Function::ExternalLinkage, "f2", module2);<br>
llvm::Function::Create(llvm::FunctionType::get(Type::getInt32Ty(*ctx3), false), llvm::Function::ExternalLinkage, "f3", module3);<br>
<br>
// merge f1 <- f2<br>
Result = Linker::LinkModules(module1, module2, [&](const DiagnosticInfo &DI) {DI.print(DP);});<br>
cout << "merge result=" << Result << endl;<br>
delete ctx2;<br>
cout << "--done merge #1--" << endl;<br>
<br>
// merge f3 <- f1<br>
Result = Linker::LinkModules(module3, module1, [&](const DiagnosticInfo &DI) {DI.print(DP);});<br>
cout << "merge result=" << Result << endl;<br>
delete ctx1;<br>
cout << "--done merge #2--" << endl;<br>
<br>
return 0;<br>
}<br>
<br>
---output---<br>
merge result=0<br>
--done merge #1--<br>
Bus error<br>
<br>
rev.237344<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>