public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] gas: Unify parsing of --compress-debug-sections
@ 2023-02-28  0:16 Tom de Vries
  2023-02-28  0:16 ` [PATCH v2 2/3] gas: Handle --compress-debug-sections=subopt1,subopt2 Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom de Vries @ 2023-02-28  0:16 UTC (permalink / raw)
  To: binutils

There are three related option forms:
* --compress-debug-sections=<none|zlib|zlib-gnu|zlib-gabi>
* --compress-debug-sections
* --nocompress-debug-sections
where the last two are documented as being equivalent to:
* --compress-debug-section=zlib-gabi
* --compress-debug-section=none

However, the three related option forms are handled independently in
parse_args, and there are minor differences in handling.

For instance, in case !defined OBJ_ELF && !defined OBJ_MAYBE_ELF, using
--compress-debug-section=zlib-gabi or --compress-debug-section=none will
trigger as_fatal ("--compress-debug-sections=%s is unsupported"), while that's
not the case for --compress-debug-sections and --nocompress-debug-sections.

Fix this by:
- factoring out a new function parse_compress_debug_optarg, and
- using it to handle all three options forms.

Also make the code easier to read by not nesting preprocessor conditionals.
---
 gas/as.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index 598bfd56cf5..40742b13511 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -418,6 +418,32 @@ Options:\n\
     fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
 }
 
+static void
+parse_compress_debug_optarg (const char *optarg)
+{
+#if !defined OBJ_ELF && !defined OBJ_MAYBE_ELF
+  as_fatal (_("--compress-debug-sections=%s is unsupported"),
+	    optarg);
+#endif
+
+  gas_assert (optarg != NULL);
+
+  enum compressed_debug_section_type tmp
+    = bfd_get_compression_algorithm (optarg);
+
+#ifndef HAVE_ZSTD
+  if (tmp == COMPRESS_DEBUG_ZSTD)
+    as_fatal (_ ("--compress-debug-sections=zstd: gas is not "
+		 "built with zstd support"));
+#endif
+
+  if (tmp == COMPRESS_UNKNOWN)
+    as_fatal (_("Invalid --compress-debug-sections option: `%s'"),
+	      optarg);
+
+  flag_compress_debug = tmp;
+}
+
 /* Since it is easy to do here we interpret the special arg "-"
    to mean "use stdin" and we set that argv[] pointing to "".
    After we have munged argv[], the only things left are source file
@@ -747,28 +773,13 @@ This program has absolutely no warranty.\n"));
 
 	case OPTION_COMPRESS_DEBUG:
 	  if (optarg)
-	    {
-#if defined OBJ_ELF || defined OBJ_MAYBE_ELF
-	      flag_compress_debug = bfd_get_compression_algorithm (optarg);
-#ifndef HAVE_ZSTD
-	      if (flag_compress_debug == COMPRESS_DEBUG_ZSTD)
-		  as_fatal (_ ("--compress-debug-sections=zstd: gas is not "
-			       "built with zstd support"));
-#endif
-	      if (flag_compress_debug == COMPRESS_UNKNOWN)
-		as_fatal (_("Invalid --compress-debug-sections option: `%s'"),
-			  optarg);
-#else
-	      as_fatal (_("--compress-debug-sections=%s is unsupported"),
-			optarg);
-#endif
-	    }
+	    parse_compress_debug_optarg (optarg);
 	  else
-	    flag_compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
+	    parse_compress_debug_optarg ("zlib-gabi");
 	  break;
 
 	case OPTION_NOCOMPRESS_DEBUG:
-	  flag_compress_debug = COMPRESS_DEBUG_NONE;
+	  parse_compress_debug_optarg ("none");
 	  break;
 
 	case OPTION_DEBUG_PREFIX_MAP:

base-commit: d273049e140ef324be2b018e235ae0ba8021a769
-- 
2.35.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-09 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28  0:16 [PATCH v2 1/3] gas: Unify parsing of --compress-debug-sections Tom de Vries
2023-02-28  0:16 ` [PATCH v2 2/3] gas: Handle --compress-debug-sections=subopt1,subopt2 Tom de Vries
2023-02-28  0:16 ` [PATCH v2 3/3] gas: Add --compress-debug-sections={heuristic-always,heuristic-sizewin} Tom de Vries
2023-03-09 15:33 ` [PING] [PATCH v2 1/3] gas: Unify parsing of --compress-debug-sections Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).