diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index b6066b557cbf..fb848325f96c 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -62,8 +62,11 @@ void lld::exitLld(int val) { // avoid intermittent crashes on Windows when exiting. llvm_shutdown(); - lld::outs().flush(); - lld::errs().flush(); + { + std::lock_guard lock(mu); + lld::outs().flush(); + lld::errs().flush(); + } _exit(val); } @@ -191,20 +194,26 @@ void ErrorHandler::error(const Twine &msg) { } } - std::lock_guard lock(mu); + bool exit = false; + { + std::lock_guard lock(mu); - if (errorLimit == 0 || errorCount < errorLimit) { - lld::errs() << sep << getLocation(msg) << ": " << Colors::RED - << "error: " << Colors::RESET << msg << "\n"; - } else if (errorCount == errorLimit) { - lld::errs() << sep << getLocation(msg) << ": " << Colors::RED - << "error: " << Colors::RESET << errorLimitExceededMsg << "\n"; - if (exitEarly) - exitLld(1); + if (errorLimit == 0 || errorCount < errorLimit) { + lld::errs() << sep << getLocation(msg) << ": " << Colors::RED + << "error: " << Colors::RESET << msg << "\n"; + } else if (errorCount == errorLimit) { + lld::errs() << sep << getLocation(msg) << ": " << Colors::RED + << "error: " << Colors::RESET << errorLimitExceededMsg + << "\n"; + exit = exitEarly; + } + + sep = getSeparator(msg); + ++errorCount; } - sep = getSeparator(msg); - ++errorCount; + if (exit) + exitLld(1); } void ErrorHandler::fatal(const Twine &msg) {