diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2015-11-11 21:41:49 +0300 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2015-11-11 21:41:49 +0300 |
commit | 818402cd789811f9dd1386d184e5eeac436df1d1 (patch) | |
tree | fe88848ebf86bc4168bbf86006d9c4472d11ef00 | |
parent | 4a86227eca1c13978d40803b678386aa8597e131 (diff) |
Merging r247461:
------------------------------------------------------------------------
r247461 | Yunzhong_Gao | 2015-09-11 16:01:53 -0400 (Fri, 11 Sep 2015) | 4 lines
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.
------------------------------------------------------------------------
llvm-svn: 252774
-rw-r--r-- | llvm/lib/LTO/LTOCodeGenerator.cpp | 11 | ||||
-rw-r--r-- | llvm/test/LTO/X86/diagnostic-handler-noexit.ll | 13 | ||||
-rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 5 |
3 files changed, 26 insertions, 3 deletions
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 149ec6a4f372..25ae4ac76e3c 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -63,14 +63,21 @@ const char* LTOCodeGenerator::getVersionString() { #endif } +static void handleLTODiagnostic(const DiagnosticInfo &DI) { + DiagnosticPrinterRawOStream DP(errs()); + DI.print(DP); + errs() << "\n"; +} + LTOCodeGenerator::LTOCodeGenerator() - : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) { + : Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context), + handleLTODiagnostic) { initializeLTOPasses(); } LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context) : OwnedContext(std::move(Context)), Context(*OwnedContext), - IRLinker(new Module("ld-temp.o", *OwnedContext)) { + IRLinker(new Module("ld-temp.o", *OwnedContext), handleLTODiagnostic) { initializeLTOPasses(); } diff --git a/llvm/test/LTO/X86/diagnostic-handler-noexit.ll b/llvm/test/LTO/X86/diagnostic-handler-noexit.ll new file mode 100644 index 000000000000..be768c900f14 --- /dev/null +++ b/llvm/test/LTO/X86/diagnostic-handler-noexit.ll @@ -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 +@goodboy = global i32 3203383023, align 4 ; 0xbeefbeef diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 9678c8397e0e..08218986f45b 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -214,8 +214,11 @@ int main(int argc, char **argv) { if (SetMergedModule && i == BaseArg) { // Transfer ownership to the code generator. CodeGen.setModule(Module.release()); - } 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; + } unsigned NumSyms = LTOMod->getSymbolCount(); for (unsigned I = 0; I < NumSyms; ++I) { |