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.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Summary of the changes:
- Instead of #include "Error.h", #include "lld/Common/ErrorHandler.h".
- Instead of ColorDiagnostics, ErrorLimit, and FatalWarnings being properties of the Config object, they are now set on the ErrorHandler object.
- Removed the fatal() variants that take Error or std::error_code. This was previously done for ELF, so I've done it here for COFF too.
- Instead of ErrorCount as a global variable, the value is now retrieved by calling the errorCount() function.
I chose ErrorHandler instead of Error as the name of the header file, because there is already an Error.h in lld/Core, and also in LLVM.
lld/include/lld/Common/ErrorHandler.h | ||
---|---|---|
50–81 ↗ | (On Diff #120133) | These Java-ish method chains are not very lld-ish. It is better to directly expose the members. |
85–93 ↗ | (On Diff #120133) | You can use C++11-style member initialization because all these values are constant. E.g. bool ColorDiagnostics = false; |
lld/include/lld/Common/ErrorHandler.h | ||
---|---|---|
50–54 ↗ | (On Diff #120292) | The default ctor delegates to it. I suppose I could just only have a default ctor. |
lld/include/lld/Common/ErrorHandler.h | ||
---|---|---|
50–54 ↗ | (On Diff #120292) | Yeah, and initializing a member with an ELF-ish default value seems a bit odd if you move this file to Common directory. |
lld/include/lld/Common/ErrorHandler.h | ||
---|---|---|
50–54 ↗ | (On Diff #120292) | Yeah. The thinking is basically that this is the common case, with the Windows variant being the odd one out, but I'm happy to do it a different way if you have suggestions. I wasn't able to think of a way I really like better. |
- Removed ErrorHandler parameter to handleColorDiagnostics.
- Cut number of constructors for ErrorHandler down to one.
- Initialize all fields in their definition instead of in the contructor.
- Replaced default ErrorLimitExceededMsg with something more generic.
- clang-format