gas: Add --gdwarf-cie-version command line flag
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 4 Nov 2019 12:27:45 +0000 (12:27 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 18 Nov 2019 10:30:21 +0000 (10:30 +0000)
Add a flag to control the version of CIE that is generated.  By
default gas produces CIE version 1, and this continues to be the
default after this patch.

However, a user can now provide --gdwarf-cie-version=NUMBER to switch
to either version 3 or version 4 of CIE, version 2 was never released,
and so causes an error as does any number less than 1 or greater than
4.

Producing version 4 CIE requires two new fields to be added to the
CIE, an address size field, and an segment selector field.  For a flat
address space the DWARF specification indicates that the segment
selector should be 0, and the address size fields just contains the
address size in bytes.  For now we support 4 or 8 byte addresses, and
the segment selector is always produced as 0.  At some future time we
might need to allow targets to override this.

gas/ChangeLog:

* as.c (parse_args): Parse --gdwarf-cie-version option.
(flag_dwarf_cie_version): New variable.
* as.h (flag_dwarf_cie_version): Declare.
* dw2gencfi.c (output_cie): Switch from DW_CIE_VERSION to
flag_dwarf_cie_version.
* doc/as.texi (Overview): Document --gdwarf-cie-version.
* NEWS: Likewise.
* testsuite/gas/cfi/cfi.exp: Add new tests.
* testsuite/gas/cfi/cie-version-0.d: New file.
* testsuite/gas/cfi/cie-version-1.d: New file.
* testsuite/gas/cfi/cie-version-2.d: New file.
* testsuite/gas/cfi/cie-version-3.d: New file.
* testsuite/gas/cfi/cie-version-4.d: New file.
* testsuite/gas/cfi/cie-version.s: New file.

include/ChangeLog:

* dwarf2.h (DW_CIE_VERSION): Delete.

Change-Id: I9de19461aeb8332b5a57bbfe802953d0725a7ae8

15 files changed:
gas/ChangeLog
gas/NEWS
gas/as.c
gas/as.h
gas/doc/as.texi
gas/dw2gencfi.c
gas/testsuite/gas/cfi/cfi.exp
gas/testsuite/gas/cfi/cie-version-0.d [new file with mode: 0644]
gas/testsuite/gas/cfi/cie-version-1.d [new file with mode: 0644]
gas/testsuite/gas/cfi/cie-version-2.d [new file with mode: 0644]
gas/testsuite/gas/cfi/cie-version-3.d [new file with mode: 0644]
gas/testsuite/gas/cfi/cie-version-4.d [new file with mode: 0644]
gas/testsuite/gas/cfi/cie-version.s [new file with mode: 0644]
include/ChangeLog
include/dwarf2.h

index 7e9e6eff487eb1ee2be24cd9fcfb94c0597fe56e..d9ad6498efc0dfd8d3da17f6b394e606c77ad64c 100644 (file)
@@ -1,3 +1,20 @@
+2019-11-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * as.c (parse_args): Parse --gdwarf-cie-version option.
+       (flag_dwarf_cie_version): New variable.
+       * as.h (flag_dwarf_cie_version): Declare.
+       * dw2gencfi.c (output_cie): Switch from DW_CIE_VERSION to
+       flag_dwarf_cie_version.
+       * doc/as.texi (Overview): Document --gdwarf-cie-version.
+       * NEWS: Likewise.
+       * testsuite/gas/cfi/cfi.exp: Add new tests.
+       * testsuite/gas/cfi/cie-version-0.d: New file.
+       * testsuite/gas/cfi/cie-version-1.d: New file.
+       * testsuite/gas/cfi/cie-version-2.d: New file.
+       * testsuite/gas/cfi/cie-version-3.d: New file.
+       * testsuite/gas/cfi/cie-version-4.d: New file.
+       * testsuite/gas/cfi/cie-version.s: New file.
+
 2019-11-14  Jan Beulich  <jbeulich@suse.com>
 
        * config/tc-i386.c (operand_size_match, md_assemble,
index 1e7007428b5e87a65c350088693b8c4ce36127e6..aaf857292c3e1e138d1a227264cabd0a6e2ca7aa 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -27,6 +27,9 @@ Changes in 2.33:
   -mfp16-format=[ieee|alternative] option for Arm to control the format of the
   encoding.
 
+* Add --gdwarf-cie-version command line flag.  This allows control over which
+  version of DWARF CIE the assembler creates.
+
 Changes in 2.32:
 
 * Add -mvexwig=[0|1] option to x86 assembler to control encoding of
index d53db113e22ea868f69a3da29390813a0f1c52e3..cc84725a421fcdc60b7a6eac157d42feceb3da60 100644 (file)
--- a/gas/as.c
+++ b/gas/as.c
@@ -95,6 +95,11 @@ int debug_memory = 0;
 /* Enable verbose mode.  */
 int verbose = 0;
 
+/* Which version of DWARF CIE to produce.  The default could be overridden
+   by a target during its initialisation, or by the --gdwarf-cie-version
+   command line flag.  */
+int flag_dwarf_cie_version = 1;
+
 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
 int flag_use_elf_stt_common = DEFAULT_GENERATE_ELF_STT_COMMON;
 bfd_boolean flag_generate_build_notes = DEFAULT_GENERATE_BUILD_NOTES;
@@ -479,6 +484,7 @@ parse_args (int * pargc, char *** pargv)
       OPTION_GSTABS_PLUS,
       OPTION_GDWARF2,
       OPTION_GDWARF_SECTIONS,
+      OPTION_GDWARF_CIE_VERSION,
       OPTION_STRIP_LOCAL_ABSOLUTE,
       OPTION_TRADITIONAL_FORMAT,
       OPTION_WARN,
@@ -534,6 +540,7 @@ parse_args (int * pargc, char *** pargv)
        so we keep it here for backwards compatibility.  */
     ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
     ,{"gdwarf-sections", no_argument, NULL, OPTION_GDWARF_SECTIONS}
+    ,{"gdwarf-cie-version", required_argument, NULL, OPTION_GDWARF_CIE_VERSION}
     ,{"gen-debug", no_argument, NULL, 'g'}
     ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
     ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
@@ -828,6 +835,16 @@ This program has absolutely no warranty.\n"));
          flag_dwarf_sections = TRUE;
          break;
 
+        case OPTION_GDWARF_CIE_VERSION:
+         flag_dwarf_cie_version = atoi (optarg);
+          /* The available CIE versions are 1 (DWARF 2), 3 (DWARF 3), and 4
+             (DWARF 4 and 5).  */
+         if (flag_dwarf_cie_version < 1
+              || flag_dwarf_cie_version == 2
+              || flag_dwarf_cie_version > 4)
+            as_fatal (_("Invalid --gdwarf-cie-version `%s'"), optarg);
+         break;
+
        case 'J':
          flag_signed_overflow_ok = 1;
          break;
index d996697bed8784260a8f5400ac0c72254e4d0387..3c37519c1bf13874a0de7db120ee5348fd7eaf99 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -412,6 +412,7 @@ enum debug_info_type
 extern enum debug_info_type debug_type;
 extern int use_gnu_debug_info_extensions;
 COMMON bfd_boolean flag_dwarf_sections;
+extern int flag_dwarf_cie_version;
 \f
 /* Maximum level of macro nesting.  */
 extern int max_macro_nest;
index b54ab1eeccc2ee9e6d03b23af5ab8a4754bfea11..532ed7acfac0b91a434e566250123e66fda1c9ba 100644 (file)
@@ -231,6 +231,7 @@ gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}.
  [@b{--debug-prefix-map} @var{old}=@var{new}]
  [@b{--defsym} @var{sym}=@var{val}] [@b{-f}] [@b{-g}] [@b{--gstabs}]
  [@b{--gstabs+}] [@b{--gdwarf-2}] [@b{--gdwarf-sections}]
+ [@b{--gdwarf-cie-version}=@var{VERSION}]
  [@b{--help}] [@b{-I} @var{dir}] [@b{-J}]
  [@b{-K}] [@b{-L}] [@b{--listing-lhs-width}=@var{NUM}]
  [@b{--listing-lhs-width2}=@var{NUM}] [@b{--listing-rhs-width}=@var{NUM}]
@@ -772,6 +773,11 @@ will have its dwarf line number information placed into a section called
 then debug line section will still be called just @var{.debug_line} without any
 suffix.
 
+@item --gdwarf-cie-version=@var{version}
+Control which version of DWARF Common Information Entries (CIEs) are produced.
+When this flag is not specificed the default is version 1, though some targets
+can modify this default.  Other possible values for @var{version} are 3 or 4.
+
 @ifset ELF
 @item --size-check=error
 @itemx --size-check=warning
index 6c0478a72063801f1f91441a11350daa94605843..e27253db8ee9277db2408327c2977f152e5095dc 100644 (file)
@@ -1860,7 +1860,7 @@ output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
       if (fmt != dwarf2_format_32bit)
        out_four (-1);
     }
