This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] gas: Add --gdwarf-cie-version command line flag


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
---
 gas/ChangeLog                         | 17 +++++++++++++++++
 gas/NEWS                              |  3 +++
 gas/as.c                              | 17 +++++++++++++++++
 gas/as.h                              |  1 +
 gas/doc/as.texi                       |  6 ++++++
 gas/dw2gencfi.c                       | 12 ++++++++++--
 gas/testsuite/gas/cfi/cfi.exp         |  6 ++++++
 gas/testsuite/gas/cfi/cie-version-0.d |  5 +++++
 gas/testsuite/gas/cfi/cie-version-1.d | 17 +++++++++++++++++
 gas/testsuite/gas/cfi/cie-version-2.d |  5 +++++
 gas/testsuite/gas/cfi/cie-version-3.d | 17 +++++++++++++++++
 gas/testsuite/gas/cfi/cie-version-4.d | 19 +++++++++++++++++++
 gas/testsuite/gas/cfi/cie-version.s   |  2 ++
 include/ChangeLog                     |  4 ++++
 include/dwarf2.h                      |  1 -
 15 files changed, 129 insertions(+), 3 deletions(-)
 create mode 100644 gas/testsuite/gas/cfi/cie-version-0.d
 create mode 100644 gas/testsuite/gas/cfi/cie-version-1.d
 create mode 100644 gas/testsuite/gas/cfi/cie-version-2.d
 create mode 100644 gas/testsuite/gas/cfi/cie-version-3.d
 create mode 100644 gas/testsuite/gas/cfi/cie-version-4.d
 create mode 100644 gas/testsuite/gas/cfi/cie-version.s

diff --git a/gas/NEWS b/gas/NEWS
index 1e7007428b5..aaf857292c3 100644
--- 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
diff --git a/gas/as.c b/gas/as.c
index d53db113e22..cc84725a421 100644
--- 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;
diff --git a/gas/as.h b/gas/as.h
index d996697bed8..3c37519c1bf 100644
--- 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;
 
 /* Maximum level of macro nesting.  */
 extern int max_macro_nest;
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index b54ab1eeccc..532ed7acfac 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -231,6 +231,7 @@
  [@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 @@
 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
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 6c0478a7206..e27253db8ee 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -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);
diff --git a/gas/testsuite/gas/cfi/cfi.exp b/gas/testsuite/gas/cfi/cfi.exp
index c55f069afb7..2d410545b29 100644
--- a/gas/testsuite/gas/cfi/cfi.exp
+++ b/gas/testsuite/gas/cfi/cfi.exp
@@ -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
index 00000000000..d9f71c41834
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version-0.d
@@ -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
index 00000000000..2a9a8f1d386
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version-1.d
@@ -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
index 00000000000..5279489ae9c
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version-2.d
@@ -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
index 00000000000..68cb79d49e1
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version-3.d
@@ -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
index 00000000000..bdd19d994f5
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version-4.d
@@ -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
index 00000000000..659b3b9d99b
--- /dev/null
+++ b/gas/testsuite/gas/cfi/cie-version.s
@@ -0,0 +1,2 @@
+	.cfi_startproc
+	.cfi_endproc
diff --git a/include/dwarf2.h b/include/dwarf2.h
index e03349da940..a4a18315535 100644
--- a/include/dwarf2.h
+++ b/include/dwarf2.h
@@ -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
 
-- 
2.14.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]