[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
//===- ErrorHandler.cpp ---------------------------------------------------===//
|
2015-08-06 23:08:23 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-08-06 23:08:23 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2017-10-14 02:22:55 +08:00
|
|
|
|
|
|
|
#include "lld/Common/Threads.h"
|
2015-08-06 23:08:23 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2018-05-23 04:20:25 +08:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
|
|
|
#include "llvm/IR/DiagnosticPrinter.h"
|
2016-11-11 03:39:05 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2015-08-06 23:08:23 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-11-24 02:34:28 +08:00
|
|
|
#include <mutex>
|
2019-07-17 22:54:02 +08:00
|
|
|
#include <regex>
|
2015-08-06 23:08:23 +08:00
|
|
|
|
2016-10-27 21:32:32 +08:00
|
|
|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2016-07-07 22:06:38 +08:00
|
|
|
using namespace llvm;
|
2017-03-24 08:15:37 +08:00
|
|
|
using namespace lld;
|
ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.
In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.
This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.
In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.
I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.
http://reviews.llvm.org/D16641
llvm-svn: 259069
2016-01-29 02:40:06 +08:00
|
|
|
|
2016-11-24 02:34:28 +08:00
|
|
|
// 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.
|
2019-07-11 13:40:30 +08:00
|
|
|
static std::mutex mu;
|
2016-11-24 02:34:28 +08:00
|
|
|
|
2017-03-31 03:13:47 +08:00
|
|
|
// Prints "\n" or does nothing, depending on Msg contents of
|
|
|
|
// the previous call of this function.
|
2019-07-11 13:40:30 +08:00
|
|
|
static void newline(raw_ostream *errorOS, const Twine &msg) {
|
2017-03-31 03:13:47 +08:00
|
|
|
// True if the previous error message contained "\n".
|
|
|
|
// We want to separate multi-line error messages with a newline.
|
2019-07-11 13:40:30 +08:00
|
|
|
static bool flag;
|
2017-03-31 03:13:47 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
if (flag)
|
|
|
|
*errorOS << "\n";
|
|
|
|
flag = StringRef(msg.str()).contains('\n');
|
2017-03-31 03:13:47 +08:00
|
|
|
}
|
|
|
|
|
2017-10-28 02:04:49 +08:00
|
|
|
ErrorHandler &lld::errorHandler() {
|
2019-07-11 13:40:30 +08:00
|
|
|
static ErrorHandler handler;
|
|
|
|
return handler;
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void lld::exitLld(int val) {
|
2018-08-25 02:36:42 +08:00
|
|
|
// Delete any temporary file, while keeping the memory mapping open.
|
2019-07-11 13:40:30 +08:00
|
|
|
if (errorHandler().outputBuffer)
|
|
|
|
errorHandler().outputBuffer->discard();
|
2017-11-14 02:06:43 +08:00
|
|
|
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
// 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.
|
|
|
|
llvm_shutdown();
|
|
|
|
|
|
|
|
outs().flush();
|
|
|
|
errs().flush();
|
2019-07-11 13:40:30 +08:00
|
|
|
_exit(val);
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void lld::diagnosticHandler(const DiagnosticInfo &di) {
|
|
|
|
SmallString<128> s;
|
|
|
|
raw_svector_ostream os(s);
|
|
|
|
DiagnosticPrinterRawOStream dp(os);
|
|
|
|
di.print(dp);
|
|
|
|
switch (di.getSeverity()) {
|
2018-07-03 05:01:43 +08:00
|
|
|
case DS_Error:
|
2019-07-11 13:40:30 +08:00
|
|
|
error(s);
|
2018-07-03 05:01:43 +08:00
|
|
|
break;
|
|
|
|
case DS_Warning:
|
2019-07-11 13:40:30 +08:00
|
|
|
warn(s);
|
2018-07-03 05:01:43 +08:00
|
|
|
break;
|
|
|
|
case DS_Remark:
|
|
|
|
case DS_Note:
|
2019-07-11 13:40:30 +08:00
|
|
|
message(s);
|
2018-07-03 05:01:43 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-05-23 04:20:25 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void lld::checkError(Error e) {
|
|
|
|
handleAllErrors(std::move(e),
|
|
|
|
[&](ErrorInfoBase &eib) { error(eib.message()); });
|
2018-05-23 04:20:25 +08:00
|
|
|
}
|
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
std::string ErrorHandler::getLocation(const Twine &msg) {
|
|
|
|
if (!vsDiagnostics)
|
|
|
|
return logName;
|
|
|
|
|
|
|
|
static std::regex regexes[] = {
|
|
|
|
std::regex(
|
|
|
|
R"(^undefined (?:\S+ )?symbol:.*\n>>> referenced by (\S+):(\d+)\n.*)"),
|
2019-07-17 22:54:02 +08:00
|
|
|
std::regex(R"(^undefined symbol:.*\n>>> referenced by (.*):)"),
|
|
|
|
std::regex(
|
|
|
|
R"(^duplicate symbol: .*\n>>> defined in (\S+)\n>>> defined in.*)"),
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
std::regex(R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+).*)"),
|
|
|
|
std::regex(R"(.*\n>>> defined in .*\n>>> referenced by (\S+):(\d+))"),
|
2019-07-17 22:54:02 +08:00
|
|
|
std::regex(R"((\S+):(\d+): unclosed quote)"),
|
|
|
|
};
|
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
std::string str = msg.str();
|
2019-07-17 22:54:02 +08:00
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
for (std::regex &re : regexes) {
|
|
|
|
std::smatch match;
|
|
|
|
if (!std::regex_search(str, match, re))
|
|
|
|
continue;
|
2019-07-17 22:54:02 +08:00
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
if (match.size() > 2)
|
|
|
|
return match.str(1) + "(" + match.str(2) + ")";
|
|
|
|
return match.str(1);
|
2019-07-17 22:54:02 +08:00
|
|
|
}
|
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
return logName;
|
2016-11-26 04:27:32 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void ErrorHandler::log(const Twine &msg) {
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
if (!verbose)
|
|
|
|
return;
|
|
|
|
std::lock_guard<std::mutex> lock(mu);
|
|
|
|
*errorOS << logName << ": " << msg << "\n";
|
2017-02-22 07:22:56 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void ErrorHandler::message(const Twine &msg) {
|
|
|
|
std::lock_guard<std::mutex> lock(mu);
|
|
|
|
outs() << msg << "\n";
|
2017-02-22 07:22:56 +08:00
|
|
|
outs().flush();
|
2016-02-26 02:56:01 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void ErrorHandler::warn(const Twine &msg) {
|
|
|
|
if (fatalWarnings) {
|
|
|
|
error(msg);
|
2016-11-24 02:34:28 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 03:13:47 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::lock_guard<std::mutex> lock(mu);
|
|
|
|
newline(errorOS, msg);
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
*errorOS << getLocation(msg) << ": " << Color::MAGENTA
|
|
|
|
<< "warning: " << Color::RESET << msg << "\n";
|
2019-08-01 17:58:03 +08:00
|
|
|
}
|
|
|
|
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
void ErrorHandler::error(const Twine &msg) {
|
|
|
|
// If Microsoft Visual Studio-style error message mode is enabled,
|
|
|
|
// this particular error is printed out as two errors.
|
2019-08-01 17:58:03 +08:00
|
|
|
if (vsDiagnostics) {
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
static std::regex re(R"(^(duplicate symbol: .*))"
|
|
|
|
R"((\n>>> defined at \S+:\d+\n>>>.*))"
|
|
|
|
R"((\n>>> defined at \S+:\d+\n>>>.*))");
|
|
|
|
std::string str = msg.str();
|
|
|
|
std::smatch m;
|
|
|
|
|
|
|
|
if (std::regex_match(str, m, re)) {
|
|
|
|
error(m.str(1) + m.str(2));
|
|
|
|
error(m.str(1) + m.str(3));
|
2019-08-01 17:58:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
std::lock_guard<std::mutex> lock(mu);
|
2016-11-24 02:34:28 +08:00
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
if (errorLimit == 0 || errorCount < errorLimit) {
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
newline(errorOS, msg);
|
|
|
|
*errorOS << getLocation(msg) << ": " << Color::RED
|
|
|
|
<< "error: " << Color::RESET << msg << "\n";
|
2019-07-11 13:40:30 +08:00
|
|
|
} else if (errorCount == errorLimit) {
|
2019-07-25 04:56:23 +08:00
|
|
|
newline(errorOS, msg);
|
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.
So, if you print out "error: " in red, for example, you had to do
something like this:
OS.changeColor(raw_ostream::RED);
OS << "error: ";
OS.resetColor();
With this patch, you can write the same code as follows:
OS << raw_ostream::RED << "error: " << raw_ostream::RESET;
2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.
Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.
Differential Revision: https://reviews.llvm.org/D65564
llvm-svn: 367649
2019-08-02 12:48:30 +08:00
|
|
|
*errorOS << getLocation(msg) << ": " << Color::RED
|
|
|
|
<< "error: " << Color::RESET << errorLimitExceededMsg << "\n";
|
2019-07-11 13:40:30 +08:00
|
|
|
if (exitEarly)
|
2016-11-24 02:15:37 +08:00
|
|
|
exitLld(1);
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
++errorCount;
|
2015-08-06 23:08:23 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:40:30 +08:00
|
|
|
void ErrorHandler::fatal(const Twine &msg) {
|
|
|
|
error(msg);
|
2016-10-27 21:32:32 +08:00
|
|
|
exitLld(1);
|
ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.
In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.
This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.
In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.
I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.
http://reviews.llvm.org/D16641
llvm-svn: 259069
2016-01-29 02:40:06 +08:00
|
|
|
}
|