Skip to content

Commit 402fb0d

Browse files
committed
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. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@252774 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent aab02dd commit 402fb0d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/LTO/LTOCodeGenerator.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ const char* LTOCodeGenerator::getVersionString() {
6363
#endif
6464
}
6565

66+
static void handleLTODiagnostic(const DiagnosticInfo &DI) {
67+
DiagnosticPrinterRawOStream DP(errs());
68+
DI.print(DP);
69+
errs() << "\n";
70+
}
71+
6672
LTOCodeGenerator::LTOCodeGenerator()
67-
: Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context)) {
73+
: Context(getGlobalContext()), IRLinker(new Module("ld-temp.o", Context),
74+
handleLTODiagnostic) {
6875
initializeLTOPasses();
6976
}
7077

7178
LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
7279
: OwnedContext(std::move(Context)), Context(*OwnedContext),
73-
IRLinker(new Module("ld-temp.o", *OwnedContext)) {
80+
IRLinker(new Module("ld-temp.o", *OwnedContext), handleLTODiagnostic) {
7481
initializeLTOPasses();
7582
}
7683

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; LTO default diagnostic handler should be non-exiting.
2+
; This test verifies that after addModule() encounters an error, the diagnostic
3+
; handler does not call exit(1) and instead returns to the caller of addModule.
4+
5+
; RUN: llvm-as <%s >%t1
6+
; RUN: llvm-as <%s >%t2
7+
; RUN: not llvm-lto -o /dev/null %t1 %t2 2>&1 | FileCheck %s
8+
9+
target triple = "x86_64-unknown-linux-gnu"
10+
11+
; CHECK: Linking globals named 'goodboy': symbol multiply defined!
12+
; CHECK: llvm-lto{{.*}}: error adding file
13+
@goodboy = global i32 3203383023, align 4 ; 0xbeefbeef

tools/llvm-lto/llvm-lto.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ int main(int argc, char **argv) {
214214
if (SetMergedModule && i == BaseArg) {
215215
// Transfer ownership to the code generator.
216216
CodeGen.setModule(Module.release());
217-
} else if (!CodeGen.addModule(Module.get()))
217+
} else if (!CodeGen.addModule(Module.get())) {
218+
// Print a message here so that we know addModule() did not abort.
219+
errs() << argv[0] << ": error adding file '" << InputFilenames[i] << "'\n";
218220
return 1;
221+
}
219222

220223
unsigned NumSyms = LTOMod->getSymbolCount();
221224
for (unsigned I = 0; I < NumSyms; ++I) {

0 commit comments

Comments
 (0)