[llvm] r247461 - Add a non-exiting diagnostic handler for LTO.

Yunzhong Gao via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 13:01:53 PDT 2015


Author: ygao
Date: Fri Sep 11 15:01:53 2015
New Revision: 247461

URL: http://llvm.org/viewvc/llvm-project?rev=247461&view=rev
Log:
Add a non-exiting diagnostic handler for LTO.
This is in order to give LTO clients a chance to do some clean-up before
terminating the process.


Added:
    llvm/trunk/test/LTO/X86/diagnostic-handler-noexit.ll
Modified:
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/tools/llvm-lto/llvm-lto.cpp

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=247461&r1=247460&r2=247461&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Fri Sep 11 15:01:53 2015
@@ -64,17 +64,23 @@ const char* LTOCodeGenerator::getVersion
 #endif
 }
 
+static void handleLTODiagnostic(const DiagnosticInfo &DI) {
+  DiagnosticPrinterRawOStream DP(errs());                                
+  DI.print(DP);                                                          
+  errs() << "\n";
+}
+
 LTOCodeGenerator::LTOCodeGenerator()
     : Context(getGlobalContext()),
       MergedModule(new Module("ld-temp.o", Context)),
-      IRLinker(MergedModule.get()) {
+      IRLinker(MergedModule.get(), handleLTODiagnostic) {
   initializeLTOPasses();
 }
 
 LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
     : OwnedContext(std::move(Context)), Context(*OwnedContext),
       MergedModule(new Module("ld-temp.o", *OwnedContext)),
-      IRLinker(MergedModule.get()) {
+      IRLinker(MergedModule.get(), handleLTODiagnostic) {
   initializeLTOPasses();
 }
 

Added: llvm/trunk/test/LTO/X86/diagnostic-handler-noexit.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/diagnostic-handler-noexit.ll?rev=247461&view=auto
==============================================================================
--- llvm/trunk/test/LTO/X86/diagnostic-handler-noexit.ll (added)
+++ llvm/trunk/test/LTO/X86/diagnostic-handler-noexit.ll Fri Sep 11 15:01:53 2015
@@ -0,0 +1,13 @@
+; LTO default diagnostic handler should be non-exiting.
+; This test verifies that after addModule() encounters an error, the diagnostic
+; handler does not call exit(1) and instead returns to the caller of addModule.
+
+; RUN: llvm-as <%s >%t1
+; RUN: llvm-as <%s >%t2
+; RUN: not llvm-lto -o /dev/null %t1 %t2 2>&1 | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: Linking globals named 'goodboy': symbol multiply defined!
+; CHECK: llvm-lto{{.*}}: error adding file
+ at goodboy = global i32 3203383023, align 4    ; 0xbeefbeef

Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=247461&r1=247460&r2=247461&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Fri Sep 11 15:01:53 2015
@@ -216,8 +216,11 @@ int main(int argc, char **argv) {
     if (SetMergedModule && i == BaseArg) {
       // Transfer ownership to the code generator.
       CodeGen.setModule(std::move(Module));
-    } else if (!CodeGen.addModule(Module.get()))
+    } else if (!CodeGen.addModule(Module.get())) {
+      // Print a message here so that we know addModule() did not abort.
+      errs() << argv[0] << ": error adding file '" << InputFilenames[i] << "'\n";
       return 1;
+    }
   }
 
   // Add all the exported symbols to the table of symbols to preserve.




More information about the llvm-commits mailing list