From 3b75a5c4c84d17d6647ba079391722ed9be09f85 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 16 Nov 2024 15:34:42 -0800 Subject: [PATCH] [ELF] Replace message(...) with Msg(ctx) --- lld/Common/ErrorHandler.cpp | 3 +++ lld/ELF/Config.h | 3 +++ lld/ELF/Driver.cpp | 11 ++++++----- lld/ELF/ICF.cpp | 2 +- lld/ELF/InputFiles.cpp | 2 +- lld/ELF/MarkLive.cpp | 2 +- lld/ELF/Symbols.cpp | 2 +- lld/include/lld/Common/ErrorHandler.h | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index 217554816659..9526db7fefc9 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -342,6 +342,9 @@ SyncStream::~SyncStream() { case DiagLevel::Log: e.log(buf); break; + case DiagLevel::Msg: + e.message(buf, llvm::outs()); + break; case DiagLevel::Warn: e.warn(buf); break; diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index c847a32bb5f1..3198b77353fc 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -710,6 +710,9 @@ inline const ELFSyncStream &operator<<(const ELFSyncStream &s, Error v) { // Report a log if --verbose is specified. ELFSyncStream Log(Ctx &ctx); +// Print a message to stdout. +ELFSyncStream Msg(Ctx &ctx); + // Report a warning. Upgraded to an error if --fatal-warnings is specified. ELFSyncStream Warn(Ctx &ctx); diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 8f23514bcdcd..41816025f38b 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -85,6 +85,7 @@ static void setConfigs(Ctx &ctx, opt::InputArgList &args); static void readConfigs(Ctx &ctx, opt::InputArgList &args); ELFSyncStream elf::Log(Ctx &ctx) { return {ctx, DiagLevel::Log}; } +ELFSyncStream elf::Msg(Ctx &ctx) { return {ctx, DiagLevel::Msg}; } ELFSyncStream elf::Warn(Ctx &ctx) { return {ctx, DiagLevel::Warn}; } ELFSyncStream elf::Err(Ctx &ctx) { return {ctx, ctx.arg.noinhibitExec ? DiagLevel::Warn : DiagLevel::Err}; @@ -672,7 +673,7 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { // of Libtool. We cannot convince every software developer to migrate to // the latest version and re-generate scripts. So we have this hack. if (args.hasArg(OPT_v) || args.hasArg(OPT_version)) - message(getLLDVersion() + " (compatible with GNU linkers)"); + Msg(ctx) << getLLDVersion() << " (compatible with GNU linkers)"; if (const char *path = getReproduceOption(args)) { // Note that --reproduce is a debug option so you can ignore it @@ -1151,10 +1152,10 @@ static void ltoValidateAllVtablesHaveTypeInfos(Ctx &ctx, ctx.ltoAllVtablesHaveTypeInfos = vtableSymbolsWithNoRTTI.empty(); // Check for unmatched RTTI symbols for (StringRef s : vtableSymbolsWithNoRTTI) { - message( - "--lto-validate-all-vtables-have-type-infos: RTTI missing for vtable " - "_ZTV" + - s + ", --lto-whole-program-visibility disabled"); + Msg(ctx) << "--lto-validate-all-vtables-have-type-infos: RTTI missing for " + "vtable " + "_ZTV" + << s << ", --lto-whole-program-visibility disabled"; } } diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 0bf551771130..7090ca779b0e 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -461,7 +461,7 @@ static void combineRelocHashes(unsigned cnt, InputSection *isec, static void print(Ctx &ctx, const Twine &s) { if (ctx.arg.printIcfSections) - message(s); + Msg(ctx) << s; } // The main function of ICF. diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index fb19fce257a1..63dfffd1d9b8 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -316,7 +316,7 @@ template static void doParseFile(Ctx &ctx, InputFile *file) { } if (ctx.arg.trace) - message(toStr(ctx, file)); + Msg(ctx) << file; if (file->kind() == InputFile::ObjKind) { ctx.objectFiles.push_back(cast(file)); diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 066c52540123..df81d443accd 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -391,7 +391,7 @@ template void elf::markLive(Ctx &ctx) { if (ctx.arg.printGcSections) for (InputSectionBase *sec : ctx.inputSections) if (!sec->isLive()) - message("removing unused section " + toStr(ctx, sec)); + Msg(ctx) << "removing unused section " << sec; } template void elf::markLive(Ctx &); diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 670a748363c5..baa704363efb 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -295,7 +295,7 @@ void elf::printTraceSymbol(const Symbol &sym, StringRef name) { else s = ": definition of "; - message(toStr(sym.file->ctx, sym.file) + s + name); + Msg(ctx) << toStr(sym.file->ctx, sym.file) << s << name; } static void recordWhyExtract(Ctx &ctx, const InputFile *reference, diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h index 996eeae423c9..6be862e5115d 100644 --- a/lld/include/lld/Common/ErrorHandler.h +++ b/lld/include/lld/Common/ErrorHandler.h @@ -152,7 +152,7 @@ void message(const Twine &msg, llvm::raw_ostream &s = outs()); void warn(const Twine &msg); uint64_t errorCount(); -enum class DiagLevel { Log, Warn, Err, Fatal }; +enum class DiagLevel { Log, Msg, Warn, Err, Fatal }; // A class that synchronizes thread writing to the same stream similar // std::osyncstream.