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

Message ID 20240710112610.1948227-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_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Matthieu Longo July 10, 2024, 11:26 a.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 8690b8f9142..7d245c4649f 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -5670,6 +5670,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..6027d56da82 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -253,6 +253,7 @@  gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}.
+ [@b{--no-info}] [@b{--info}]
  [@b{-o} @var{objfile}] [@b{-R}]
@@ -925,6 +926,12 @@  warning to be generated when a symbol is defined with a name that contains
 multibyte characters.  (References to undefined symbols will not generate a
+@item --no-info
+Suppress information messages.
+@item --info
+Don't suppress information messages.
 @item --no-pad-sections
 Stop the assembler for padding the ends of output sections to the alignment
 of that section.  The default is to pad the sections, but this can waste space
@@ -2458,6 +2465,7 @@  assembler.)
 * listing::       --listing-XXX to configure listing output
 * M::		  -M or --mri to assemble in MRI compatibility mode
 * MD::            --MD for dependency tracking
+* no-info::       --no-info, --info to control information messages
 * no-pad-sections:: --no-pad-sections to stop section padding
 * o::             -o to name the object file
 * R::             -R to join data and text sections
@@ -2775,6 +2783,32 @@  The rule is written to the file named in its argument.
 This feature is used in the automatic updating of makefiles.
+@node no-info
+@section Control Information Messages: @option{--no-info}, @option{--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 no-pad-sections
 @section Output Section Padding
 @kindex --no-pad-sections
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];