From 6c15be6813546f463a4ab10ca5cb0abb35dabdca Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Fri, 6 Dec 2024 15:08:58 +0100 Subject: [PATCH] Always handle Error of createObjectFile This avoids test failures because the destructor of llvm::Error aborts he program "due to an unhandled Error", which can happen in case of race conditions with concurrent file operations in a directory. --- .../DynamicLibraryManagerSymbol.cpp | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 4577c329a0..5d523776aa 100644 --- a/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -748,11 +748,14 @@ namespace cling { auto ObjFileOrErr = llvm::object::ObjectFile::createObjectFile(FileName); if (llvm::Error Err = ObjFileOrErr.takeError()) { + // Note: It is important to always call handleAllErrors, otherwise + // the destructor of llvm::Error will abort the program "due to an + // unhandled Error" + std::string Message; + handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase& EIB) { + Message += EIB.message() + "; "; + }); if (DEBUG > 1) { - std::string Message; - handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase &EIB) { - Message += EIB.message() + "; "; - }); cling::errs() << "Dyld::ScanForLibraries: Failed to read object file " << FileName.str() << " Errors: " << Message << "\n"; @@ -1007,11 +1010,14 @@ namespace cling { auto ObjF = llvm::object::ObjectFile::createObjectFile(library_filename); if (llvm::Error Err = ObjF.takeError()) { + // Note: It is important to always call handleAllErrors, otherwise the + // destructor of llvm::Error will abort the program "due to an unhandled + // Error" + std::string Message; + handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase& EIB) { + Message += EIB.message() + "; "; + }); if (DEBUG > 1) { - std::string Message; - handleAllErrors(std::move(Err), [&](llvm::ErrorInfoBase &EIB) { - Message += EIB.message() + "; "; - }); cling::errs() << "Dyld::ContainsSymbol: Failed to read object file " << library_filename << " Errors: " << Message << "\n"; } @@ -1141,6 +1147,9 @@ namespace cling { auto ObjF = llvm::object::ObjectFile::createObjectFile(FileName); if (!ObjF) { + // Note: It is important to always call handleAllErrors, otherwise the + // destructor of llvm::Error will abort the program "due to an unhandled + // Error" std::string Message; handleAllErrors(ObjF.takeError(), [&](llvm::ErrorInfoBase &EIB) { Message += EIB.message() + "; ";