message(LDPL_ERROR, "Failed to get a view of %s", file->name);
return LDPS_ERR;
}
- BufferRef = MemoryBufferRef(StringRef((char *)view, file->filesize), "");
+ BufferRef = MemoryBufferRef(StringRef((const char *)view, file->filesize), "");
} else {
int64_t offset = 0;
// Gold has found what might be IR part-way inside of a file, such as
assert(!GV.isDiscardableIfUnused());
}
-static bool isDeclaration(const GlobalValue &V) {
- if (V.hasAvailableExternallyLinkage())
- return true;
-
- if (V.isMaterializable())
- return false;
-
- return V.isDeclaration();
-}
-
static void internalize(GlobalValue &GV) {
- if (isDeclaration(GV))
+ if (GV.isDeclarationForLinker())
return; // We get here if there is a matching asm definition.
if (!GV.hasLocalLinkage())
GV.setLinkage(GlobalValue::InternalLinkage);
case LDPR_PREVAILING_DEF_IRONLY_EXP:
return "PREVAILING_DEF_IRONLY_EXP";
}
+ llvm_unreachable("Unknown resolution");
}
static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
Module *M = GO->getParent();
GlobalObject *Ret;
if (auto *F = dyn_cast<Function>(GO)) {
+ if (F->isMaterializable()) {
+ if (F->materialize())
+ message(LDPL_FATAL, "LLVM gold plugin has failed to read a function");
+
+ }
+
auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
F->getName(), M);
case LDPR_RESOLVED_EXEC:
case LDPR_RESOLVED_DYN:
case LDPR_UNDEF:
- assert(isDeclaration(*GV));
+ assert(GV->isDeclarationForLinker());
break;
case LDPR_PREVAILING_DEF_IRONLY: {
keepGlobalValue(*GV, KeptAliases);
break;
- case LDPR_PREEMPTED_REG:
case LDPR_PREEMPTED_IR:
+ // Gold might have selected a linkonce_odr and preempted a weak_odr.
+ // In that case we have to make sure we don't end up internalizing it.
+ if (!GV->isDiscardableIfUnused())
+ Maybe.erase(Sym.name);
+
+ // fall-through
+ case LDPR_PREEMPTED_REG:
Drop.insert(GV);
break;
Sym.comdat_key = nullptr;
}
- if (!Drop.empty())
- // This is horrible. Given how lazy loading is implemented, dropping
- // the body while there is a materializer present doesn't work, the
- // linker will just read the body back.
- M->materializeAllPermanently();
-
ValueToValueMapTy VM;
LocalValueMaterializer Materializer(Drop);
for (GlobalAlias *GA : KeptAliases) {
M->setTargetTriple(DefaultTriple);
}
- std::string ErrMsg;
- if (L.linkInModule(M.get(), &ErrMsg))
- message(LDPL_FATAL, "Failed to link module: %s", ErrMsg.c_str());
+ if (L.linkInModule(M.get()))
+ message(LDPL_FATAL, "Failed to link module");
}
for (const auto &Name : Internalize) {