diff options
Diffstat (limited to 'lib/Linker/LinkModules.cpp')
-rw-r--r-- | lib/Linker/LinkModules.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index c358a0ad72..26061c280d 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -927,6 +927,19 @@ void ModuleLinker::linkFunctionBody(Function *Dst, Function *Src) { ValueMap[I] = DI; } + // @LOCALMOD-BEGIN + // Local patch for http://llvm.org/bugs/show_bug.cgi?id=11112 + // and http://llvm.org/bugs/show_bug.cgi?id=10887 + // Create an identity mapping for instructions so that alloca instructions + // do not get dropped and related debug info isn't lost. E.g., prevent + // call @llvm.dbg.declare(metadata !{i32 * %local_var}, ...) + // from becoming + // call @llvm.dbg.declare(null, ...) + for (Function::iterator BB = Src->begin(), BE = Src->end(); BB != BE; ++BB) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + ValueMap[I] = I; + // @LOCALMOD-END + if (Mode == Linker::DestroySource) { // Splice the body of the source function into the dest function. Dst->getBasicBlockList().splice(Dst->end(), Src->getBasicBlockList()); @@ -944,6 +957,13 @@ void ModuleLinker::linkFunctionBody(Function *Dst, Function *Src) { SmallVector<ReturnInst*, 8> Returns; // Ignore returns. CloneFunctionInto(Dst, Src, ValueMap, false, Returns, "", NULL, &TypeMap); } + + // @LOCALMOD-BEGIN + // There is no need for the identity mapping anymore. + for (Function::iterator BB = Src->begin(), BE = Src->end(); BB != BE; ++BB) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + ValueMap.erase(I); + // @LOCALMOD-END // There is no need to map the arguments anymore. for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end(); @@ -1168,7 +1188,20 @@ bool ModuleLinker::run() { DstM->setModuleInlineAsm(DstM->getModuleInlineAsm()+"\n"+ SrcM->getModuleInlineAsm()); } - + // @LOCALMOD-BEGIN + // Update the destination module's dependent libraries list with the libraries + // from the source module. There's no opportunity for duplicates here as the + // Module ensures that duplicate insertions are discarded. + for (Module::lib_iterator SI = SrcM->lib_begin(), SE = SrcM->lib_end(); + SI != SE; ++SI) + DstM->addLibrary(*SI); + + // If the source library's module id is in the dependent library list of the + // destination library, remove it since that module is now linked in. + StringRef ModuleId = SrcM->getModuleIdentifier(); + if (!ModuleId.empty()) + DstM->removeLibrary(sys::path::stem(ModuleId)); + // @LOCALMOD-END // Loop over all of the linked values to compute type mappings. computeTypeMapping(); |