bool compileOptimizedToFile(const char **Name);
void restoreLinkageForExternals();
void applyScopeRestrictions();
+ void preserveDiscardableGVs(
+ Module &TheModule,
+ llvm::function_ref<bool(const GlobalValue &)> mustPreserveGV);
+
bool determineTarget();
std::unique_ptr<TargetMachine> createTargetMachine();
void DiagnosticHandler2(const DiagnosticInfo &DI);
void emitError(const std::string &ErrMsg);
+ void emitWarning(const std::string &ErrMsg);
LLVMContext &Context;
std::unique_ptr<Module> MergedModule;
// If a linkonce global is present in the MustPreserveSymbols, we need to make
// sure we honor this. To force the compiler to not drop it, we add it to the
// "llvm.compiler.used" global.
-static void preserveDiscardableGVs(
+void LTOCodeGenerator::preserveDiscardableGVs(
Module &TheModule,
llvm::function_ref<bool(const GlobalValue &)> mustPreserveGV) {
SetVector<Constant *> UsedValuesSet;
return;
if (!mustPreserveGV(GV))
return;
- assert(!GV.hasAvailableExternallyLinkage() && !GV.hasInternalLinkage());
+ if (GV.hasAvailableExternallyLinkage()) {
+ emitWarning(
+ (Twine("Linker asked to preserve available_externally global: '") +
+ GV.getName() + "'").str());
+ return;
+ }
+ if (GV.hasInternalLinkage()) {
+ emitWarning((Twine("Linker asked to preserve internal global: '") +
+ GV.getName() + "'").str());
+ return;
+ }
UsedValuesSet.insert(ConstantExpr::getBitCast(&GV, i8PTy));
};
for (auto &GV : TheModule)
else
Context.diagnose(LTODiagnosticInfo(ErrMsg));
}
+
+void LTOCodeGenerator::emitWarning(const std::string &ErrMsg) {
+ if (DiagHandler)
+ (*DiagHandler)(LTO_DS_WARNING, ErrMsg.c_str(), DiagContext);
+ else
+ Context.diagnose(LTODiagnosticInfo(ErrMsg, DS_Warning));
+}