[lld] dc6229b - [lld] Use context-aware outs() and errs()

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 18:25:56 PST 2024


Author: Fangrui Song
Date: 2024-11-16T18:25:51-08:00
New Revision: dc6229bd662cf74a3f4fad75f1e7832123d00db7

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

LOG: [lld] Use context-aware outs() and errs()

Added: 
    

Modified: 
    lld/Common/ErrorHandler.cpp
    lld/ELF/DriverUtils.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index daca2e36ac4a5e..e80b69c9c30669 100644
--- a/lld/Common/ErrorHandler.cpp
+++ b/lld/Common/ErrorHandler.cpp
@@ -215,7 +215,7 @@ void ErrorHandler::reportDiagnostic(StringRef location, Colors c,
   raw_svector_ostream os(buf);
   os << sep << location << ": ";
   if (!diagKind.empty()) {
-    if (lld::errs().colors_enabled()) {
+    if (errs().colors_enabled()) {
       os.enable_colors(true);
       os << c << diagKind << ": " << Colors::RESET;
     } else {
@@ -223,7 +223,7 @@ void ErrorHandler::reportDiagnostic(StringRef location, Colors c,
     }
   }
   os << msg << '\n';
-  lld::errs() << buf;
+  errs() << buf;
 }
 
 void ErrorHandler::log(const Twine &msg) {

diff  --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index 8fbf7bf69c0896..bb6146fa36f6d8 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -58,9 +58,9 @@ static void handleColorDiagnostics(Ctx &ctx, opt::InputArgList &args) {
     return;
   StringRef s = arg->getValue();
   if (s == "always")
-    lld::errs().enable_colors(true);
+    ctx.errHandler->errs().enable_colors(true);
   else if (s == "never")
-    lld::errs().enable_colors(false);
+    ctx.errHandler->errs().enable_colors(false);
   else if (s != "auto")
     ErrAlways(ctx) << "unknown option: --color-diagnostics=" << s;
 }
@@ -139,16 +139,17 @@ opt::InputArgList ELFOptTable::parse(Ctx &ctx, ArrayRef<const char *> argv) {
 }
 
 void elf::printHelp(Ctx &ctx) {
+  auto &outs = ctx.errHandler->outs();
   ELFOptTable().printHelp(
-      lld::outs(), (ctx.arg.progName + " [options] file...").str().c_str(),
-      "lld", false /*ShowHidden*/, true /*ShowAllAliases*/);
-  lld::outs() << "\n";
+      outs, (ctx.arg.progName + " [options] file...").str().c_str(), "lld",
+      false /*ShowHidden*/, true /*ShowAllAliases*/);
+  outs << "\n";
 
   // Scripts generated by Libtool versions up to 2021-10 expect /: supported
   // targets:.* elf/ in a message for the --help option. If it doesn't match,
   // the scripts assume that the linker doesn't support very basic features
   // such as shared libraries. Therefore, we need to print out at least "elf".
-  lld::outs() << ctx.arg.progName << ": supported targets: elf\n";
+  outs << ctx.arg.progName << ": supported targets: elf\n";
 }
 
 static std::string rewritePath(StringRef s) {

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index fc6d88893597ea..32bb05f83d15b1 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -342,7 +342,7 @@ template <class ELFT> void Writer<ELFT>::run() {
 
   // Handle --print-memory-usage option.
   if (ctx.arg.printMemoryUsage)
-    ctx.script->printMemoryUsage(lld::outs());
+    ctx.script->printMemoryUsage(ctx.errHandler->outs());
 
   if (ctx.arg.checkSections)
     checkSections();


        


More information about the llvm-commits mailing list