diff options
Diffstat (limited to 'lld/Common/ErrorHandler.cpp')
| -rw-r--r-- | lld/Common/ErrorHandler.cpp | 42 | 
1 files changed, 23 insertions, 19 deletions
| diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index b91854c51cef..b6066b557cbf 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -26,7 +26,8 @@ using namespace llvm;  using namespace lld;  // The functions defined in this file can be called from multiple threads, -// but outs() or errs() are not thread-safe. We protect them using a mutex. +// but lld::outs() or lld::errs() are not thread-safe. We protect them using a +// mutex.  static std::mutex mu;  // We want to separate multi-line messages with a newline. `sep` is "\n" @@ -39,27 +40,30 @@ static StringRef getSeparator(const Twine &msg) {    return "";  } +raw_ostream *lld::stdoutOS; +raw_ostream *lld::stderrOS; + +raw_ostream &lld::outs() { return stdoutOS ? *stdoutOS : llvm::outs(); } +raw_ostream &lld::errs() { return stderrOS ? *stderrOS : llvm::errs(); } +  ErrorHandler &lld::errorHandler() {    static ErrorHandler handler;    return handler;  } -void lld::enableColors(bool enable) { -  errorHandler().errorOS->enable_colors(enable); -} -  void lld::exitLld(int val) {    // Delete any temporary file, while keeping the memory mapping open.    if (errorHandler().outputBuffer)      errorHandler().outputBuffer->discard(); -  // Dealloc/destroy ManagedStatic variables before calling -  // _exit(). In a non-LTO build, this is a nop. In an LTO -  // build allows us to get the output of -time-passes. +  // Dealloc/destroy ManagedStatic variables before calling _exit(). +  // In an LTO build, allows us to get the output of -time-passes. +  // Ensures that the thread pool for the parallel algorithms is stopped to +  // avoid intermittent crashes on Windows when exiting.    llvm_shutdown(); -  outs().flush(); -  errs().flush(); +  lld::outs().flush(); +  lld::errs().flush();    _exit(val);  } @@ -149,13 +153,13 @@ void ErrorHandler::log(const Twine &msg) {    if (!verbose)      return;    std::lock_guard<std::mutex> lock(mu); -  *errorOS << logName << ": " << msg << "\n"; +  lld::errs() << logName << ": " << msg << "\n";  }  void ErrorHandler::message(const Twine &msg) {    std::lock_guard<std::mutex> lock(mu); -  outs() << msg << "\n"; -  outs().flush(); +  lld::outs() << msg << "\n"; +  lld::outs().flush();  }  void ErrorHandler::warn(const Twine &msg) { @@ -165,8 +169,8 @@ void ErrorHandler::warn(const Twine &msg) {    }    std::lock_guard<std::mutex> lock(mu); -  *errorOS << sep << getLocation(msg) << ": " << Colors::MAGENTA -           << "warning: " << Colors::RESET << msg << "\n"; +  lld::errs() << sep << getLocation(msg) << ": " << Colors::MAGENTA +              << "warning: " << Colors::RESET << msg << "\n";    sep = getSeparator(msg);  } @@ -190,11 +194,11 @@ void ErrorHandler::error(const Twine &msg) {    std::lock_guard<std::mutex> lock(mu);    if (errorLimit == 0 || errorCount < errorLimit) { -    *errorOS << sep << getLocation(msg) << ": " << Colors::RED -             << "error: " << Colors::RESET << msg << "\n"; +    lld::errs() << sep << getLocation(msg) << ": " << Colors::RED +                << "error: " << Colors::RESET << msg << "\n";    } else if (errorCount == errorLimit) { -    *errorOS << sep << getLocation(msg) << ": " << Colors::RED -             << "error: " << Colors::RESET << errorLimitExceededMsg << "\n"; +    lld::errs() << sep << getLocation(msg) << ": " << Colors::RED +                << "error: " << Colors::RESET << errorLimitExceededMsg << "\n";      if (exitEarly)        exitLld(1);    } | 
