From 941f06282a3d304a96c1ea71b335be5fc91d8f7c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 17 Feb 2022 11:54:57 -0800 Subject: [PATCH] [lld] Make error handling functions opaque The inline `lld::error` expands to two function calls `errorHandler` and `error` where the latter is opaque. Move the functions to .cpp files to decrease code size. My x86-64 lld executable is 9KiB smaller. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D120002 --- lld/Common/ErrorHandler.cpp | 12 ++++++++++++ lld/include/lld/Common/ErrorHandler.h | 18 +++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index e557e533dedc..4cacd82c9f35 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -53,6 +53,18 @@ void ErrorHandler::flushStreams() { ErrorHandler &lld::errorHandler() { return context().e; } +void lld::error(const Twine &msg) { errorHandler().error(msg); } +void lld::error(const Twine &msg, ErrorTag tag, ArrayRef args) { + errorHandler().error(msg, tag, args); +} +void lld::fatal(const Twine &msg) { errorHandler().fatal(msg); } +void lld::log(const Twine &msg) { errorHandler().log(msg); } +void lld::message(const Twine &msg, llvm::raw_ostream &s) { + errorHandler().message(msg, s); +} +void lld::warn(const Twine &msg) { errorHandler().warn(msg); } +uint64_t lld::errorCount() { return errorHandler().errorCount; } + raw_ostream &lld::outs() { ErrorHandler &e = errorHandler(); return e.outs(); diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h index ce077290d60b..0ba4787e5888 100644 --- a/lld/include/lld/Common/ErrorHandler.h +++ b/lld/include/lld/Common/ErrorHandler.h @@ -143,17 +143,13 @@ private: /// Returns the default error handler. ErrorHandler &errorHandler(); -inline void error(const Twine &msg) { errorHandler().error(msg); } -inline void error(const Twine &msg, ErrorTag tag, ArrayRef args) { - errorHandler().error(msg, tag, args); -} -[[noreturn]] inline void fatal(const Twine &msg) { errorHandler().fatal(msg); } -inline void log(const Twine &msg) { errorHandler().log(msg); } -inline void message(const Twine &msg, llvm::raw_ostream &s = outs()) { - errorHandler().message(msg, s); -} -inline void warn(const Twine &msg) { errorHandler().warn(msg); } -inline uint64_t errorCount() { return errorHandler().errorCount; } +void error(const Twine &msg); +void error(const Twine &msg, ErrorTag tag, ArrayRef args); +[[noreturn]] void fatal(const Twine &msg); +void log(const Twine &msg); +void message(const Twine &msg, llvm::raw_ostream &s = outs()); +void warn(const Twine &msg); +uint64_t errorCount(); [[noreturn]] void exitLld(int val);