[PATCH] D139559: [lld/mac] Abort link immediately on invalid -undefined argument

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 10:50:07 PST 2022


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
thakis requested review of this revision.

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.


https://reviews.llvm.org/D139559

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


Index: lld/test/MachO/treat-undef-sym.s
===================================================================
--- lld/test/MachO/treat-undef-sym.s
+++ lld/test/MachO/treat-undef-sym.s
@@ -43,17 +43,16 @@
 # 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
 
 # UNKNOWN: unknown -undefined TREATMENT 'bogus'
-# UNKNOWN-NEXT: error: undefined symbol: _bar
-# UNKNOWN-NEXT: >>> referenced by
+# UNKNOWN-NOT: error: undefined symbol: _bar
 
 # BIND: Lazy bind table:
 # BIND: __DATA   __la_symbol_ptr    0x{{[0-9a-f]*}} flat-namespace   _bar
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1608,6 +1608,8 @@
                                 : NamespaceKind::flat;
 
   config->undefinedSymbolTreatment = getUndefinedSymbolTreatment(args);
+  if (errorCount())
+    return false;
 
   if (config->outputType == MH_EXECUTE)
     config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139559.480978.patch
Type: text/x-patch
Size: 1438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221207/50183b51/attachment.bin>


More information about the llvm-commits mailing list