+ GO->setLinkage(GlobalValue::InternalLinkage);
+ GO->setName(Declaration->getName());
+ Dropped.erase(GO);
+ GO->replaceAllUsesWith(Declaration);
+
+ LocalVersions[Declaration] = GO;
+
+ return GO;
+}
+
+static Constant *mapConstantToLocalCopy(Constant *C, ValueToValueMapTy &VM,
+ LocalValueMaterializer *Materializer) {
+ return MapValue(C, VM, RF_IgnoreMissingEntries, nullptr, Materializer);
+}
+
+static void freeSymName(ld_plugin_symbol &Sym) {
+ free(Sym.name);
+ free(Sym.comdat_key);
+ Sym.name = nullptr;
+ Sym.comdat_key = nullptr;
+}
+
+static std::unique_ptr<Module>
+getModuleForFile(LLVMContext &Context, claimed_file &F,
+ ld_plugin_input_file &Info, raw_fd_ostream *ApiFile,
+ StringSet<> &Internalize, StringSet<> &Maybe) {
+
+ if (get_symbols(F.handle, F.syms.size(), F.syms.data()) != LDPS_OK)
+ message(LDPL_FATAL, "Failed to get symbol information");
+
+ const void *View;
+ if (get_view(F.handle, &View) != LDPS_OK)
+ message(LDPL_FATAL, "Failed to get a view of file");
+
+ MemoryBufferRef BufferRef(StringRef((const char *)View, Info.filesize),
+ Info.name);
+ ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
+ object::IRObjectFile::create(BufferRef, Context);
+
+ if (std::error_code EC = ObjOrErr.getError())
+ message(LDPL_FATAL, "Could not read bitcode from file : %s",
+ EC.message().c_str());
+
+ object::IRObjectFile &Obj = **ObjOrErr;
+
+ Module &M = Obj.getModule();
+
+ M.materializeMetadata();
+ UpgradeDebugInfo(M);
+
+ SmallPtrSet<GlobalValue *, 8> Used;
+ collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
+
+ DenseSet<GlobalValue *> Drop;
+ std::vector<GlobalAlias *> KeptAliases;
+
+ unsigned SymNum = 0;
+ for (auto &ObjSym : Obj.symbols()) {
+ if (shouldSkip(ObjSym.getFlags()))