[lld] 26fcee6 - [ELF] Add --no-warnings/-w
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 24 10:54:15 PDT 2022
Author: Fangrui Song
Date: 2022-10-24T10:54:09-07:00
New Revision: 26fcee601fb340bf19b9f23ab6e7ac1772aa14dc
URL: https://github.com/llvm/llvm-project/commit/26fcee601fb340bf19b9f23ab6e7ac1772aa14dc
DIFF: https://github.com/llvm/llvm-project/commit/26fcee601fb340bf19b9f23ab6e7ac1772aa14dc.diff
LOG: [ELF] Add --no-warnings/-w
Mach-O ld64 supports -w to suppress warnings. GNU ld 2.40 will support the
option as well (https://sourceware.org/bugzilla/show_bug.cgi?id=29654).
This feature has some small value. E.g. when analyzing a large executable with
relocation overflow issues, we may use --noinhibit-exec --emit-relocs to get an
output file with static relocations despite relocation overflow issues. -w can
significantly improve the link time as printing the massive warnings is slow.
Reviewed By: peter.smith
Differential Revision: https://reviews.llvm.org/D136569
Added:
lld/test/ELF/warnings.s
Modified:
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/docs/ReleaseNotes.rst
lld/docs/ld.lld.1
lld/test/ELF/no-inhibit-exec.s
Removed:
lld/test/ELF/fatal-warnings.s
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 48990d00f44b8..271776ddd32b8 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -542,7 +542,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// Interpret these flags early because error()/warn() depend on them.
errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
errorHandler().fatalWarnings =
- args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
+ args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false) &&
+ !args.hasArg(OPT_no_warnings);
+ errorHandler().suppressWarnings = args.hasArg(OPT_no_warnings);
checkZOptions(args);
// Handle -help
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 1d8cc77ed0094..2e9e057a09615 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -297,6 +297,9 @@ def no_omagic: F<"no-omagic">, MetaVarName<"<magic>">,
def no_undefined: F<"no-undefined">,
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
+def no_warnings: FF<"no-warnings">, HelpText<"Suppress warnings and cancel --fatal-warnings">;
+def : Flag<["-"], "w">, Alias<no_warnings>, HelpText<"Alias for --no-warnings">;
+
def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
HelpText<"Path to file to write output">;
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index 2aad9b8644f3e..141f34103da15 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -31,6 +31,8 @@ ELF Improvements
* ``--compress-debug-sections=zstd`` is now available to compress debug
sections with zstd (``ELFCOMPRESS_ZSTD``).
(`D133548 <https://reviews.llvm.org/D133548>`_)
+* ``--no-warnings``/``-w`` is now available to suppress warnings.
+ (`D136569 <https://reviews.llvm.org/D136569>`_)
Breaking changes
----------------
diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1
index 9ddd2897a23af..2b530af39ad64 100644
--- a/lld/docs/ld.lld.1
+++ b/lld/docs/ld.lld.1
@@ -358,6 +358,9 @@ Report version scripts that refer undefined symbols.
Report unresolved symbols even if the linker is creating a shared library.
.It Fl -no-warn-symbol-ordering
Do not warn about problems with the symbol ordering file or call graph profile.
+.It Fl -no-warnings , Fl w
+Suppress warnings and cancel
+.Cm --fatal-warnings.
.It Fl -no-whole-archive
Restores the default behavior of loading archive members.
.It Fl -no-pie , Fl -no-pic-executable
diff --git a/lld/test/ELF/no-inhibit-exec.s b/lld/test/ELF/no-inhibit-exec.s
index 66031eaea912c..abf93f1c6545a 100644
--- a/lld/test/ELF/no-inhibit-exec.s
+++ b/lld/test/ELF/no-inhibit-exec.s
@@ -5,6 +5,8 @@
# RUN: llvm-objdump -d %t2 | FileCheck %s
# RUN: llvm-readobj -r %t2 | FileCheck %s --check-prefix=RELOC
+# RUN: ld.lld %t -w --noinhibit-exec -o /dev/null 2>&1 | count 0
+
# CHECK: Disassembly of section .text:
# CHECK-EMPTY:
# CHECK-NEXT: _start
diff --git a/lld/test/ELF/fatal-warnings.s b/lld/test/ELF/warnings.s
similarity index 66%
rename from lld/test/ELF/fatal-warnings.s
rename to lld/test/ELF/warnings.s
index 51f2864a05987..c66685de5a0cd 100644
--- a/lld/test/ELF/fatal-warnings.s
+++ b/lld/test/ELF/warnings.s
@@ -9,6 +9,10 @@
# RUN: not ld.lld --warn-common --fatal-warnings %t1.o %t2.o -o /dev/null 2>&1 | \
# RUN: FileCheck -check-prefix=ERR %s
+## --no-warnings/-w suppresses warnings and cancel --fatal-warnings.
+# RUN: ld.lld --no-warnings --warn-common %t1.o %t2.o -o /dev/null 2>&1 | count 0
+# RUN: ld.lld -w --fatal-warnings --warn-common %t1.o %t2.o -o /dev/null 2>&1 | count 0
+
.globl _start
_start:
More information about the llvm-commits
mailing list