<div dir="ltr">Can you also make sure that the "too many errors emitted" message includes something like "use --error-limit=0 to see all errors"? Otherwise users may spend a lot of time to find this feature (or not find it).<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 23, 2016 at 10:15 AM, Rui Ueyama via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Wed Nov 23 12:15:37 2016<br>
New Revision: 287789<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=287789&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=287789&view=rev</a><br>
Log:<br>
Limit default maximum number of errors to 20.<br>
<br>
This is in the context of <a href="https://llvm.org/bugs/show_bug.cgi?id=31109" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=31109</a>.<br>
When LLD prints out errors for relocations, it tends to print out<br>
extremely large number of errors (like millions) because it would<br>
print out one error per relocation.<br>
<br>
This patch makes LLD bail out if it prints out more than 20 errors.<br>
You can configure the limitation using -error-limit argument.<br>
-error-limit=0 means no limit.<br>
<br>
I chose the flag name because Clang has the same feature as -ferror-limit.<br>
"f" doesn't make sense to us, so I omitted it.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D26981" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D26981</a><br>
<br>
Added:<br>
lld/trunk/test/ELF/error-<wbr>limit.test<br>
Modified:<br>
lld/trunk/ELF/Config.h<br>
lld/trunk/ELF/Driver.cpp<br>
lld/trunk/ELF/Error.cpp<br>
lld/trunk/ELF/Error.h<br>
lld/trunk/ELF/Options.td<br>
<br>
Modified: lld/trunk/ELF/Config.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=287789&r1=287788&r2=287789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Config.<wbr>h?rev=287789&r1=287788&r2=<wbr>287789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Config.h (original)<br>
+++ lld/trunk/ELF/Config.h Wed Nov 23 12:15:37 2016<br>
@@ -145,6 +145,7 @@ struct Configuration {<br>
uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;<br>
uint16_t EMachine = llvm::ELF::EM_NONE;<br>
uint64_t EntryAddr = 0;<br>
+ uint64_t ErrorLimit;<br>
uint64_t ImageBase;<br>
uint64_t MaxPageSize;<br>
uint64_t ZStackSize;<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=287789&r1=287788&r2=287789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Driver.<wbr>cpp?rev=287789&r1=287788&r2=<wbr>287789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Wed Nov 23 12:15:37 2016<br>
@@ -43,6 +43,7 @@ LinkerDriver *elf::Driver;<br>
bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,<br>
raw_ostream &Error) {<br>
HasError = false;<br>
+ ErrorCount = 0;<br>
ErrorOS = &Error;<br>
Argv0 = Args[0];<br>
<br>
@@ -490,6 +491,7 @@ void LinkerDriver::readConfigs(opt:<wbr>:Inpu<br>
Config->Discard = getDiscardOption(Args);<br>
Config->EhFrameHdr = Args.hasArg(OPT_eh_frame_hdr);<br>
Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_<wbr>dtags);<br>
+ Config->ErrorLimit = getInteger(Args, OPT_error_limit, 20);<br>
Config->ExportDynamic = Args.hasArg(OPT_export_<wbr>dynamic);<br>
Config->FatalWarnings = Args.hasArg(OPT_fatal_<wbr>warnings);<br>
Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false);<br>
<br>
Modified: lld/trunk/ELF/Error.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=287789&r1=287788&r2=287789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Error.<wbr>cpp?rev=287789&r1=287788&r2=<wbr>287789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Error.cpp (original)<br>
+++ lld/trunk/ELF/Error.cpp Wed Nov 23 12:15:37 2016<br>
@@ -24,6 +24,7 @@ using namespace llvm;<br>
namespace lld {<br>
<br>
bool elf::HasError;<br>
+uint64_t elf::ErrorCount;<br>
raw_ostream *elf::ErrorOS;<br>
StringRef elf::Argv0;<br>
<br>
@@ -40,8 +41,16 @@ void elf::warn(const Twine &Msg) {<br>
}<br>
<br>
void elf::error(const Twine &Msg) {<br>
- *ErrorOS << Argv0 << ": error: " << Msg << "\n";<br>
+ if (Config->ErrorLimit == 0 || ErrorCount < Config->ErrorLimit) {<br>
+ *ErrorOS << Argv0 << ": error: " << Msg << "\n";<br>
+ } else if (ErrorCount == Config->ErrorLimit) {<br>
+ *ErrorOS << Argv0 << ": error: too many errors emitted, stopping now\n";<br>
+ if (Config->ExitEarly)<br>
+ exitLld(1);<br>
+ }<br>
+<br>
HasError = true;<br>
+ ++ErrorCount;<br>
}<br>
<br>
void elf::error(std::error_code EC, const Twine &Prefix) {<br>
<br>
Modified: lld/trunk/ELF/Error.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=287789&r1=287788&r2=287789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Error.h?<wbr>rev=287789&r1=287788&r2=<wbr>287789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Error.h (original)<br>
+++ lld/trunk/ELF/Error.h Wed Nov 23 12:15:37 2016<br>
@@ -32,6 +32,7 @@ namespace lld {<br>
namespace elf {<br>
<br>
extern bool HasError;<br>
+extern uint64_t ErrorCount;<br>
extern llvm::raw_ostream *ErrorOS;<br>
extern llvm::StringRef Argv0;<br>
<br>
<br>
Modified: lld/trunk/ELF/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=287789&r1=287788&r2=287789&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Options.<wbr>td?rev=287789&r1=287788&r2=<wbr>287789&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Options.td (original)<br>
+++ lld/trunk/ELF/Options.td Wed Nov 23 12:15:37 2016<br>
@@ -68,6 +68,9 @@ def end_lib: F<"end-lib">,<br>
def entry: S<"entry">, MetaVarName<"<entry>">,<br>
HelpText<"Name of entry point symbol">;<br>
<br>
+def error_limit: S<"error-limit">,<br>
+ HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;<br>
+<br>
def export_dynamic: F<"export-dynamic">,<br>
HelpText<"Put symbols in the dynamic symbol table">;<br>
<br>
@@ -240,6 +243,7 @@ def alias_discard_locals_X: Flag<["-"],<br>
def alias_dynamic_list: J<"dynamic-list=">, Alias<dynamic_list>;<br>
def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;<br>
def alias_entry_entry: J<"entry=">, Alias<entry>;<br>
+def alias_error_limit: J<"error-limit=">, Alias<error_limit>;<br>
def alias_export_dynamic_E: Flag<["-"], "E">, Alias<export_dynamic>;<br>
def alias_export_dynamic_symbol: J<"export-dynamic-symbol=">,<br>
Alias<export_dynamic_symbol>;<br>
<br>
Added: lld/trunk/test/ELF/error-<wbr>limit.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/error-limit.test?rev=287789&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/test/ELF/<wbr>error-limit.test?rev=287789&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/test/ELF/error-<wbr>limit.test (added)<br>
+++ lld/trunk/test/ELF/error-<wbr>limit.test Wed Nov 23 12:15:37 2016<br>
@@ -0,0 +1,26 @@<br>
+RUN: not ld.lld 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 \<br>
+RUN: 21 22 2>&1 | FileCheck -check-prefix=DEFAULT %s<br>
+<br>
+DEFAULT: cannot open 01<br>
+DEFAULT: cannot open 20<br>
+DEFAULT-NEXT: too many errors emitted, stopping now<br>
+DEFAULT-NOT: cannot open 21<br>
+<br>
+RUN: not ld.lld -error-limit=5 01 02 03 04 05 06 07 08 09 10 2>&1 \<br>
+RUN: | FileCheck -check-prefix=LIMIT5 %s<br>
+RUN: not ld.lld -error-limit 5 01 02 03 04 05 06 07 08 09 10 2>&1 \<br>
+RUN: | FileCheck -check-prefix=LIMIT5 %s<br>
+<br>
+LIMIT5: cannot open 01<br>
+LIMIT5: cannot open 05<br>
+LIMIT5-NEXT: too many errors emitted, stopping now<br>
+LIMIT5-NOT: cannot open 06<br>
+<br>
+RUN: not ld.lld -error-limit=0 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \<br>
+RUN: 16 17 18 19 20 21 22 2>&1 | FileCheck -check-prefix=UNLIMITED %s<br>
+<br>
+UNLIMITED: cannot open 01<br>
+UNLIMITED: cannot open 20<br>
+UNLIMITED: cannot open 21<br>
+UNLIMITED: cannot open 22<br>
+UNLIMITED-NOT: too many errors emitted, stopping now<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>