summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Smiley <keithbsmiley@gmail.com>2022-06-11 00:10:48 -0700
committerKeith Smiley <keithbsmiley@gmail.com>2022-06-11 17:38:50 -0700
commit7d57c69826a6bf4f29875994743ef4c717ee9deb (patch)
tree04d11c948d3c6c7de1e1664c7fc72e80536aa95a
parentc115e760c25a45e0d045ebb51d758a5386a9ce94 (diff)
downloadllvm-7d57c69826a6bf4f29875994743ef4c717ee9deb.tar.gz
[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
-rw-r--r--lld/Common/ErrorHandler.cpp3
-rw-r--r--lld/MachO/DriverUtils.cpp1
-rw-r--r--lld/MachO/Options.td1
-rw-r--r--lld/include/lld/Common/ErrorHandler.h1
-rw-r--r--lld/test/MachO/fatal-warnings.s6
5 files changed, 11 insertions, 1 deletions
diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index 4cacd82c9f35..0a8fc8f054fc 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 95a1183b71d9..b52d5e851c62 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 21d9dc00b5bb..291e55c9402a 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 0ba4787e5888..69e798c66ca6 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -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;
diff --git a/lld/test/MachO/fatal-warnings.s b/lld/test/MachO/fatal-warnings.s
index 1dc40396e5a8..0fedb9431438 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