[lld] 7d57c69 - [lld-macho] Add support for -w

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


Author: Keith Smiley
Date: 2022-06-11T17:38:50-07:00
New Revision: 7d57c69826a6bf4f29875994743ef4c717ee9deb

URL: https://github.com/llvm/llvm-project/commit/7d57c69826a6bf4f29875994743ef4c717ee9deb
DIFF: https://github.com/llvm/llvm-project/commit/7d57c69826a6bf4f29875994743ef4c717ee9deb.diff

LOG: [lld-macho] Add support for -w

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index 4cacd82c9f354..0a8fc8f054fc9 100644
--- a/lld/Common/ErrorHandler.cpp
+++ b/lld/Common/ErrorHandler.cpp
@@ -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);

diff  --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index 95a1183b71d94..b52d5e851c62d 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -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");

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 21d9dc00b5bb9..291e55c9402aa 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -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>">,

diff  --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 0ba4787e5888e..69e798c66ca6a 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -101,6 +101,7 @@ class ErrorHandler {
   StringRef logName = "lld";
   bool exitEarly = true;
   bool fatalWarnings = false;
+  bool suppressWarnings = false;
   bool verbose = false;
   bool vsDiagnostics = false;
   bool disableOutput = false;

diff  --git a/lld/test/MachO/fatal-warnings.s b/lld/test/MachO/fatal-warnings.s
index 1dc40396e5a8e..0fedb9431438d 100644
--- a/lld/test/MachO/fatal-warnings.s
+++ b/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
 


        


More information about the llvm-commits mailing list