llvm.org GIT mirror llvm / 8de34ad
Add a libLTO diagnostic handler that supports lto_get_error_message API This is a follow-up from the previous discussion on the thread: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151019/307763.html The LibLTO lto_get_error_message() API reads error messages from a std::string sLastErrorString. Instead of passing this string around as an argument, this patch creates a diagnostic handler and then sends this handler to the constructor of LTOCodeGenerator. Differential Revision: http://reviews.llvm.org/D14313 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252791 91177308-0d34-0410-b5e6-96231b3b80d8 Yunzhong Gao 3 years ago
3 changed file(s) with 14 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6363 #endif
6464 }
6565
66 static void handleLTODiagnostic(const DiagnosticInfo &DI) {
67 DiagnosticPrinterRawOStream DP(errs());
68 DI.print(DP);
69 errs() << "\n";
70 }
71
7266 LTOCodeGenerator::LTOCodeGenerator()
7367 : Context(getGlobalContext()),
7468 MergedModule(new Module("ld-temp.o", Context)),
75 IRLinker(MergedModule.get(), handleLTODiagnostic) {
69 IRLinker(MergedModule.get()) {
7670 initializeLTOPasses();
7771 }
7872
7973 LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr Context)
8074 : OwnedContext(std::move(Context)), Context(*OwnedContext),
8175 MergedModule(new Module("ld-temp.o", *OwnedContext)),
82 IRLinker(MergedModule.get(), handleLTODiagnostic) {
76 IRLinker(MergedModule.get()) {
8377 initializeLTOPasses();
8478 }
8579
33
44 ; RUN: llvm-as <%s >%t1
55 ; RUN: llvm-as <%s >%t2
6 ; RUN: not llvm-lto -o /dev/null %t1 %t2 2>&1 | FileCheck %s
6 ; RUN: not llvm-lto -use-diagnostic-handler -o /dev/null %t1 %t2 2>&1 | FileCheck %s
77
88 target triple = "x86_64-unknown-linux-gnu"
99
10 ; CHECK: Linking globals named 'goodboy': symbol multiply defined!
10 ; CHECK: llvm-lto: error: Linking globals named 'goodboy': symbol multiply defined!
1111 ; CHECK: llvm-lto{{.*}}: error adding file
1212 @goodboy = global i32 3203383023, align 4 ; 0xbeefbeef
8484
8585 namespace {
8686
87 static void handleLibLTODiagnostic(lto_codegen_diagnostic_severity_t Severity,
88 const char *Msg, void *) {
89 sLastErrorString = Msg;
90 sLastErrorString += "\n";
91 }
92
8793 // This derived class owns the native object file. This helps implement the
8894 // libLTO API semantics, which require that the code generator owns the object
8995 // file.
9096 struct LibLTOCodeGenerator : LTOCodeGenerator {
91 LibLTOCodeGenerator() {}
97 LibLTOCodeGenerator() {
98 setDiagnosticHandler(handleLibLTODiagnostic, nullptr); }
9299 LibLTOCodeGenerator(std::unique_ptr Context)
93 : LTOCodeGenerator(std::move(Context)) {}
100 : LTOCodeGenerator(std::move(Context)) {
101 setDiagnosticHandler(handleLibLTODiagnostic, nullptr); }
94102
95103 std::unique_ptr NativeObjectFile;
96104 };