[lld-macho] Add support for -w
authorKeith Smiley <keithbsmiley@gmail.com>
Sat, 11 Jun 2022 07:10:48 +0000 (00:10 -0700)
committerKeith Smiley <keithbsmiley@gmail.com>
Sun, 12 Jun 2022 00:38:50 +0000 (17:38 -0700)
This flag suppresses warnings produced by the linker. In ld64 this has
an interesting interaction with -fatal_warnings, it silences the
warnings but the link still fails. Instead of doing that here we still
print the warning and eagerly fail the link in case both are passed,
this seems more reasonable so users can understand why the link fails.

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

lld/Common/ErrorHandler.cpp
lld/MachO/DriverUtils.cpp
lld/MachO/Options.td
lld/include/lld/Common/ErrorHandler.h
lld/test/MachO/fatal-warnings.s

index 4cacd82..0a8fc8f 100644 (file)
@@ -242,6 +242,9 @@ void ErrorHandler::warn(const Twine &msg) {
     return;
   }
 
+  if (suppressWarnings)
+    return;
+
   std::lock_guard<std::mutex> lock(mu);
   reportDiagnostic(getLocation(msg), Colors::MAGENTA, "warning", msg);
   sep = getSeparator(msg);
index 95a1183..b52d5e8 100644 (file)
@@ -87,6 +87,7 @@ InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
   // Handle -fatal_warnings early since it converts missing argument warnings
   // to errors.
   errorHandler().fatalWarnings = args.hasArg(OPT_fatal_warnings);
+  errorHandler().suppressWarnings = args.hasArg(OPT_w);
 
   if (missingCount)
     error(Twine(args.getArgString(missingIndex)) + ": missing argument");
index 21d9dc0..291e55c 100644 (file)
@@ -887,7 +887,6 @@ def e : Separate<["-"], "e">,
     Group<grp_rare>;
 def w : Flag<["-"], "w">,
     HelpText<"Suppress all warnings">,
-    Flags<[HelpHidden]>,
     Group<grp_rare>;
 def final_output : Separate<["-"], "final_output">,
     MetaVarName<"<name>">,
index 0ba4787..69e798c 100644 (file)
@@ -101,6 +101,7 @@ public:
   StringRef logName = "lld";
   bool exitEarly = true;
   bool fatalWarnings = false;
+  bool suppressWarnings = false;
   bool verbose = false;
   bool vsDiagnostics = false;
   bool disableOutput = false;
index 1dc4039..0fedb94 100644 (file)
@@ -6,6 +6,12 @@
 # RUN: not %no-fatal-warnings-lld %t1.o -fatal_warnings -o /dev/null \
 # RUN:     -single_module 2>&1 | FileCheck -check-prefix=ERROR %s
 
+# RUN: %no-fatal-warnings-lld %t1.o -w -o /dev/null -single_module 2>&1 \
+# RUN:     | count 0
+# RUN: not %no-fatal-warnings-lld %t1.o -fatal_warnings -w -o /dev/null \
+# RUN:     -single_module 2>&1 \
+# RUN:     | FileCheck --check-prefix=ERROR %s
+
 # ERROR: error: Option `-single_module' is deprecated
 # WARNING: warning: Option `-single_module' is deprecated