[v2,2/3] gas: add new command line options to control diagnostic information messages

Message ID 20240704155145.1599822-3-matthieu.longo@arm.com
State New
Series gas: add command line option to inhibit info messages |


Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Matthieu Longo July 4, 2024, 3:51 p.m. UTC
  gas currently emits information messages for context information along warnings.
In the context of system register tests in AArch64 backend, these messages
pollute the tests when checking for error message patterns in stderr output.

This patch aims at providing two new flags while preserving the existing
behavior if none of the options is provided.
  * --info, similar to the existing --warn flag to enable diagnostic
    information messages (default behavior).
  * --no-info, similar to the existing --no-warn flag to disable diagnostic
    information messages.

It also adds the flags to the existing documentation, and command manual.
 gas/as.c                | 18 +++++++++++++++++-
 gas/as.h                |  3 +++
 gas/config/tc-aarch64.c |  3 +++
 gas/doc/as.texi         | 34 ++++++++++++++++++++++++++++++++++
 gas/messages.c          |  3 +++
 5 files changed, 60 insertions(+), 1 deletion(-)


diff --git a/gas/as.c b/gas/as.c
index 259dc0ee580..93792e5d4d1 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -393,6 +393,10 @@  Options:\n\
   --warn                  don't suppress warnings\n"));
   fprintf (stream, _("\
   --fatal-warnings        treat warnings as errors\n"));
+  fprintf (stream, _("\
+  --no-info               suppress information messages\n"));
+  fprintf (stream, _("\
+  --info                  don't suppress information messages\n"));
   fprintf (stream, _("\
   --itbl INSTTBL          extend instruction set to include instructions\n\
@@ -519,7 +523,9 @@  parse_args (int * pargc, char *** pargv)
     /* When you add options here, check that they do
        not collide with OPTION_MD_BASE.  See as.h.  */
@@ -595,6 +601,7 @@  parse_args (int * pargc, char *** pargv)
     ,{"mri", no_argument, NULL, 'M'}
     ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
     ,{"no-pad-sections", no_argument, NULL, OPTION_NO_PAD_SECTIONS}
+    ,{"no-info", no_argument, NULL, OPTION_NOINFO}
     ,{"no-warn", no_argument, NULL, 'W'}
     ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
     ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
@@ -603,6 +610,7 @@  parse_args (int * pargc, char *** pargv)
     ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
     ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
     ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
+    ,{"info", no_argument, NULL, OPTION_INFO}
     ,{"warn", no_argument, NULL, OPTION_WARN}
     ,{"multibyte-handling", required_argument, NULL, OPTION_MULTIBYTE_HANDLING}
@@ -982,6 +990,14 @@  This program has absolutely no warranty.\n"));
 	  flag_fatal_warnings = 1;
+	  flag_no_information = 1;
+	  break;
+	  flag_no_information = 0;
+	  break;
 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
 	  flag_execstack = 1;
diff --git a/gas/as.h b/gas/as.h
index 24bf66eb8a7..5adcc679a8b 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -320,6 +320,9 @@  COMMON int flag_no_warnings; /* -W, --no-warn */
 /* True if warnings count as errors.  */
 COMMON int flag_fatal_warnings; /* --fatal-warnings */
+/* True if infos should be inhibited.  */
+COMMON int flag_no_information; /* --no-info */
 /* True if we should attempt to generate output even if non-fatal errors
    are detected.  */
 COMMON unsigned char flag_always_generate_output; /* -Z */
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 42c03bd199e..34ed802a2bc 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -5662,6 +5662,9 @@  print_operands (char *buf, const aarch64_opcode *opcode,
 static void
 output_info (const char *format, ...)
+  if (flag_no_information)
+    return;
   const char *file;
   unsigned int line;
   va_list args;
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index 352f2a328c3..ee65eb06668 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -261,6 +261,7 @@  gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}.
  [@b{-v}] [@b{-version}] [@b{--version}]
  [@b{-W}] [@b{--no-warn}] [@b{--warn}] [@b{--fatal-warnings}]
+ [@b{--no-info}] [@b{--info}]
  [@b{-w}] [@b{-x}]
  [@b{-Z}] [@b{@@@var{FILE}}]
@@ -990,6 +991,12 @@  Don't suppress warning messages or treat them as errors.
 @item --fatal-warnings
 Treat warnings as errors.
+@item --no-info
+Suppress information messages.
+@item --info
+Don't suppress information messages.
 @item -w
@@ -2465,6 +2472,7 @@  assembler.)
 * traditional-format:: --traditional-format for compatible output
 * v::             -v to announce version
 * W::             -W, --no-warn, --warn, --fatal-warnings to control warnings
+* info::          --no-info, --info to control information messages
 * Z::             -Z to make object file even after errors
 @end menu
@@ -2573,6 +2581,32 @@  working directory is always searched first; after that, @command{@value{AS}}
 searches any @samp{-I} directories in the same order as they were
 specified (left to right) on the command line.
+@node info
+@section Control Information Messages: @option{--info}, @option{--no-info}
+In some cases, @command{@value{AS}} might give an additional information message
+associated to a context that generated a warning or error message when assembling.
+The information message provides additional details about an earlier diagnostic
+message, usually in the form of some context (such as when the earlier diagnostic
+was within a macro).
+All such informations are directed to the standard error file.
+This flag only affects the information messages, it does not change any particular
+of how @command{@value{AS}} assembles your file.
+@kindex --no-info
+@cindex diagnostic informations, switching off
+You can switch the option @option{--info} off by specifying @option{--no-info},
+which disables printing of additional information in the context of an earlier
+@kindex --info
+@cindex diagnostic informations, switching on (default behavior)
+The option @option{--info} is enabled by default, and enables printing of additional
+diagnostic informations.
+Specifying @option{--info} after @option{--no-info} will turn on again printing
+of additional diagnostic informations.
 @node K
 @section Difference Tables: @option{-K}
diff --git a/gas/messages.c b/gas/messages.c
index bbe2596f27b..17835d1c251 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -138,6 +138,9 @@  void
 as_info_where (const char *file, unsigned int line, unsigned int indent,
 	       const char *format, ...)
+  if (flag_no_information)
+    return;
   va_list args;
   char buffer[2000];