gas: Check for overflow on return column in version 1 CIE DWARF
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 4 Nov 2019 22:44:48 +0000 (22:44 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 28 Nov 2019 00:03:05 +0000 (00:03 +0000)
In version 1 of DWARF CIE format, the return register column is just a
single byte.  For targets with large numbers of DWARF registers, any
use of a register with a high number for the return column
will (currently) silently overflow giving incorrect DWARF.

This commit adds an error when the overflow occurs.

gas/ChangeLog:

* dw2gencfi.c (output_cie): Error on return column overflow.
* testsuite/gas/riscv/cie-rtn-col-1.d: New file.
* testsuite/gas/riscv/cie-rtn-col-3.d: New file.
* testsuite/gas/riscv/cie-rtn-col.s: New file.

Change-Id: I1809f739ba7771737ec012807f0260e1a3ed5e64

gas/ChangeLog
gas/dw2gencfi.c
gas/testsuite/gas/riscv/cie-rtn-col-1.d [new file with mode: 0644]
gas/testsuite/gas/riscv/cie-rtn-col-3.d [new file with mode: 0644]
gas/testsuite/gas/riscv/cie-rtn-col.s [new file with mode: 0644]

index 474e5c31f8af9f3ddbfe37fa1e8e99c8e0173c9f..c7dfd5ee98bf4597266e1190fd3dd1c454967a51 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-22  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * dw2gencfi.c (output_cie): Error on return column overflow.
+       * testsuite/gas/riscv/cie-rtn-col-1.d: New file.
+       * testsuite/gas/riscv/cie-rtn-col-3.d: New file.
+       * testsuite/gas/riscv/cie-rtn-col.s: New file.
+
 2019-11-22  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * config/tc-riscv.c (tc_riscv_regname_to_dw2regnum): Lookup CSR
index e27253db8ee9277db2408327c2977f152e5095dc..c1b5becc0a69937bf5524581ca98bd9592460269 100644 (file)
@@ -1887,7 +1887,12 @@ output_cie (struct cie_entry *cie, bfd_boolean eh_frame, int align)
   out_uleb128 (DWARF2_LINE_MIN_INSN_LENGTH);   /* Code alignment.  */
   out_sleb128 (DWARF2_CIE_DATA_ALIGNMENT);     /* Data alignment.  */
   if (flag_dwarf_cie_version == 1)             /* Return column.  */
-    out_one (cie->return_column);
+    {
+      if ((cie->return_column & 0xff) != cie->return_column)
+       as_bad (_("return column number %d overflows in CIE version 1"),
+               cie->return_column);
+      out_one (cie->return_column);
+    }
   else
     out_uleb128 (cie->return_column);
   if (eh_frame)
diff --git a/gas/testsuite/gas/riscv/cie-rtn-col-1.d b/gas/testsuite/gas/riscv/cie-rtn-col-1.d
new file mode 100644 (file)
index 0000000..dba9c0d
--- /dev/null
@@ -0,0 +1,3 @@
+#as: --gdwarf-cie-version=1
+#source: cie-rtn-col.s
+#error: return column number 4929 overflows in CIE version 1
diff --git a/gas/testsuite/gas/riscv/cie-rtn-col-3.d b/gas/testsuite/gas/riscv/cie-rtn-col-3.d
new file mode 100644 (file)
index 0000000..a1d71e1
--- /dev/null
@@ -0,0 +1,17 @@
+#objdump: --dwarf=frames
+#as: --gdwarf-cie-version=3
+#source: cie-rtn-col.s
+
+.*:     file format elf.*-.*riscv
+
+Contents of the .* section:
+
+
+00000000 [a-zA-Z0-9]+ [a-zA-Z0-9]+ CIE
+  Version:               3
+  Augmentation:          .*
+  Code alignment factor: .*
+  Data alignment factor: .*
+  Return address column: 4929
+  Augmentation data:     .*
+#...
diff --git a/gas/testsuite/gas/riscv/cie-rtn-col.s b/gas/testsuite/gas/riscv/cie-rtn-col.s
new file mode 100644 (file)
index 0000000..b5e3aa6
--- /dev/null
@@ -0,0 +1,3 @@
+       .cfi_startproc
+       .cfi_return_column mepc
+       .cfi_endproc
This page took 0.027689 seconds and 4 git commands to generate.