[lld/mac] Abort link immediately on invalid -undefined argument
authorNico Weber <thakis@chromium.org>
Wed, 7 Dec 2022 18:48:08 +0000 (13:48 -0500)
committerNico Weber <thakis@chromium.org>
Thu, 8 Dec 2022 13:30:59 +0000 (08:30 -0500)
I tried `-undefined suppress` without `-flat_namespace`.
lld printed `'-undefined suppress' only valid with '-flat_namespace'`
followed by many many screenfuls of error messages about undefined
symbols, making the original diag hard to see.

This is probably the common case when using `-undefined`, so let's
just abort the link immediately when there's an invalid `-undefined`
arg.

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

lld/MachO/Driver.cpp
lld/test/MachO/treat-undef-sym.s

index a42c1af..74a1311 100644 (file)
@@ -765,9 +765,9 @@ getUndefinedSymbolTreatment(const ArgList &args) {
              (treatment == UndefinedSymbolTreatment::warning ||
               treatment == UndefinedSymbolTreatment::suppress)) {
     if (treatment == UndefinedSymbolTreatment::warning)
-      error("'-undefined warning' only valid with '-flat_namespace'");
+      fatal("'-undefined warning' only valid with '-flat_namespace'");
     else
-      error("'-undefined suppress' only valid with '-flat_namespace'");
+      fatal("'-undefined suppress' only valid with '-flat_namespace'");
     treatment = UndefinedSymbolTreatment::error;
   }
   return treatment;
index 8f5e82d..b757e04 100644 (file)
 # ERROR-NEXT: >>> referenced by
 
 # INVAL-WARNING: error: '-undefined warning' only valid with '-flat_namespace'
-# INVAL-WARNING-NEXT: error: undefined symbol: _bar
+# INVAL-WARNING-NOT: error: undefined symbol: _bar
 
 # INVAL-SUPPRESS: error: '-undefined suppress' only valid with '-flat_namespace'
-# INVAL-SUPPRESS-NEXT: error: undefined symbol: _bar
+# INVAL-SUPPRESS-NOT: error: undefined symbol: _bar
 
 # WARNING: warning: undefined symbol: _bar
 # WARNING-NEXT: >>> referenced by