[lld] 1bfe55a - [lld-link] Replace errorHandler() with ctx.e

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


Author: Fangrui Song
Date: 2024-11-16T18:31:58-08:00
New Revision: 1bfe55aff5f01e81f268f4ba8dbf25c7fcebdc7c

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

LOG: [lld-link] Replace errorHandler() with ctx.e

errorHandler() uses the global state, which should be avoided in
lld/COFF code.

Added: 
    

Modified: 
    lld/COFF/Driver.cpp
    lld/COFF/DriverUtils.cpp
    lld/COFF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index d6d6cc8f394f0c..a0bff69c6302a2 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1582,7 +1582,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
     StringRef s = arg->getValue();
     if (s.getAsInteger(10, n))
       error(arg->getSpelling() + " number expected, but got " + s);
-    errorHandler().errorLimit = n;
+    ctx.e.errorLimit = n;
   }
 
   config->vfs = getVFS(args);
@@ -1696,7 +1696,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   // Handle /verbose
   if (args.hasArg(OPT_verbose))
     config->verbose = true;
-  errorHandler().verbose = config->verbose;
+  ctx.e.verbose = config->verbose;
 
   // Handle /force or /force:unresolved
   if (args.hasArg(OPT_force, OPT_force_unresolved))

diff  --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 39af621cec85ca..071f0d86d74d9b 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -934,7 +934,7 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
   }
 
   // Handle /WX early since it converts missing argument warnings to errors.
-  errorHandler().fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);
+  ctx.e.fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);
 
   if (missingCount)
     fatal(Twine(args.getArgString(missingIndex)) + ": missing argument");

diff  --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 58d0700c52aaf4..d84bc78adb3014 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -205,7 +205,7 @@ struct ChunkRange {
 class Writer {
 public:
   Writer(COFFLinkerContext &c)
-      : buffer(errorHandler().outputBuffer), delayIdata(c), edata(c), ctx(c) {}
+      : buffer(c.e.outputBuffer), delayIdata(c), edata(c), ctx(c) {}
   void run();
 
 private:


        


More information about the llvm-commits mailing list