[lld] 24c7d97 - [ELF] Replace context-less errorHandler() and error() with ctx.errHandler

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 14:14:59 PST 2024


Author: Fangrui Song
Date: 2024-11-16T14:14:54-08:00
New Revision: 24c7d97cff189071a3c2195258bc52c7d0e609a5

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

LOG: [ELF] Replace context-less errorHandler() and error() with ctx.errHandler

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/Relocations.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8addff3d32edbb..81126a91024dd8 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -388,7 +388,8 @@ void LinkerDriver::addLibrary(StringRef name) {
   if (std::optional<std::string> path = searchLibrary(ctx, name))
     addFile(saver().save(*path), /*withLOption=*/true);
   else
-    error("unable to find library -l" + name, ErrorTag::LibNotFound, {name});
+    ctx.errHandler->error("unable to find library -l" + name,
+                          ErrorTag::LibNotFound, {name});
 }
 
 // This function is called on startup. We need this for LTO since
@@ -642,11 +643,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   opt::InputArgList args = parser.parse(ctx, argsArr.slice(1));
 
   // Interpret these flags early because Err/Warn depend on them.
-  errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
-  errorHandler().fatalWarnings =
+  ctx.errHandler->errorLimit = args::getInteger(args, OPT_error_limit, 20);
+  ctx.errHandler->fatalWarnings =
       args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false) &&
       !args.hasArg(OPT_no_warnings);
-  errorHandler().suppressWarnings = args.hasArg(OPT_no_warnings);
+  ctx.errHandler->suppressWarnings = args.hasArg(OPT_no_warnings);
 
   // Handle -help
   if (args.hasArg(OPT_help)) {
@@ -1278,8 +1279,8 @@ static bool remapInputs(Ctx &ctx, StringRef line, const Twine &location) {
 
 // Initializes Config members by the command line options.
 static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
-  errorHandler().verbose = args.hasArg(OPT_verbose);
-  errorHandler().vsDiagnostics =
+  ctx.errHandler->verbose = args.hasArg(OPT_verbose);
+  ctx.errHandler->vsDiagnostics =
       args.hasArg(OPT_visual_studio_diagnostics_format, false);
 
   ctx.arg.allowMultipleDefinition =
@@ -1337,7 +1338,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
       args.hasArg(OPT_enable_non_contiguous_regions);
   ctx.arg.entry = args.getLastArgValue(OPT_entry);
 
-  errorHandler().errorHandlingScript =
+  ctx.errHandler->errorHandlingScript =
       args.getLastArgValue(OPT_error_handling_script);
 
   ctx.arg.executeOnly =

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 56b654ae510191..6da61f14f0f131 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -798,7 +798,7 @@ static void reportUndefinedSymbol(Ctx &ctx, const UndefinedDiag &undef,
   if (undef.isWarning)
     Warn(ctx) << msg;
   else
-    error(msg, ErrorTag::SymbolNotFound, {sym.getName()});
+    ctx.errHandler->error(msg, ErrorTag::SymbolNotFound, {sym.getName()});
 }
 
 void elf::reportUndefinedSymbols(Ctx &ctx) {

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 5ddaa7319224b0..2a9d57ec8deec6 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -49,7 +49,7 @@ template <class ELFT> class Writer {
 public:
   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
 
-  Writer(Ctx &ctx) : ctx(ctx), buffer(errorHandler().outputBuffer) {}
+  Writer(Ctx &ctx) : ctx(ctx), buffer(ctx.errHandler->outputBuffer) {}
 
   void run();
 


        


More information about the llvm-commits mailing list