-  out_one (DW_CIE_VERSION);                    /* Version.  */
+  out_one (flag_dwarf_cie_version);            /* Version.  */
   if (eh_frame)
     {
       out_one ('z');                           /* Augmentation.  */
@@ -1876,9 +1876,17 @@ output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
   if (cie->signal_frame)
     out_one ('S');
   out_one (0);
+  if (flag_dwarf_cie_version >= 4)
+    {
+      /* For now we are assuming a flat address space with 4 or 8 byte
+         addresses.  */
+      int address_size = dwarf2_format_32bit ? 4 : 8;
+      out_one (address_size);                  /* Address size.  */
+      out_one (0);                             /* Segment size.  */
+    }
   out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH);   /* Code alignment.  */
   out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT);     /* Data alignment.  */
-  if (DW_CIE_VERSION == 1)                     /* Return column.  */
+  if (flag_dwarf_cie_version == 1)             /* Return column.  */
     out_one (cie->return_column);
   else
     out_uleb128 (cie->return_column);
index c55f069afb75aedd932b34165141993b049ebf32..2d410545b290b112d2257093cc651804f2a668bd 100644 (file)
@@ -133,4 +133,10 @@ if { ![istarget "hppa64*-*"] } then {
   run_dump_test "cfi-common-7"
   run_dump_test "cfi-common-8"
   run_dump_test "cfi-common-9"
+
+  run_dump_test "cie-version-0"
+  run_dump_test "cie-version-1"
+  run_dump_test "cie-version-2"
+  run_dump_test "cie-version-3"
+  run_dump_test "cie-version-4"
 }
