[llvm-jitlink] Don't show FailedToMaterialize errors by default.

This patch makes printing of FailedToMaterialize errors in llvm-jitlink
conditional on the -show-err-failed-to-materialize option, which defaults to
false.

FailedToMaterialize errors are not root-cause errors: they're generated when a
symbol is requested but cannot be provided because of a failure that was
reported on some other error path. They typically don't convey actionable
information, and tend to flood error logs making root cause errors harder to
spot. Hiding FailedToMaterialize errors by default addresses these issues.
This commit is contained in:
Lang Hames 2022-04-17 09:32:02 -07:00
parent d98481a1e7
commit ef61592bb4
1 changed files with 49 additions and 4 deletions

View File

@ -224,9 +224,14 @@ static cl::opt<bool> AddSelfRelocations(
cl::desc("Add relocations to function pointers to the current function"),
cl::init(false), cl::cat(JITLinkCategory));
ExitOnError ExitOnErr;
static cl::opt<bool>
ShowErrFailedToMaterialize("show-err-failed-to-materialize",
cl::desc("Show FailedToMaterialize errors"),
cl::init(false), cl::cat(JITLinkCategory));
LLVM_ATTRIBUTE_USED void linkComponents() {
static ExitOnError ExitOnErr;
static LLVM_ATTRIBUTE_USED void linkComponents() {
errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper
<< (void *)&llvm_orc_deregisterEHFrameSectionWrapper
<< (void *)&llvm_orc_registerJITLoaderGDBWrapper;
@ -243,6 +248,34 @@ llvm_jitlink_setTestResultOverride(int64_t Value) {
static Error addSelfRelocations(LinkGraph &G);
namespace {
template <typename ErrT>
class ConditionalPrintErr {
public:
ConditionalPrintErr(bool C) : C(C) {}
void operator()(ErrT &EI) {
if (C) {
errs() << "llvm-jitlink error: ";
EI.log(errs());
errs() << "\n";
}
}
private:
bool C;
};
void reportLLVMJITLinkError(Error Err) {
handleAllErrors(
std::move(Err),
ConditionalPrintErr<orc::FailedToMaterialize>(ShowErrFailedToMaterialize),
ConditionalPrintErr<ErrorInfoBase>(true));
}
} // end anonymous namespace
namespace llvm {
static raw_ostream &
@ -1010,6 +1043,8 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
ErrorAsOutParameter _(&Err);
ES.setErrorReporter(reportLLVMJITLinkError);
if (auto MainJDOrErr = ES.createJITDylib("main"))
MainJD = &*MainJDOrErr;
else {
@ -1968,7 +2003,12 @@ int main(int argc, char *argv[]) {
TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
// Find the entry-point function unconditionally, since we want to force
// it to be materialized to collect stats.
EntryPoint = ExitOnErr(getMainEntryPoint(*S));
if (auto EP = getMainEntryPoint(*S))
EntryPoint = *EP;
else {
reportLLVMJITLinkError(EP.takeError());
exit(1);
}
LLVM_DEBUG({
dbgs() << "Using entry point \"" << EntryPointName
<< "\": " << formatv("{0:x16}", EntryPoint.getAddress()) << "\n";
@ -1977,7 +2017,12 @@ int main(int argc, char *argv[]) {
// If we're running with the ORC runtime then replace the entry-point
// with the __orc_rt_run_program symbol.
if (!OrcRuntime.empty()) {
EntryPoint = ExitOnErr(getOrcRuntimeEntryPoint(*S));
if (auto EP = getOrcRuntimeEntryPoint(*S))
EntryPoint = *EP;
else {
reportLLVMJITLinkError(EP.takeError());
exit(1);
}
LLVM_DEBUG({
dbgs() << "(called via __orc_rt_run_program_wrapper at "
<< formatv("{0:x16}", EntryPoint.getAddress()) << ")\n";