return false;
}
-static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+static void diagnosticHandler(const DiagnosticInfo &DI) {
if (const auto *BDI = dyn_cast<BitcodeDiagnosticInfo>(&DI)) {
std::error_code EC = BDI->getError();
if (EC == BitcodeError::InvalidBitcodeSignature)
message(Level, "LLVM gold plugin: %s", ErrStorage.c_str());
}
+static void diagnosticHandlerForContext(const DiagnosticInfo &DI,
+ void *Context) {
+ diagnosticHandler(DI);
+}
+
/// Called by gold to see whether this file is one that our plugin can handle.
/// We'll try to open it and register all the symbols with add_symbol if
/// possible.
BufferRef = Buffer->getMemBufferRef();
}
- Context.setDiagnosticHandler(diagnosticHandler);
+ Context.setDiagnosticHandler(diagnosticHandlerForContext);
ErrorOr<std::unique_ptr<object::IRObjectFile>> ObjOrErr =
object::IRObjectFile::create(BufferRef, Context);
std::error_code EC = ObjOrErr.getError();
// If we are doing ThinLTO compilation, don't need to process the symbols.
// Later we simply build a combined index file after all files are claimed.
- if (options::thinlto) return LDPS_OK;
+ if (options::thinlto)
+ return LDPS_OK;
for (auto &Sym : Obj->symbols()) {
uint32_t Symflags = Sym.getFlags();
const Comdat *C = Base->getComdat();
if (C)
sym.comdat_key = strdup(C->getName().str().c_str());
- else if (Base->hasWeakLinkage() || Base->hasLinkOnceLinkage())
- sym.comdat_key = strdup(sym.name);
}
sym.resolution = LDPR_UNKNOWN;
}
namespace {
-class LocalValueMaterializer : public ValueMaterializer {
+class LocalValueMaterializer final : public ValueMaterializer {
DenseSet<GlobalValue *> &Dropped;
DenseMap<GlobalObject *, GlobalObject *> LocalVersions;
public:
LocalValueMaterializer(DenseSet<GlobalValue *> &Dropped) : Dropped(Dropped) {}
- Value *materializeValueFor(Value *V) override;
+ Value *materializeDeclFor(Value *V) override;
};
}
-Value *LocalValueMaterializer::materializeValueFor(Value *V) {
+Value *LocalValueMaterializer::materializeDeclFor(Value *V) {
auto *GO = dyn_cast<GlobalObject>(V);
if (!GO)
return nullptr;
Sym.comdat_key = nullptr;
}
-static std::unique_ptr<FunctionInfoIndex> getFunctionIndexForFile(
- LLVMContext &Context, claimed_file &F, ld_plugin_input_file &Info) {
+static std::unique_ptr<FunctionInfoIndex>
+getFunctionIndexForFile(claimed_file &F, ld_plugin_input_file &Info) {
if (get_symbols(F.handle, F.syms.size(), &F.syms[0]) != LDPS_OK)
message(LDPL_FATAL, "Failed to get symbol information");
MemoryBufferRef BufferRef(StringRef((const char *)View, Info.filesize),
Info.name);
+
+ // Don't bother trying to build an index if there is no summary information
+ // in this bitcode file.
+ if (!object::FunctionIndexObjectFile::hasFunctionSummaryInMemBuffer(
+ BufferRef, diagnosticHandler))
+ return std::unique_ptr<FunctionInfoIndex>(nullptr);
+
ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
- object::FunctionIndexObjectFile::create(BufferRef, Context);
+ object::FunctionIndexObjectFile::create(BufferRef, diagnosticHandler);
if (std::error_code EC = ObjOrErr.getError())
message(LDPL_FATAL, "Could not read function index bitcode from file : %s",
return LDPS_OK;
LLVMContext Context;
- Context.setDiagnosticHandler(diagnosticHandler, nullptr, true);
+ Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true);
// If we are doing ThinLTO compilation, simply build the combined
// function index/summary and emit it. We don't need to parse the modules
message(LDPL_FATAL, "Failed to get file information");
std::unique_ptr<FunctionInfoIndex> Index =
- getFunctionIndexForFile(Context, F, File);
+ getFunctionIndexForFile(F, File);
+
+ // Skip files without a function summary.
+ if (!Index)
+ continue;
+
CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
}
if (EC)
message(LDPL_FATAL, "Unable to open %s.thinlto.bc for writing: %s",
output_name.data(), EC.message().c_str());
- WriteFunctionSummaryToFile(&CombinedIndex, OS);
+ WriteFunctionSummaryToFile(CombinedIndex, OS);
OS.close();
cleanup_hook();
}
std::unique_ptr<Module> Combined(new Module("ld-temp.o", Context));
- Linker L(Combined.get());
+ Linker L(*Combined);
std::string DefaultTriple = sys::getDefaultTargetTriple();
M->setTargetTriple(DefaultTriple);
}
- if (L.linkInModule(M.get()))
+ if (L.linkInModule(*M))
message(LDPL_FATAL, "Failed to link module");
if (release_input_file(F.handle) != LDPS_OK)
message(LDPL_FATAL, "Failed to release file information");
path = output_name;
else
path = output_name + ".bc";
- saveBCFile(path, *L.getModule());
+ saveBCFile(path, *Combined);
if (options::TheOutputType == options::OT_BC_ONLY)
return LDPS_OK;
}