From: Nick Clifton Date: Fri, 21 Oct 2022 11:20:09 +0000 (+0100) Subject: Add a -w option to the linker to suppress warning and error messages. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4b2e7a577c2f7311a8c381ff791d46e654c41fcc;p=binutils-gdb.git Add a -w option to the linker to suppress warning and error messages. PR 29654 * ld.h (struct ld_config_type): Add no_warnings field. * ldlex.h (enum option_values): Add OPTION_NO_WARNINGS. * lexsup.c (ld_options): Add --no-warnings. (parse_args): Add support for -w and --no-warnings. * ldmisc.c (vfinfo): Return early if the message is a warning and -w has been enabled. * ld.texi (options): Document new command line option. * NEWS: Mention the new feature. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index 15cf800a231..9ba8cbcfd0b 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,15 @@ +2022-10-21 Nick Clifton + + PR 29654 + * ld.h (struct ld_config_type): Add no_warnings field. + * ldlex.h (enum option_values): Add OPTION_NO_WARNINGS. + * lexsup.c (ld_options): Add --no-warnings. + (parse_args): Add support for -w and --no-warnings. + * ldmisc.c (vfinfo): Return early if the message is a warning and + -w has been enabled. + * ld.texi (options): Document new command line option. + * NEWS: Mention the new feature. + 2022-08-30 Nick Clifton PR 29529 diff --git a/ld/NEWS b/ld/NEWS index d7ceb0c68b6..24df91aa85f 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,7 +1,12 @@ -*- text -*- +* The linker has a new command line option to suppress the generation of any + warning or error messages. This can be useful when there is a need to create + a known non-working binary. The option is -w or --no-warnings. + * ld now supports zstd compressed debug sections. The new option --compress-debug-sections=zstd compresses debug sections with zstd. + * Add --enable-default-compressed-debug-sections-algorithm={zlib,zstd} that selects the default compression algorithm for --enable-compressed-debug-sections. diff --git a/ld/ld.h b/ld/ld.h index f3086bf30de..2ac9f469d04 100644 --- a/ld/ld.h +++ b/ld/ld.h @@ -252,9 +252,12 @@ typedef struct changes due to the alignment of an input section. */ bool warn_section_align; - /* If TRUE, warning messages are fatal */ + /* If TRUE, warning messages are fatal. */ bool fatal_warnings; + /* If TRUE, warning and error messages are ignored. */ + bool no_warnings; + sort_order sort_common; bool text_read_only; diff --git a/ld/ld.texi b/ld/ld.texi index 9daed2e7e9f..82527e3652c 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -1876,6 +1876,15 @@ in filename invoked by -R or --just-symbols Treat all warnings as errors. The default behaviour can be restored with the option @option{--no-fatal-warnings}. +@kindex -w +@kindex --no-warnings +@item -w +@itemx --no-warnings +Do not display any warning or error messages. This overrides +@option{--fatal-warnings} if it has been enabled. This option can be +used when it is known that the output binary will not work, but there +is still a need to create it. + @kindex --force-exe-suffix @item --force-exe-suffix Make sure that an output file has a .exe suffix. diff --git a/ld/ldlex.h b/ld/ldlex.h index 894582595c1..31b77606a55 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -88,6 +88,7 @@ enum option_values OPTION_WARN_CONSTRUCTORS, OPTION_WARN_FATAL, OPTION_NO_WARN_FATAL, + OPTION_NO_WARNINGS, OPTION_WARN_MULTIPLE_GP, OPTION_WARN_ONCE, OPTION_WARN_SECTION_ALIGN, diff --git a/ld/ldmisc.c b/ld/ldmisc.c index 3a02f752c38..033e9c29c57 100644 --- a/ld/ldmisc.c +++ b/ld/ldmisc.c @@ -95,6 +95,9 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning) } type; } args[9]; + if (is_warning && config.no_warnings) + return; + for (arg_no = 0; arg_no < sizeof (args) / sizeof (args[0]); arg_no++) args[arg_no].type = Bad; diff --git a/ld/lexsup.c b/ld/lexsup.c index 0068ff59798..d107bd7a348 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -381,6 +381,9 @@ static const struct ld_option ld_options[] = { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED}, '\0', NULL, N_("Do not allow unresolved references in object files"), TWO_DASHES }, + { {"no-warnings", no_argument, NULL, OPTION_NO_WARNINGS}, + 'w', NULL, N_("Do not display any warning or error messages"), + TWO_DASHES }, { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED}, '\0', NULL, N_("Allow unresolved references in shared libraries"), TWO_DASHES }, @@ -1554,6 +1557,11 @@ parse_args (unsigned argc, char **argv) case OPTION_NO_WARN_FATAL: config.fatal_warnings = false; break; + case OPTION_NO_WARNINGS: + case 'w': + config.no_warnings = true; + config.fatal_warnings = false; + break; case OPTION_WARN_MULTIPLE_GP: config.warn_multiple_gp = true; break;