DWARF: Add .debug_addr table header for dwarf_version >= 5.
authorMark Wielaard <mark@klomp.org>
Sat, 28 Apr 2018 19:54:08 +0000 (19:54 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Sat, 28 Apr 2018 19:54:08 +0000 (19:54 +0000)
GNU DebugFission didn't add table headers for the .debug_addr
tables, but DWARF5 does. The table header makes it possible
for a DWARF consumer to parse the address tables without having
to index all .debug_info CUs first.

We can keep using the .debug_addr section label as is, because the
DW_AT_[GNU_]addr_base attribute points at the actual address index,
which starts right after the table header. So the label is generated
at the correct location whether the header is added first or not.

Add DW_AT_addr_base instead of DW_AT_GNU_addr_base to the skeleton
CU DIE for DWARF5.

gcc/ChangeLog

* dwarf2out.c (dwarf2out_finish): Add .debug_addr table header for
dwarf_version >= 5.
(dwarf_AT): Handle DW_AT_addr_base.
(add_top_level_skeleton_die_attrs): Use dwarf_AT for DW_AT_addr_base.

From-SVN: r259743

gcc/ChangeLog
gcc/dwarf2out.c

index 1433190f20916cf19ef390a7a7902470e7a4ecc0..56aec8f3352818d5600f740ce69043f093365de8 100644 (file)
@@ -1,3 +1,10 @@
+2018-04-28  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf2out.c (dwarf2out_finish): Add .debug_addr table header for
+       dwarf_version >= 5.
+       (dwarf_AT): Handle DW_AT_addr_base.
+       (add_top_level_skeleton_die_attrs): Use dwarf_AT for DW_AT_addr_base.
+
 2018-04-28  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/84431
index d3d925d5279d65e55f362b3f24cb0797d0d29412..d2d4ec009e769390750a000e937a305c1a6b9788 100644 (file)
@@ -1724,6 +1724,11 @@ dwarf_AT (enum dwarf_attribute at)
        return DW_AT_GNU_dwo_name;
       break;
 
+    case DW_AT_addr_base:
+      if (dwarf_version < 5)
+       return DW_AT_GNU_addr_base;
+      break;
+
     default:
       break;
     }
@@ -11106,7 +11111,7 @@ add_top_level_skeleton_die_attrs (dw_die_ref die)
   if (comp_dir != NULL)
     add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
   add_AT_pubnames (die);
-  add_AT_lineptr (die, DW_AT_GNU_addr_base, debug_addr_section_label);
+  add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
 }
 
 /* Output skeleton debug sections that point to the dwo file.  */
@@ -31293,6 +31298,24 @@ dwarf2out_finish (const char *)
        }
 
       switch_to_section (debug_addr_section);
+      /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
+        which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
+        before DWARF5, didn't have a header for .debug_addr units.
+        DWARF5 specifies a small header when address tables are used.  */
+      if (dwarf_version >= 5)
+       {
+         unsigned long addrs_length
+           = addr_index_table->elements () * DWARF2_ADDR_SIZE + 4;
+
+         if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+           dw2_asm_output_data (4, 0xffffffff,
+                                "Escape value for 64-bit DWARF extension");
+         dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length,
+                              "Length of Address Unit");
+         dw2_asm_output_data (2, 5, "DWARF addr version");
+         dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
+         dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
+       }
       ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
       output_addr_table ();
     }