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
This commit is contained in:
Andrew Burgess
2019-11-04 12:27:45 +00:00
parent f1e8bd2dd2
commit 66f8b2cbbb
15 changed files with 129 additions and 3 deletions

View 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,

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View 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

View 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);

View 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"
}

View File

@@ -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'

View File

@@ -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]
#...

View File

@@ -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'

View File

@@ -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]
#...

View File

@@ -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]
#...

View File

@@ -0,0 +1,2 @@
.cfi_startproc
.cfi_endproc

View 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.

View 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