[lld] de4364f - [LLD][MinGW] Add --error-limit=<N> option

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 03:53:52 PST 2022


Author: Alvin Wong
Date: 2022-11-10T13:52:47+02:00
New Revision: de4364f1ecaa6a5d631cff036b8f31e02841e73d

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

LOG: [LLD][MinGW] Add --error-limit=<N> option

This maps to -errorlimit:<N> in the COFF linker and is functionally
identical to the same option in the ELF and MachO linker.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D137489

Added: 
    lld/test/MinGW/error-limit.test

Modified: 
    lld/COFF/Driver.cpp
    lld/MinGW/Driver.cpp
    lld/MinGW/Options.td
    lld/test/COFF/error-limit.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6dbda1045152c..b34d952ad2975 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1475,6 +1475,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   // Handle /lldmingw early, since it can potentially affect how other
   // options are handled.
   config->mingw = args.hasArg(OPT_lldmingw);
+  if (config->mingw)
+    ctx.e.errorLimitExceededMsg = "too many errors emitted, stopping now"
+                                  " (use --error-limit=0 to see all errors)";
 
   // Handle /linkrepro and /reproduce.
   if (Optional<std::string> path = getReproduceFile(args)) {

diff  --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 865a90837eba9..9d41806dac416 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -390,6 +390,15 @@ bool mingw::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
          " only takes effect when used with --guard-cf");
   }
 
+  if (auto *a = args.getLastArg(OPT_error_limit)) {
+    int n;
+    StringRef s = a->getValue();
+    if (s.getAsInteger(10, n))
+      error(a->getSpelling() + ": number expected, but got " + s);
+    else
+      add("-errorlimit:" + s);
+  }
+
   for (auto *a : args.filtered(OPT_mllvm))
     add("-mllvm:" + StringRef(a->getValue()));
 

diff  --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index 923b9cce3d18e..c9c60638a4e59 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -146,6 +146,8 @@ defm guard_cf : B<"guard-cf", "Enable Control Flow Guard" ,
 defm guard_longjmp : B<"guard-longjmp",
   "Enable Control Flow Guard long jump hardening (default for --guard-cf)" ,
   "Do not enable Control Flow Guard long jump hardening">;
+defm error_limit:
+  EqLong<"error-limit", "Maximum number of errors to emit before stopping (0 = no limit)">;
 
 // Alias
 def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;

diff  --git a/lld/test/COFF/error-limit.test b/lld/test/COFF/error-limit.test
index eddd2ab9a64dc..ef19ccf2a4ed3 100644
--- a/lld/test/COFF/error-limit.test
+++ b/lld/test/COFF/error-limit.test
@@ -27,3 +27,11 @@ RUN: not lld-link /errorlimit:XYZ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 \
 RUN:   15 16 17 18 19 20 21 22 2>&1 | FileCheck -check-prefix=WRONG %s
 
 WRONG:      /errorlimit: number expected, but got XYZ
+
+RUN: not lld-link -lldmingw 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 \
+RUN:   21 22 2>&1 | FileCheck -check-prefix=MINGW-DEFAULT %s
+
+MINGW-DEFAULT:      could not open '01'
+MINGW-DEFAULT:      could not open '20'
+MINGW-DEFAULT-NEXT: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
+MINGW-DEFAULT-NOT:  could not open '21'

diff  --git a/lld/test/MinGW/error-limit.test b/lld/test/MinGW/error-limit.test
new file mode 100644
index 0000000000000..68e9ea9b31ce6
--- /dev/null
+++ b/lld/test/MinGW/error-limit.test
@@ -0,0 +1,12 @@
+RUN: ld.lld -### foo.o -m i386pep 2>&1 | FileCheck -check-prefix=DEFAULT %s
+DEFAULT-NOT: -errorlimit:
+DEFAULT-NOT: /errorlimit:
+
+RUN: ld.lld -### foo.o -m i386pep --error-limit=5 2>&1 | FileCheck -check-prefix=NUMERIC %s
+NUMERIC: -errorlimit:5
+
+RUN: ld.lld -### foo.o -m i386pep --error-limit=0 2>&1 | FileCheck -check-prefix=UNLIMITED %s
+UNLIMITED: -errorlimit:0
+
+RUN: not ld.lld -### foo.o -m i386pep --error-limit=XYZ 2>&1 | FileCheck -check-prefix=WRONG %s
+WRONG:      --error-limit: number expected, but got XYZ


        


More information about the llvm-commits mailing list