[lld] ddc0eb7 - [lld,MinGW] Use context-aware outs() and errs()

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 20:43:46 PST 2024


Author: Fangrui Song
Date: 2024-11-16T20:43:42-08:00
New Revision: ddc0eb70c8b60de9fa5e55f550ff3ac822c849f1

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

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

lld::outs() and lld::errs() use the global errorHandler() and should be
avoided.

Added: 
    

Modified: 
    lld/MinGW/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 553698d4f537fc..86752ef1f51d23 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -97,11 +97,12 @@ class MinGWOptTable : public opt::GenericOptTable {
 };
 } // namespace
 
-static void printHelp(const char *argv0) {
+static void printHelp(CommonLinkerContext &ctx, const char *argv0) {
+  auto &outs = ctx.e.outs();
   MinGWOptTable().printHelp(
-      lld::outs(), (std::string(argv0) + " [options] file...").c_str(), "lld",
-      false /*ShowHidden*/, true /*ShowAllAliases*/);
-  lld::outs() << "\n";
+      outs, (std::string(argv0) + " [options] file...").c_str(), "lld",
+      /*ShowHidden=*/false, /*ShowAllAliases=*/true);
+  outs << '\n';
 }
 
 static cl::TokenizerCallback getQuotingStyle() {
@@ -189,7 +190,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
     return false;
 
   if (args.hasArg(OPT_help)) {
-    printHelp(argsArr[0]);
+    printHelp(*ctx, argsArr[0]);
     return true;
   }
 
@@ -563,7 +564,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
     return false;
 
   if (args.hasArg(OPT_verbose) || args.hasArg(OPT__HASH_HASH_HASH))
-    lld::errs() << llvm::join(linkArgs, " ") << "\n";
+    ctx->e.errs() << llvm::join(linkArgs, " ") << "\n";
 
   if (args.hasArg(OPT__HASH_HASH_HASH))
     return true;


        


More information about the llvm-commits mailing list