diff --git a/gas/testsuite/gas/cfi/cie-version-0.d b/gas/testsuite/gas/cfi/cie-version-0.d
new file mode 100644 (file)
index 0000000..d9f71c4
--- /dev/null
@@ -0,0 +1,5 @@
+#objdump: --dwarf=frames
+#name: CIE Version 0
+#as: --gdwarf-cie-version=0
+#source: cie-version.s
+#error: Invalid --gdwarf-cie-version `0'
diff --git a/gas/testsuite/gas/cfi/cie-version-1.d b/gas/testsuite/gas/cfi/cie-version-1.d
new file mode 100644 (file)
index 0000000..2a9a8f1
--- /dev/null
@@ -0,0 +1,17 @@
+#objdump: --dwarf=frames
+#name: CIE Version 1
+#as: --gdwarf-cie-version=1
+#source: cie-version.s
+#...
+.*:     file format .*
+
+Contents of the .eh_frame section:
+
+00000000 0+[0-9a-f]+ 0+000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: .*
+  Data alignment factor: .*
+  Return address column: .*
+  Augmentation data:     [01][abc]
+#...
\ No newline at end of file
diff --git a/gas/testsuite/gas/cfi/cie-version-2.d b/gas/testsuite/gas/cfi/cie-version-2.d
new file mode 100644 (file)
index 0000000..5279489
--- /dev/null
@@ -0,0 +1,5 @@
+#objdump: --dwarf=frames
+#name: CIE Version 2
+#as: --gdwarf-cie-version=2
+#source: cie-version.s
+#error: Invalid --gdwarf-cie-version `2'
diff --git a/gas/testsuite/gas/cfi/cie-version-3.d b/gas/testsuite/gas/cfi/cie-version-3.d
new file mode 100644 (file)
index 0000000..68cb79d
--- /dev/null
@@ -0,0 +1,17 @@
+#objdump: --dwarf=frames
+#name: CIE Version 3
+#as: --gdwarf-cie-version=3
+#source: cie-version.s
+#...
+.*:     file format .*
+
+Contents of the .eh_frame section:
+
+00000000 0+[0-9a-f]+ 0+000 CIE
+  Version:               3
+  Augmentation:          "zR"
+  Code alignment factor: .*
+  Data alignment factor: .*
+  Return address column: .*
+  Augmentation data:     [01][abc]
+#...
\ No newline at end of file
diff --git a/gas/testsuite/gas/cfi/cie-version-4.d b/gas/testsuite/gas/cfi/cie-version-4.d
new file mode 100644 (file)
index 0000000..bdd19d9
--- /dev/null
@@ -0,0 +1,19 @@
+#objdump: --dwarf=frames
+#name: CIE Version 4
+#as: --gdwarf-cie-version=4
+#source: cie-version.s
+#...
+.*:     file format .*
+
+Contents of the .eh_frame section:
+
+00000000 0+[0-9a-f]+ 0+000 CIE
+  Version:               4
+  Augmentation:          "zR"
+  Pointer Size:          .*
+  Segment Size:          .*
+  Code alignment factor: .*
+  Data alignment factor: .*
+  Return address column: .*
+  Augmentation data:     [01][abc]
+#...
diff --git a/gas/testsuite/gas/cfi/cie-version.s b/gas/testsuite/gas/cfi/cie-version.s
new file mode 100644 (file)
index 0000000..659b3b9
--- /dev/null
@@ -0,0 +1,2 @@
+       .cfi_startproc
+       .cfi_endproc
index 591ae4e773b6b857fd5c06e0a6f0a5c6ab7a08f6..bfbf2bd5a2cb1c542b0fe11a843da66706df8053 100644 (file)
@@ -1,3 +1,7 @@
+2019-11-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * dwarf2.h (DW_CIE_VERSION): Delete.
+
 2019-11-07  Mihail Ionescu  <mihail.ionescu@arm.com>
 
        * opcode/arm.h (ARM_EXT2_I8MM): New feature macro.
index e03349da9406bb0dc4728741c8244ce4dbae18d7..a4a183155358936af2ce2b2f4c53faadd6052c4c 100644 (file)
@@ -316,7 +316,6 @@ enum dwarf_location_list_entry_type
 
 #define DW_CIE_ID        0xffffffff
 #define DW64_CIE_ID      0xffffffffffffffffULL
-#define DW_CIE_VERSION   1
 
 #define DW_CFA_extended   0
 
This page took 0.032427 seconds and 4 git commands to generate.