Skip to content

Commit

Permalink
[lld-macho] Add support for -w
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keith committed Jun 12, 2022
1 parent c115e76 commit 7d57c69
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lld/Common/ErrorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lld/MachO/DriverUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion lld/MachO/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>">,
Expand Down
1 change: 1 addition & 0 deletions lld/include/lld/Common/ErrorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions lld/test/MachO/fatal-warnings.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7d57c69

Please sign in to comment.