[lld] 3b75a5c - [ELF] Replace message(...) with Msg(ctx)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 15:34:48 PST 2024


Author: Fangrui Song
Date: 2024-11-16T15:34:42-08:00
New Revision: 3b75a5c4c84d17d6647ba079391722ed9be09f85

URL: https://github.com/llvm/llvm-project/commit/3b75a5c4c84d17d6647ba079391722ed9be09f85
DIFF: https://github.com/llvm/llvm-project/commit/3b75a5c4c84d17d6647ba079391722ed9be09f85.diff

LOG: [ELF] Replace message(...) with Msg(ctx)

Added: 
    

Modified: 
    lld/Common/ErrorHandler.cpp
    lld/ELF/Config.h
    lld/ELF/Driver.cpp
    lld/ELF/ICF.cpp
    lld/ELF/InputFiles.cpp
    lld/ELF/MarkLive.cpp
    lld/ELF/Symbols.cpp
    lld/include/lld/Common/ErrorHandler.h

Removed: 
    


################################################################################
diff  --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index 21755481665961..9526db7fefc9aa 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 c847a32bb5f13f..3198b77353fc1d 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 8f23514bcdcdb9..41816025f38b16 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<const char *> 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 0bf55177113044..7090ca779b0e7b 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 fb19fce257a144..63dfffd1d9b849 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -316,7 +316,7 @@ template <class ELFT> 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<ELFFileBase>(file));

diff  --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 066c52540123e5..df81d443accd55 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -391,7 +391,7 @@ template <class ELFT> 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<ELF32LE>(Ctx &);

diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 670a748363c5be..baa704363efb1f 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 996eeae423c933..6be862e5115da9 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.


        


More information about the llvm-commits mailing list