Mikhail Glushenkov | 59a5afa | 2009-03-03 10:04:23 +0000 | [diff] [blame] | 1 | //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===// |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 361e513 | 2004-11-12 20:37:43 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 361e513 | 2004-11-12 20:37:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the LLVM module linker. |
| 11 | // |
Reid Spencer | 361e513 | 2004-11-12 20:37:43 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 14 | #include "LinkDiagnosticInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm-c/Linker.h" |
Bill Wendling | 66f0241 | 2012-02-11 11:38:06 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SetVector.h" |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringSet.h" |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DiagnosticPrinter.h" |
Rafael Espindola | 9d2bfc4 | 2015-12-14 23:17:03 +0000 | [diff] [blame] | 19 | #include "llvm/IR/LLVMContext.h" |
Teresa Johnson | 488a800 | 2016-02-10 18:11:31 +0000 | [diff] [blame] | 20 | #include "llvm/Linker/Linker.h" |
| 21 | #include "llvm/Transforms/Utils/FunctionImportUtils.h" |
Reid Spencer | 361e513 | 2004-11-12 20:37:43 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Chris Lattner | eee6f99 | 2008-06-16 21:00:18 +0000 | [diff] [blame] | 24 | namespace { |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 25 | |
| 26 | /// This is an implementation class for the LinkModules function, which is the |
| 27 | /// entrypoint for this file. |
| 28 | class ModuleLinker { |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 29 | IRMover &Mover; |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 30 | std::unique_ptr<Module> SrcM; |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 31 | |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 32 | SetVector<GlobalValue *> ValuesToLink; |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 33 | StringSet<> Internalize; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 34 | |
Duncan P. N. Exon Smith | e868123 | 2015-04-22 04:11:00 +0000 | [diff] [blame] | 35 | /// For symbol clashes, prefer those from Src. |
Artem Belevich | 020d4fb | 2015-09-01 17:55:55 +0000 | [diff] [blame] | 36 | unsigned Flags; |
Duncan P. N. Exon Smith | e868123 | 2015-04-22 04:11:00 +0000 | [diff] [blame] | 37 | |
Teresa Johnson | 4f04d85 | 2015-12-21 17:33:24 +0000 | [diff] [blame] | 38 | /// Functions to import from source module, all other functions are |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 39 | /// imported as declarations instead of definitions. |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 40 | DenseSet<const GlobalValue *> *GlobalsToImport; |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 41 | |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 42 | /// Association between metadata value id and temporary metadata that |
| 43 | /// remains unmapped after function importing. Saved during function |
| 44 | /// importing and consumed during the metadata linking postpass. |
| 45 | DenseMap<unsigned, MDNode *> *ValIDToTempMDMap; |
| 46 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 47 | /// Used as the callback for lazy linking. |
| 48 | /// The mover has just hit GV and we have to decide if it, and other members |
| 49 | /// of the same comdat, should be linked. Every member to be linked is passed |
| 50 | /// to Add. |
| 51 | void addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add); |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 52 | |
Artem Belevich | 020d4fb | 2015-09-01 17:55:55 +0000 | [diff] [blame] | 53 | bool shouldOverrideFromSrc() { return Flags & Linker::OverrideFromSrc; } |
| 54 | bool shouldLinkOnlyNeeded() { return Flags & Linker::LinkOnlyNeeded; } |
| 55 | bool shouldInternalizeLinkedSymbols() { |
| 56 | return Flags & Linker::InternalizeLinkedSymbols; |
| 57 | } |
| 58 | |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 59 | bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest, |
| 60 | const GlobalValue &Src); |
Rafael Espindola | ed6dc37 | 2014-05-09 14:39:25 +0000 | [diff] [blame] | 61 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 62 | /// Should we have mover and linker error diag info? |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 63 | bool emitError(const Twine &Message) { |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 64 | SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message)); |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 65 | return true; |
| 66 | } |
Rafael Espindola | ed6dc37 | 2014-05-09 14:39:25 +0000 | [diff] [blame] | 67 | |
Rafael Espindola | 0e309fe | 2015-12-01 19:50:54 +0000 | [diff] [blame] | 68 | bool getComdatLeader(Module &M, StringRef ComdatName, |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 69 | const GlobalVariable *&GVar); |
| 70 | bool computeResultingSelectionKind(StringRef ComdatName, |
| 71 | Comdat::SelectionKind Src, |
| 72 | Comdat::SelectionKind Dst, |
| 73 | Comdat::SelectionKind &Result, |
| 74 | bool &LinkFromSrc); |
| 75 | std::map<const Comdat *, std::pair<Comdat::SelectionKind, bool>> |
| 76 | ComdatsChosen; |
| 77 | bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK, |
| 78 | bool &LinkFromSrc); |
Teresa Johnson | 2d5fb8c | 2015-11-10 21:09:06 +0000 | [diff] [blame] | 79 | // Keep track of the global value members of each comdat in source. |
| 80 | DenseMap<const Comdat *, std::vector<GlobalValue *>> ComdatMembers; |
Rafael Espindola | 4160f5d | 2014-10-27 23:02:10 +0000 | [diff] [blame] | 81 | |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 82 | /// Given a global in the source module, return the global in the |
| 83 | /// destination module that is being linked to, if any. |
| 84 | GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) { |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 85 | Module &DstM = Mover.getModule(); |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 86 | // If the source has no name it can't link. If it has local linkage, |
| 87 | // there is no name match-up going on. |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 88 | if (!SrcGV->hasName() || GlobalValue::isLocalLinkage(SrcGV->getLinkage())) |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 89 | return nullptr; |
Eli Bendersky | 7da92ed | 2014-02-20 22:19:24 +0000 | [diff] [blame] | 90 | |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 91 | // Otherwise see if we have a match in the destination module's symtab. |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 92 | GlobalValue *DGV = DstM.getNamedValue(SrcGV->getName()); |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 93 | if (!DGV) |
| 94 | return nullptr; |
Rafael Espindola | ed6dc37 | 2014-05-09 14:39:25 +0000 | [diff] [blame] | 95 | |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 96 | // If we found a global with the same name in the dest module, but it has |
| 97 | // internal linkage, we are really not doing any linkage here. |
| 98 | if (DGV->hasLocalLinkage()) |
| 99 | return nullptr; |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 100 | |
Rafael Espindola | c84f608 | 2014-11-25 06:11:24 +0000 | [diff] [blame] | 101 | // Otherwise, we do in fact link to the destination global. |
| 102 | return DGV; |
| 103 | } |
Rafael Espindola | ed6dc37 | 2014-05-09 14:39:25 +0000 | [diff] [blame] | 104 | |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 105 | bool linkIfNeeded(GlobalValue &GV); |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 106 | |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 107 | /// Helper method to check if we are importing from the current source |
| 108 | /// module. |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 109 | bool isPerformingImport() const { return GlobalsToImport != nullptr; } |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 110 | |
| 111 | /// If we are importing from the source module, checks if we should |
| 112 | /// import SGV as a definition, otherwise import as a declaration. |
| 113 | bool doImportAsDefinition(const GlobalValue *SGV); |
| 114 | |
| 115 | public: |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 116 | ModuleLinker(IRMover &Mover, std::unique_ptr<Module> SrcM, unsigned Flags, |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 117 | DenseSet<const GlobalValue *> *GlobalsToImport = nullptr, |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 118 | DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr) |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 119 | : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags), |
| 120 | GlobalsToImport(GlobalsToImport), ValIDToTempMDMap(ValIDToTempMDMap) {} |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 121 | |
| 122 | bool run(); |
| 123 | }; |
Teresa Johnson | 4504c1b | 2016-01-08 15:00:00 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) { |
| 127 | if (!isPerformingImport()) |
| 128 | return false; |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 129 | return FunctionImportGlobalProcessing::doImportAsDefinition(SGV, |
| 130 | GlobalsToImport); |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Rafael Espindola | eb5e0a7 | 2015-11-29 14:33:06 +0000 | [diff] [blame] | 133 | static GlobalValue::VisibilityTypes |
| 134 | getMinVisibility(GlobalValue::VisibilityTypes A, |
| 135 | GlobalValue::VisibilityTypes B) { |
| 136 | if (A == GlobalValue::HiddenVisibility || B == GlobalValue::HiddenVisibility) |
| 137 | return GlobalValue::HiddenVisibility; |
| 138 | if (A == GlobalValue::ProtectedVisibility || |
| 139 | B == GlobalValue::ProtectedVisibility) |
| 140 | return GlobalValue::ProtectedVisibility; |
| 141 | return GlobalValue::DefaultVisibility; |
| 142 | } |
| 143 | |
Rafael Espindola | 0e309fe | 2015-12-01 19:50:54 +0000 | [diff] [blame] | 144 | bool ModuleLinker::getComdatLeader(Module &M, StringRef ComdatName, |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 145 | const GlobalVariable *&GVar) { |
Rafael Espindola | 0e309fe | 2015-12-01 19:50:54 +0000 | [diff] [blame] | 146 | const GlobalValue *GVal = M.getNamedValue(ComdatName); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 147 | if (const auto *GA = dyn_cast_or_null<GlobalAlias>(GVal)) { |
| 148 | GVal = GA->getBaseObject(); |
| 149 | if (!GVal) |
| 150 | // We cannot resolve the size of the aliasee yet. |
| 151 | return emitError("Linking COMDATs named '" + ComdatName + |
| 152 | "': COMDAT key involves incomputable alias size."); |
| 153 | } |
| 154 | |
| 155 | GVar = dyn_cast_or_null<GlobalVariable>(GVal); |
| 156 | if (!GVar) |
| 157 | return emitError( |
| 158 | "Linking COMDATs named '" + ComdatName + |
| 159 | "': GlobalVariable required for data dependent selection!"); |
| 160 | |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | bool ModuleLinker::computeResultingSelectionKind(StringRef ComdatName, |
| 165 | Comdat::SelectionKind Src, |
| 166 | Comdat::SelectionKind Dst, |
| 167 | Comdat::SelectionKind &Result, |
| 168 | bool &LinkFromSrc) { |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 169 | Module &DstM = Mover.getModule(); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 170 | // The ability to mix Comdat::SelectionKind::Any with |
| 171 | // Comdat::SelectionKind::Largest is a behavior that comes from COFF. |
| 172 | bool DstAnyOrLargest = Dst == Comdat::SelectionKind::Any || |
| 173 | Dst == Comdat::SelectionKind::Largest; |
| 174 | bool SrcAnyOrLargest = Src == Comdat::SelectionKind::Any || |
| 175 | Src == Comdat::SelectionKind::Largest; |
| 176 | if (DstAnyOrLargest && SrcAnyOrLargest) { |
| 177 | if (Dst == Comdat::SelectionKind::Largest || |
| 178 | Src == Comdat::SelectionKind::Largest) |
| 179 | Result = Comdat::SelectionKind::Largest; |
| 180 | else |
| 181 | Result = Comdat::SelectionKind::Any; |
| 182 | } else if (Src == Dst) { |
| 183 | Result = Dst; |
| 184 | } else { |
| 185 | return emitError("Linking COMDATs named '" + ComdatName + |
| 186 | "': invalid selection kinds!"); |
| 187 | } |
| 188 | |
| 189 | switch (Result) { |
| 190 | case Comdat::SelectionKind::Any: |
| 191 | // Go with Dst. |
| 192 | LinkFromSrc = false; |
| 193 | break; |
| 194 | case Comdat::SelectionKind::NoDuplicates: |
| 195 | return emitError("Linking COMDATs named '" + ComdatName + |
| 196 | "': noduplicates has been violated!"); |
| 197 | case Comdat::SelectionKind::ExactMatch: |
| 198 | case Comdat::SelectionKind::Largest: |
| 199 | case Comdat::SelectionKind::SameSize: { |
| 200 | const GlobalVariable *DstGV; |
| 201 | const GlobalVariable *SrcGV; |
| 202 | if (getComdatLeader(DstM, ComdatName, DstGV) || |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 203 | getComdatLeader(*SrcM, ComdatName, SrcGV)) |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 204 | return true; |
| 205 | |
Rafael Espindola | 0e309fe | 2015-12-01 19:50:54 +0000 | [diff] [blame] | 206 | const DataLayout &DstDL = DstM.getDataLayout(); |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 207 | const DataLayout &SrcDL = SrcM->getDataLayout(); |
Manuel Jacob | 5f6eaac | 2016-01-16 20:30:46 +0000 | [diff] [blame] | 208 | uint64_t DstSize = DstDL.getTypeAllocSize(DstGV->getValueType()); |
| 209 | uint64_t SrcSize = SrcDL.getTypeAllocSize(SrcGV->getValueType()); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 210 | if (Result == Comdat::SelectionKind::ExactMatch) { |
| 211 | if (SrcGV->getInitializer() != DstGV->getInitializer()) |
| 212 | return emitError("Linking COMDATs named '" + ComdatName + |
| 213 | "': ExactMatch violated!"); |
| 214 | LinkFromSrc = false; |
| 215 | } else if (Result == Comdat::SelectionKind::Largest) { |
| 216 | LinkFromSrc = SrcSize > DstSize; |
| 217 | } else if (Result == Comdat::SelectionKind::SameSize) { |
| 218 | if (SrcSize != DstSize) |
| 219 | return emitError("Linking COMDATs named '" + ComdatName + |
| 220 | "': SameSize violated!"); |
| 221 | LinkFromSrc = false; |
| 222 | } else { |
| 223 | llvm_unreachable("unknown selection kind"); |
| 224 | } |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | bool ModuleLinker::getComdatResult(const Comdat *SrcC, |
| 233 | Comdat::SelectionKind &Result, |
| 234 | bool &LinkFromSrc) { |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 235 | Module &DstM = Mover.getModule(); |
Rafael Espindola | b16196a | 2014-08-11 17:07:34 +0000 | [diff] [blame] | 236 | Comdat::SelectionKind SSK = SrcC->getSelectionKind(); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 237 | StringRef ComdatName = SrcC->getName(); |
Rafael Espindola | 0e309fe | 2015-12-01 19:50:54 +0000 | [diff] [blame] | 238 | Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable(); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 239 | Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(ComdatName); |
Rafael Espindola | 2ef3f29 | 2014-08-11 16:55:42 +0000 | [diff] [blame] | 240 | |
Rafael Espindola | b16196a | 2014-08-11 17:07:34 +0000 | [diff] [blame] | 241 | if (DstCI == ComdatSymTab.end()) { |
| 242 | // Use the comdat if it is only available in one of the modules. |
| 243 | LinkFromSrc = true; |
| 244 | Result = SSK; |
Rafael Espindola | 2ef3f29 | 2014-08-11 16:55:42 +0000 | [diff] [blame] | 245 | return false; |
Rafael Espindola | b16196a | 2014-08-11 17:07:34 +0000 | [diff] [blame] | 246 | } |
Rafael Espindola | 2ef3f29 | 2014-08-11 16:55:42 +0000 | [diff] [blame] | 247 | |
| 248 | const Comdat *DstC = &DstCI->second; |
Rafael Espindola | 2ef3f29 | 2014-08-11 16:55:42 +0000 | [diff] [blame] | 249 | Comdat::SelectionKind DSK = DstC->getSelectionKind(); |
| 250 | return computeResultingSelectionKind(ComdatName, SSK, DSK, Result, |
| 251 | LinkFromSrc); |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 252 | } |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 253 | |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 254 | bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc, |
| 255 | const GlobalValue &Dest, |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 256 | const GlobalValue &Src) { |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 257 | |
Duncan P. N. Exon Smith | e868123 | 2015-04-22 04:11:00 +0000 | [diff] [blame] | 258 | // Should we unconditionally use the Src? |
Artem Belevich | 020d4fb | 2015-09-01 17:55:55 +0000 | [diff] [blame] | 259 | if (shouldOverrideFromSrc()) { |
Duncan P. N. Exon Smith | e868123 | 2015-04-22 04:11:00 +0000 | [diff] [blame] | 260 | LinkFromSrc = true; |
| 261 | return false; |
| 262 | } |
| 263 | |
Rafael Espindola | 778fcc7 | 2014-11-02 13:28:57 +0000 | [diff] [blame] | 264 | // We always have to add Src if it has appending linkage. |
| 265 | if (Src.hasAppendingLinkage()) { |
Teresa Johnson | 1e20a65 | 2015-12-03 18:20:05 +0000 | [diff] [blame] | 266 | // Should have prevented importing for appending linkage in linkIfNeeded. |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 267 | assert(!isPerformingImport()); |
Rafael Espindola | 778fcc7 | 2014-11-02 13:28:57 +0000 | [diff] [blame] | 268 | LinkFromSrc = true; |
| 269 | return false; |
| 270 | } |
| 271 | |
Rafael Espindola | d4bcefc | 2014-10-24 18:13:04 +0000 | [diff] [blame] | 272 | bool SrcIsDeclaration = Src.isDeclarationForLinker(); |
| 273 | bool DestIsDeclaration = Dest.isDeclarationForLinker(); |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 274 | |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 275 | if (isPerformingImport()) { |
| 276 | if (isa<Function>(&Src)) { |
Teresa Johnson | 4f04d85 | 2015-12-21 17:33:24 +0000 | [diff] [blame] | 277 | // For functions, LinkFromSrc iff this is a function requested |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 278 | // for importing. For variables, decide below normally. |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 279 | LinkFromSrc = GlobalsToImport->count(&Src); |
Teresa Johnson | c7ed52f | 2015-11-03 00:14:15 +0000 | [diff] [blame] | 280 | return false; |
| 281 | } |
| 282 | |
| 283 | // Check if this is an alias with an already existing definition |
| 284 | // in Dest, which must have come from a prior importing pass from |
| 285 | // the same Src module. Unlike imported function and variable |
| 286 | // definitions, which are imported as available_externally and are |
| 287 | // not definitions for the linker, that is not a valid linkage for |
| 288 | // imported aliases which must be definitions. Simply use the existing |
| 289 | // Dest copy. |
| 290 | if (isa<GlobalAlias>(&Src) && !DestIsDeclaration) { |
| 291 | assert(isa<GlobalAlias>(&Dest)); |
| 292 | LinkFromSrc = false; |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 297 | if (SrcIsDeclaration) { |
| 298 | // If Src is external or if both Src & Dest are external.. Just link the |
| 299 | // external globals, we aren't adding anything. |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 300 | if (Src.hasDLLImportStorageClass()) { |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 301 | // If one of GVs is marked as DLLImport, result should be dllimport'ed. |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 302 | LinkFromSrc = DestIsDeclaration; |
| 303 | return false; |
| 304 | } |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 305 | // If the Dest is weak, use the source linkage. |
Rafael Espindola | ed11bd2 | 2015-12-09 22:44:00 +0000 | [diff] [blame] | 306 | if (Dest.hasExternalWeakLinkage()) { |
| 307 | LinkFromSrc = true; |
| 308 | return false; |
| 309 | } |
| 310 | // Link an available_externally over a declaration. |
| 311 | LinkFromSrc = !Src.isDeclaration() && Dest.isDeclaration(); |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 312 | return false; |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 315 | if (DestIsDeclaration) { |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 316 | // If Dest is external but Src is not: |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 317 | LinkFromSrc = true; |
| 318 | return false; |
| 319 | } |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 320 | |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 321 | if (Src.hasCommonLinkage()) { |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 322 | if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) { |
| 323 | LinkFromSrc = true; |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 324 | return false; |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | if (!Dest.hasCommonLinkage()) { |
| 328 | LinkFromSrc = false; |
| 329 | return false; |
| 330 | } |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 331 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 332 | const DataLayout &DL = Dest.getParent()->getDataLayout(); |
Manuel Jacob | 5f6eaac | 2016-01-16 20:30:46 +0000 | [diff] [blame] | 333 | uint64_t DestSize = DL.getTypeAllocSize(Dest.getValueType()); |
| 334 | uint64_t SrcSize = DL.getTypeAllocSize(Src.getValueType()); |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 335 | LinkFromSrc = SrcSize > DestSize; |
| 336 | return false; |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 339 | if (Src.isWeakForLinker()) { |
| 340 | assert(!Dest.hasExternalWeakLinkage()); |
| 341 | assert(!Dest.hasAvailableExternallyLinkage()); |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 342 | |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 343 | if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage()) { |
| 344 | LinkFromSrc = true; |
| 345 | return false; |
| 346 | } |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 347 | |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 348 | LinkFromSrc = false; |
Rafael Espindola | 0910605 | 2014-09-09 15:59:12 +0000 | [diff] [blame] | 349 | return false; |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | if (Dest.isWeakForLinker()) { |
| 353 | assert(Src.hasExternalLinkage()); |
Rafael Espindola | d12b4a3 | 2014-10-25 04:06:10 +0000 | [diff] [blame] | 354 | LinkFromSrc = true; |
| 355 | return false; |
Rafael Espindola | dbb0bd1 | 2014-09-09 15:21:00 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | assert(!Src.hasExternalWeakLinkage()); |
| 359 | assert(!Dest.hasExternalWeakLinkage()); |
| 360 | assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() && |
| 361 | "Unexpected linkage type!"); |
| 362 | return emitError("Linking globals named '" + Src.getName() + |
| 363 | "': symbol multiply defined!"); |
| 364 | } |
| 365 | |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 366 | bool ModuleLinker::linkIfNeeded(GlobalValue &GV) { |
| 367 | GlobalValue *DGV = getLinkedToGlobal(&GV); |
| 368 | |
| 369 | if (shouldLinkOnlyNeeded() && !(DGV && DGV->isDeclaration())) |
| 370 | return false; |
| 371 | |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 372 | if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) { |
| 373 | auto *DGVar = dyn_cast<GlobalVariable>(DGV); |
| 374 | auto *SGVar = dyn_cast<GlobalVariable>(&GV); |
| 375 | if (DGVar && SGVar) { |
| 376 | if (DGVar->isDeclaration() && SGVar->isDeclaration() && |
| 377 | (!DGVar->isConstant() || !SGVar->isConstant())) { |
| 378 | DGVar->setConstant(false); |
| 379 | SGVar->setConstant(false); |
| 380 | } |
| 381 | if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) { |
| 382 | unsigned Align = std::max(DGVar->getAlignment(), SGVar->getAlignment()); |
| 383 | SGVar->setAlignment(Align); |
| 384 | DGVar->setAlignment(Align); |
| 385 | } |
| 386 | } |
| 387 | |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 388 | GlobalValue::VisibilityTypes Visibility = |
| 389 | getMinVisibility(DGV->getVisibility(), GV.getVisibility()); |
| 390 | DGV->setVisibility(Visibility); |
| 391 | GV.setVisibility(Visibility); |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 392 | |
| 393 | bool HasUnnamedAddr = GV.hasUnnamedAddr() && DGV->hasUnnamedAddr(); |
| 394 | DGV->setUnnamedAddr(HasUnnamedAddr); |
| 395 | GV.setUnnamedAddr(HasUnnamedAddr); |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 398 | // Don't want to append to global_ctors list, for example, when we |
| 399 | // are importing for ThinLTO, otherwise the global ctors and dtors |
| 400 | // get executed multiple times for local variables (the latter causing |
| 401 | // double frees). |
| 402 | if (GV.hasAppendingLinkage() && isPerformingImport()) |
| 403 | return false; |
| 404 | |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 405 | if (isPerformingImport()) { |
| 406 | if (!doImportAsDefinition(&GV)) |
| 407 | return false; |
| 408 | } else if (!DGV && !shouldOverrideFromSrc() && |
| 409 | (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() || |
| 410 | GV.hasAvailableExternallyLinkage())) |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 411 | return false; |
| 412 | |
Rafael Espindola | bd03c50 | 2015-12-07 16:31:41 +0000 | [diff] [blame] | 413 | if (GV.isDeclaration()) |
| 414 | return false; |
| 415 | |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 416 | if (const Comdat *SC = GV.getComdat()) { |
| 417 | bool LinkFromSrc; |
| 418 | Comdat::SelectionKind SK; |
| 419 | std::tie(SK, LinkFromSrc) = ComdatsChosen[SC]; |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 420 | if (LinkFromSrc) |
| 421 | ValuesToLink.insert(&GV); |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 422 | return false; |
| 423 | } |
Rafael Espindola | 4b5ec26 | 2015-12-02 22:59:04 +0000 | [diff] [blame] | 424 | |
| 425 | bool LinkFromSrc = true; |
| 426 | if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, GV)) |
| 427 | return true; |
| 428 | if (LinkFromSrc) |
| 429 | ValuesToLink.insert(&GV); |
| 430 | return false; |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 433 | void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) { |
| 434 | // Add these to the internalize list |
| 435 | if (!GV.hasLinkOnceLinkage()) |
| 436 | return; |
| 437 | |
| 438 | if (shouldInternalizeLinkedSymbols()) |
| 439 | Internalize.insert(GV.getName()); |
| 440 | Add(GV); |
| 441 | |
| 442 | const Comdat *SC = GV.getComdat(); |
| 443 | if (!SC) |
| 444 | return; |
| 445 | for (GlobalValue *GV2 : ComdatMembers[SC]) { |
| 446 | if (!GV2->hasLocalLinkage() && shouldInternalizeLinkedSymbols()) |
| 447 | Internalize.insert(GV2->getName()); |
| 448 | Add(*GV2); |
| 449 | } |
| 450 | } |
| 451 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 452 | bool ModuleLinker::run() { |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 453 | for (const auto &SMEC : SrcM->getComdatSymbolTable()) { |
David Majnemer | dad0a64 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 454 | const Comdat &C = SMEC.getValue(); |
| 455 | if (ComdatsChosen.count(&C)) |
| 456 | continue; |
| 457 | Comdat::SelectionKind SK; |
| 458 | bool LinkFromSrc; |
| 459 | if (getComdatResult(&C, SK, LinkFromSrc)) |
| 460 | return true; |
| 461 | ComdatsChosen[&C] = std::make_pair(SK, LinkFromSrc); |
| 462 | } |
| 463 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 464 | for (GlobalVariable &GV : SrcM->globals()) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 465 | if (const Comdat *SC = GV.getComdat()) |
| 466 | ComdatMembers[SC].push_back(&GV); |
| 467 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 468 | for (Function &SF : *SrcM) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 469 | if (const Comdat *SC = SF.getComdat()) |
| 470 | ComdatMembers[SC].push_back(&SF); |
| 471 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 472 | for (GlobalAlias &GA : SrcM->aliases()) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 473 | if (const Comdat *SC = GA.getComdat()) |
| 474 | ComdatMembers[SC].push_back(&GA); |
| 475 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 476 | // Insert all of the globals in src into the DstM module... without linking |
| 477 | // initializers (which could refer to functions not yet mapped over). |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 478 | for (GlobalVariable &GV : SrcM->globals()) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 479 | if (linkIfNeeded(GV)) |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 480 | return true; |
| 481 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 482 | for (Function &SF : *SrcM) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 483 | if (linkIfNeeded(SF)) |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 484 | return true; |
| 485 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 486 | for (GlobalAlias &GA : SrcM->aliases()) |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 487 | if (linkIfNeeded(GA)) |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 488 | return true; |
| 489 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 490 | for (unsigned I = 0; I < ValuesToLink.size(); ++I) { |
| 491 | GlobalValue *GV = ValuesToLink[I]; |
| 492 | const Comdat *SC = GV->getComdat(); |
| 493 | if (!SC) |
| 494 | continue; |
| 495 | for (GlobalValue *GV2 : ComdatMembers[SC]) |
| 496 | ValuesToLink.insert(GV2); |
Rafael Espindola | beadd56 | 2014-12-08 18:05:48 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 499 | if (shouldInternalizeLinkedSymbols()) { |
| 500 | for (GlobalValue *GV : ValuesToLink) |
| 501 | Internalize.insert(GV->getName()); |
| 502 | } |
Teresa Johnson | 1063293 | 2015-11-06 17:50:53 +0000 | [diff] [blame] | 503 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 504 | if (Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(), |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 505 | [this](GlobalValue &GV, IRMover::ValueAdder Add) { |
| 506 | addLazyFor(GV, Add); |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 507 | }, |
| 508 | ValIDToTempMDMap, false)) |
Teresa Johnson | 189b252 | 2015-11-06 17:50:48 +0000 | [diff] [blame] | 509 | return true; |
Rafael Espindola | caabe22 | 2015-12-10 14:19:35 +0000 | [diff] [blame] | 510 | Module &DstM = Mover.getModule(); |
| 511 | for (auto &P : Internalize) { |
| 512 | GlobalValue *GV = DstM.getNamedValue(P.first()); |
| 513 | GV->setLinkage(GlobalValue::InternalLinkage); |
| 514 | } |
Teresa Johnson | 189b252 | 2015-11-06 17:50:48 +0000 | [diff] [blame] | 515 | |
Anton Korobeynikov | 2609888 | 2008-03-05 23:21:39 +0000 | [diff] [blame] | 516 | return false; |
| 517 | } |
Reid Spencer | 361e513 | 2004-11-12 20:37:43 +0000 | [diff] [blame] | 518 | |
Rafael Espindola | 9d2bfc4 | 2015-12-14 23:17:03 +0000 | [diff] [blame] | 519 | Linker::Linker(Module &M) : Mover(M) {} |
Rafael Espindola | 3df61b7 | 2013-05-04 03:48:37 +0000 | [diff] [blame] | 520 | |
Rafael Espindola | 434e956 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 521 | bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags, |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 522 | DenseSet<const GlobalValue *> *GlobalsToImport, |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 523 | DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) { |
Mehdi Amini | 8d05185 | 2016-03-19 00:40:31 +0000 | [diff] [blame^] | 524 | ModuleLinker ModLinker(Mover, std::move(Src), Flags, GlobalsToImport, |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 525 | ValIDToTempMDMap); |
Teresa Johnson | bef5436 | 2015-12-18 19:28:59 +0000 | [diff] [blame] | 526 | return ModLinker.run(); |
Rafael Espindola | 434e956 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 529 | bool Linker::linkInMetadata(std::unique_ptr<Module> Src, |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 530 | DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) { |
| 531 | SetVector<GlobalValue *> ValuesToLink; |
| 532 | if (Mover.move( |
Rafael Espindola | 40358fb | 2016-02-16 18:50:12 +0000 | [diff] [blame] | 533 | std::move(Src), ValuesToLink.getArrayRef(), |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 534 | [this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); }, |
| 535 | ValIDToTempMDMap, true)) |
| 536 | return true; |
| 537 | return false; |
| 538 | } |
| 539 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 540 | //===----------------------------------------------------------------------===// |
| 541 | // LinkModules entrypoint. |
| 542 | //===----------------------------------------------------------------------===// |
| 543 | |
Rafael Espindola | 18c8941 | 2014-10-27 02:35:46 +0000 | [diff] [blame] | 544 | /// This function links two modules together, with the resulting Dest module |
| 545 | /// modified to be the composite of the two input modules. If an error occurs, |
| 546 | /// true is returned and ErrorMsg (if not null) is set to indicate the problem. |
| 547 | /// Upon failure, the Dest module could be in a modified state, and shouldn't be |
| 548 | /// relied on to be consistent. |
Rafael Espindola | 434e956 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 549 | bool Linker::linkModules(Module &Dest, std::unique_ptr<Module> Src, |
| 550 | unsigned Flags) { |
Rafael Espindola | 9d2bfc4 | 2015-12-14 23:17:03 +0000 | [diff] [blame] | 551 | Linker L(Dest); |
Rafael Espindola | 434e956 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 552 | return L.linkInModule(std::move(Src), Flags); |
Rafael Espindola | 4160f5d | 2014-10-27 23:02:10 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Bill Wendling | a3aeb98 | 2012-05-09 08:55:40 +0000 | [diff] [blame] | 555 | //===----------------------------------------------------------------------===// |
| 556 | // C API. |
| 557 | //===----------------------------------------------------------------------===// |
| 558 | |
Rafael Espindola | 434e956 | 2015-12-16 23:16:33 +0000 | [diff] [blame] | 559 | LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src) { |
| 560 | Module *D = unwrap(Dest); |
| 561 | std::unique_ptr<Module> M(unwrap(Src)); |
| 562 | return Linker::linkModules(*D, std::move(M)); |
| 563 | } |