[binutils-gdb/binutils-2_35-branch] gas: Handle bad -gdwarf options, just like bad --gdwarf options.

Mark Wielaard mark@sourceware.org
Mon Sep 14 22:44:12 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a2afee4a2ca4ff0ba15e4b16e7784f4be306f527

commit a2afee4a2ca4ff0ba15e4b16e7784f4be306f527
Author: Mark Wielaard <mark@klomp.org>
Date:   Wed Aug 26 21:46:04 2020 +0200

    gas: Handle bad -gdwarf options, just like bad --gdwarf options.
    
    parse_args uses getopt_long_only so it can handle long options both
    with double and single dash. But this means that some single dash
    options like -gdwarf-1 don't generate an error (unlike --gdwarf-1).
    
    This is especially confusing since there is also --gdwarf2, but no
    --gdwarf4 (it is --gdwarf-4). When giving -gdwarf4 the option is
    silently interpreted as -g (which set dwarf_version to 2). This causes
    some confusion for people who don't expect this and suddenly get
    DWARF2 instead of DWARF4 as they might expect.
    
    So make it so that the -gdwarf<unknown> creates an error, just like
    --gdwarf<unknown> would.

Diff:
---
 gas/ChangeLog | 7 +++++++
 gas/as.c      | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index bc72700cb47..10286e66e13 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,10 @@
+2020-09-14  Mark Wielaard  <mark@klomp.org>
+
+	Backport from mainline:
+	2020-08-26  Mark Wielaard  <mark@klomp.org>
+
+	* as.c (parse_args): Handle bad -gdwarf options.
+
 2020-08-26  David Faust  <david.faust@oracle.com>
 
 	* config/tc-bpf.c: Add option -mxbpf to select xbpf isa.
diff --git a/gas/as.c b/gas/as.c
index a04e615d35d..0801903126e 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -824,6 +824,13 @@ This program has absolutely no warranty.\n"));
 	      && md_parse_option (optc, optarg))
 	    continue;
 
+	  /* We end up here for any -gsomething-not-already-a-long-option.
+	     give some useful feedback on not (yet) supported -gdwarfxxx
+	     versions/sections/options.  */
+	  if (strncmp (old_argv[optind - 1], "-gdwarf",
+		       strlen ("-gdwarf")) == 0)
+	    as_fatal (_("unknown DWARF option %s\n"), old_argv[optind - 1]);
+
 	  if (md_debug_format_selector)
 	    debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
 	  else if (IS_ELF)


More information about the Binutils-cvs mailing list