Skip to content

Commit 4a67b93

Browse files
committed
[ELF] Make checkError context-aware
1 parent 3b75a5c commit 4a67b93

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

lld/Common/ErrorHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ void lld::checkError(Error e) {
146146
[&](ErrorInfoBase &eib) { error(eib.message()); });
147147
}
148148

149+
void lld::checkError(ErrorHandler &eh, Error e) {
150+
handleAllErrors(std::move(e),
151+
[&](ErrorInfoBase &eib) { eh.error(eib.message()); });
152+
}
153+
149154
// This is for --vs-diagnostics.
150155
//
151156
// Normally, lld's error message starts with argv[0]. Therefore, it usually

lld/ELF/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
724724
}
725725

726726
if (ctx.arg.timeTraceEnabled) {
727-
checkError(timeTraceProfilerWrite(
728-
args.getLastArgValue(OPT_time_trace_eq).str(), ctx.arg.outputFile));
727+
checkError(
728+
*ctx.errHandler,
729+
timeTraceProfilerWrite(args.getLastArgValue(OPT_time_trace_eq).str(),
730+
ctx.arg.outputFile));
729731
timeTraceProfilerCleanup();
730732
}
731733
}

lld/ELF/LTO.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ static lto::Config createConfig(Ctx &ctx) {
165165
}
166166

167167
if (!ctx.arg.saveTempsArgs.empty())
168-
checkError(c.addSaveTemps(ctx.arg.outputFile.str() + ".",
169-
/*UseInputModulePath*/ true,
170-
ctx.arg.saveTempsArgs));
168+
checkError(*ctx.errHandler, c.addSaveTemps(ctx.arg.outputFile.str() + ".",
169+
/*UseInputModulePath*/ true,
170+
ctx.arg.saveTempsArgs));
171171
return c;
172172
}
173173

@@ -278,7 +278,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
278278
// their values are still not final.
279279
r.LinkerRedefined = sym->scriptDefined;
280280
}
281-
checkError(ltoObj->add(std::move(f.obj), resols));
281+
checkError(*ctx.errHandler, ltoObj->add(std::move(f.obj), resols));
282282
}
283283

284284
// If LazyObjFile has not been added to link, emit empty index files.
@@ -329,13 +329,14 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
329329
}));
330330

331331
if (!ctx.bitcodeFiles.empty())
332-
checkError(ltoObj->run(
333-
[&](size_t task, const Twine &moduleName) {
334-
buf[task].first = moduleName.str();
335-
return std::make_unique<CachedFileStream>(
336-
std::make_unique<raw_svector_ostream>(buf[task].second));
337-
},
338-
cache));
332+
checkError(*ctx.errHandler, ltoObj->run(
333+
[&](size_t task, const Twine &moduleName) {
334+
buf[task].first = moduleName.str();
335+
return std::make_unique<CachedFileStream>(
336+
std::make_unique<raw_svector_ostream>(
337+
buf[task].second));
338+
},
339+
cache));
339340

340341
// Emit empty index files for non-indexed files but not in single-module mode.
341342
if (ctx.arg.thinLTOModulesToCompile.empty()) {

lld/include/lld/Common/ErrorHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class SyncStream {
172172

173173
void diagnosticHandler(const llvm::DiagnosticInfo &di);
174174
void checkError(Error e);
175+
void checkError(ErrorHandler &eh, Error e);
175176

176177
// check functions are convenient functions to strip errors
177178
// from error-or-value objects.

0 commit comments

Comments
 (0)