[v2,2/3] gas: Handle --compress-debug-sections=subopt1,subopt2

Message ID 20230228001633.3602-2-tdevries@suse.de
State Unresolved
Headers
Series [v2,1/3] gas: Unify parsing of --compress-debug-sections |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Tom de Vries Feb. 28, 2023, 12:16 a.m. UTC
  Add the possibility to specify more than one --compress-debug-sections subopt
at a time, using a comma separator.

Using --compress-debug-sections=subopt1,subopt2 is equivalent to using
--compress-debug-sections=subopt1 --compress-debug-sections=subopt2.
---
 gas/as.c | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gas/as.c b/gas/as.c
index 40742b13511..c159c5d0d0a 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -419,13 +419,8 @@  Options:\n\
 }
 
 static void
-parse_compress_debug_optarg (const char *optarg)
+parse_compress_debug_optarg_1 (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
@@ -444,6 +439,45 @@  parse_compress_debug_optarg (const char *optarg)
   flag_compress_debug = tmp;
 }
 
+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);
+
+  /* Tokenize subopts pass to parse_compress_debug_optarg_1.  */
+  char sep = ',';
+  while (true)
+    {
+      const char *idx = optarg;
+      while (*idx != '\0' && *idx != sep)
+	idx++;
+
+      size_t len = idx - optarg;
+      if (len == 0)
+	{
+	  /* Generate error.  */
+	  parse_compress_debug_optarg_1 ("");
+	  break;
+	}
+
+      char *tmp = xstrndup (optarg, len);
+      parse_compress_debug_optarg_1 (tmp);
+      free (tmp);
+
+      if (*idx == '\0')
+	break;
+
+      /* Step over separator and continue tokenizing.  */
+      gas_assert (*idx == sep);
+      optarg = idx + 1;
+  }
+}
+
 /* 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