[PATCH] D127564: [lld-macho] Add support for -w

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 11 00:17:17 PDT 2022


keith created this revision.
Herald added a reviewer: MaskRay.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added subscribers: llvm-commits, StephenFan.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127564

Files:
  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: lld/test/MachO/fatal-warnings.s
===================================================================
--- lld/test/MachO/fatal-warnings.s
+++ lld/test/MachO/fatal-warnings.s
@@ -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
 
Index: lld/include/lld/Common/ErrorHandler.h
===================================================================
--- lld/include/lld/Common/ErrorHandler.h
+++ lld/include/lld/Common/ErrorHandler.h
@@ -101,6 +101,7 @@
   StringRef logName = "lld";
   bool exitEarly = true;
   bool fatalWarnings = false;
+  bool suppressWarnings = false;
   bool verbose = false;
   bool vsDiagnostics = false;
   bool disableOutput = false;
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -890,7 +890,6 @@
     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: lld/MachO/DriverUtils.cpp
===================================================================
--- lld/MachO/DriverUtils.cpp
+++ lld/MachO/DriverUtils.cpp
@@ -87,6 +87,7 @@
   // 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: lld/Common/ErrorHandler.cpp
===================================================================
--- lld/Common/ErrorHandler.cpp
+++ lld/Common/ErrorHandler.cpp
@@ -242,6 +242,10 @@
     return;
   }
 
+  if (suppressWarnings) {
+    return;
+  }
+
   std::lock_guard<std::mutex> lock(mu);
   reportDiagnostic(getLocation(msg), Colors::MAGENTA, "warning", msg);
   sep = getSeparator(msg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127564.436120.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220611/0fbfed76/attachment.bin>


More information about the llvm-commits mailing list