[PATCH] gas: Fix .debug_info CU header for --gdwarf-5
Mark Wielaard
mark@klomp.org
Mon Aug 3 00:37:27 GMT 2020
DWARF5 CU headers have a new unit type field and move the abbrev offset
to the end of the header.
gas/ChangeLog:
* dwarf2dbg.c (out_debug_info): Emit unit type and abbrev offset
for DWARF5.
* gas/testsuite/gas/elf/dwarf-4-cu.d: New file.
* gas/testsuite/gas/elf/dwarf-4-cu.s: Likewise.
* gas/testsuite/gas/elf/dwarf-5-cu.d: Likewise.
* gas/testsuite/gas/elf/dwarf-5-cu.s: Likewise.
* testsuite/gas/elf/elf.exp: Run dwarf-4-cu and dwarf-5-cu.
---
gas/ChangeLog | 10 ++++++++++
gas/dwarf2dbg.c | 18 ++++++++++++++++--
gas/testsuite/gas/elf/dwarf-4-cu.d | 11 +++++++++++
gas/testsuite/gas/elf/dwarf-4-cu.s | 14 ++++++++++++++
gas/testsuite/gas/elf/dwarf-5-cu.d | 11 +++++++++++
gas/testsuite/gas/elf/dwarf-5-cu.s | 14 ++++++++++++++
gas/testsuite/gas/elf/elf.exp | 2 ++
7 files changed, 78 insertions(+), 2 deletions(-)
create mode 100644 gas/testsuite/gas/elf/dwarf-4-cu.d
create mode 100644 gas/testsuite/gas/elf/dwarf-4-cu.s
create mode 100644 gas/testsuite/gas/elf/dwarf-5-cu.d
create mode 100644 gas/testsuite/gas/elf/dwarf-5-cu.s
diff --git a/gas/ChangeLog b/gas/ChangeLog
index b39ed9316f2..e2c3b77a959 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-02 Mark Wielaard <mark@klomp.org>
+
+ * dwarf2dbg.c (out_debug_info): Emit unit type and abbrev offset
+ for DWARF5.
+ * gas/testsuite/gas/elf/dwarf-4-cu.d: New file.
+ * gas/testsuite/gas/elf/dwarf-4-cu.s: Likewise.
+ * gas/testsuite/gas/elf/dwarf-5-cu.d: Likewise.
+ * gas/testsuite/gas/elf/dwarf-5-cu.s: Likewise.
+ * testsuite/gas/elf/elf.exp: Run dwarf-4-cu and dwarf-5-cu.
+
2020-08-02 Mark Wielaard <mark@klomp.org>
* doc/as.texi (--gdwarf-[345]): Fix typo.
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 69955fea5bf..b19e057c762 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -2464,12 +2464,26 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg,
/* DWARF version. */
out_two (DWARF2_VERSION);
- /* .debug_abbrev offset */
- TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
+ if (DWARF2_VERSION < 5)
+ {
+ /* .debug_abbrev offset */
+ TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
+ }
+ else
+ {
+ /* unit (header) type */
+ out_byte (DW_UT_compile);
+ }
/* Target address size. */
out_byte (sizeof_address);
+ if (DWARF2_VERSION >= 5)
+ {
+ /* .debug_abbrev offset */
+ TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
+ }
+
/* DW_TAG_compile_unit DIE abbrev */
out_uleb128 (1);
diff --git a/gas/testsuite/gas/elf/dwarf-4-cu.d b/gas/testsuite/gas/elf/dwarf-4-cu.d
new file mode 100644
index 00000000000..85a07390d38
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-4-cu.d
@@ -0,0 +1,11 @@
+#as: --gdwarf-4
+#name: DWARF4 CU
+#readelf: -wi
+
+#...
+ Compilation Unit @ offset 0x0:
+ Length: 0x.*
+ Version: 4
+ Abbrev Offset: 0x0
+ Pointer Size: .
+#pass
diff --git a/gas/testsuite/gas/elf/dwarf-4-cu.s b/gas/testsuite/gas/elf/dwarf-4-cu.s
new file mode 100644
index 00000000000..828f4102a3b
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-4-cu.s
@@ -0,0 +1,14 @@
+ .text
+ .file 1 "foo/bar.s"
+ .loc_mark_labels 1
+ .globl foobar
+ .type foobar, %function
+foobar:
+ .quad 0x1
+ .size foobar, .-foobar
+
+ .globl baz
+ .type baz, %function
+baz:
+ .quad 0x1
+ .size baz, .-baz
diff --git a/gas/testsuite/gas/elf/dwarf-5-cu.d b/gas/testsuite/gas/elf/dwarf-5-cu.d
new file mode 100644
index 00000000000..839b4b7c77b
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-cu.d
@@ -0,0 +1,11 @@
+#as: --gdwarf-5
+#name: DWARF5 CU
+#readelf: -wi
+
+#...
+ Compilation Unit @ offset 0x0:
+ Length: 0x.*
+ Version: 5
+ Abbrev Offset: 0x0
+ Pointer Size: .
+#pass
diff --git a/gas/testsuite/gas/elf/dwarf-5-cu.s b/gas/testsuite/gas/elf/dwarf-5-cu.s
new file mode 100644
index 00000000000..828f4102a3b
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-cu.s
@@ -0,0 +1,14 @@
+ .text
+ .file 1 "foo/bar.s"
+ .loc_mark_labels 1
+ .globl foobar
+ .type foobar, %function
+foobar:
+ .quad 0x1
+ .size foobar, .-foobar
+
+ .globl baz
+ .type baz, %function
+baz:
+ .quad 0x1
+ .size baz, .-baz
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 86b304ae34f..155f78efa7f 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -274,6 +274,8 @@ if { [is_elf_format] } then {
run_dump_test "dwarf2-18" $dump_opts
run_dump_test "dwarf2-19" $dump_opts
run_dump_test "dwarf-5-file0" $dump_opts
+ run_dump_test "dwarf-4-cu" $dump_opts
+ run_dump_test "dwarf-5-cu" $dump_opts
run_dump_test "pr25917"
run_dump_test "bss"
run_dump_test "bad-bss"
--
2.18.4
More information about the Binutils
mailing list