]> granicus.if.org Git - llvm/commitdiff
Degrade assertions to a warning in LTOCodeGenerator for preserved linkonce
authorMehdi Amini <mehdi.amini@apple.com>
Thu, 5 May 2016 20:05:33 +0000 (20:05 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Thu, 5 May 2016 20:05:33 +0000 (20:05 +0000)
The assertions were assuming that the linker will not ask to preserve
a global that is internal or available_externally, as it does not
really make sense. In practice this break the bootstrap of clang,
I degrade to a warning for now.

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268671 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/LTO/LTOCodeGenerator.h
lib/LTO/LTOCodeGenerator.cpp

index 4f78d27b10da053fb362f1f621f7236759ca27d9..edf50f449d08d1aa108c4b41e339398ba18fbefa 100644 (file)
@@ -190,6 +190,10 @@ private:
   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();
 
@@ -198,6 +202,7 @@ private:
   void DiagnosticHandler2(const DiagnosticInfo &DI);
 
   void emitError(const std::string &ErrMsg);
+  void emitWarning(const std::string &ErrMsg);
 
   LLVMContext &Context;
   std::unique_ptr<Module> MergedModule;
index 1980965b1691735d6a7114d98cf7b1b91e92d125..a7dad55a81901f9964b4c9cbd79e55d068de1a0c 100644 (file)
@@ -351,7 +351,7 @@ std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
 // 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;
@@ -368,7 +368,17 @@ static void preserveDiscardableGVs(
       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)
@@ -643,3 +653,10 @@ void LTOCodeGenerator::emitError(const std::string &ErrMsg) {
   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));
+}