[PATCH] DWARF support for AIX v3

David Edelsohn dje.gcc@gmail.com
Mon Sep 21 16:23:00 GMT 2015


Appended is a patch to support DWARF on AIX and works with GDB and AIX
assembler.  The AIX assembler prepends the CU length to the section
and does not want the compiler to provide it, so I need to disable
those parts of dwarf2out.c.  I know it's ugly, but, on the upside,
this eventually allows GCC to deprecate Stabs, which I think is worth
the pain.

I discovered that -g3 emits the debug_macros section, which AIX also
does not like, so I disable that section as well.  As I mentioned in
v2, I moved the calculation of aranges_length to its one use in the
output function instead of calculating it early to avoid an unused
function argument.

I also switched to XCOFF_DEBUGGING_INFO as the macro to test in
dwarf2out.c.  I think a target hook or testing that DWARF section
names have not been overridden to NULL is overkill. Suggestions
welcome, but any solution that disables arbitrary portions of
dwarf2out.c is going to be ugly. I doubt that any other system,
especially ones based on ELF file format, would ever do this.

With a few tweaks to the testsuite, this passes GCC dwarf2 tests.

Thanks, David

        * dwarf2out.c (size_of_pubnames): Don't define on AIX.
        (size_of_aranges): Don't define on AIX.
        (output_compilation_unit_header): Don't output length on AIX.
        (output_pubnames): Don't output length on AIX.
        (output_aranges): Delete argument. Compute length locally. Don't
        output length on AIX.
        (output_line_info): Don't output length on AIX.
        (dwarf2out_finish): Don't output location lists on AIX.
        Don't compute aranges_length. Don't output macros section.
        * config/rs6000/rs6000.c (rs6000_xcoff_debug_unwind_info):
        New.
        (rs6000_xcoff_asm_named_section): Emit .dwsect pseudo-op
        for SECTION_DEBUG.
        (rs6000_xcoff_declare_function_name): Emit different
        .function pseudo-op when DWARF2_DEBUG.
        * config/rs6000/xcoff.h (TARGET_DEBUG_UNWIND_INFO):
        Redefine.
        * config/rs6000/aix71.h (DWARF2_DEBUGGING_INFO): Define.
        (PREFERRED_DEBUGGING_TYPE): Define.
        (DEBUG_INFO_SECTION): Define.
        (DEBUG_ABBREV_SECTION): Define.
        (DEBUG_ARANGES_SECTION): Define.
        (DEBUG_LINE_SECTION): Define.
        (DEBUG_PUBNAMES_SECTION): Define.
        (DEBUG_PUBTYPES_SECTION): Define.
        (DEBUG_STR_SECTION): Define.
        (DEBUG_RANGES_SECTION): Define.

Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 227959)
+++ dwarf2out.c (working copy)
@@ -3185,8 +3185,10 @@ static void calc_base_type_die_sizes (void);
 static void mark_dies (dw_die_ref);
 static void unmark_dies (dw_die_ref);
 static void unmark_all_dies (dw_die_ref);
+#ifndef XCOFF_DEBUGGING_INFO
 static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
 static unsigned long size_of_aranges (void);
+#endif
 static enum dwarf_form value_format (dw_attr_node *);
 static void output_value_format (dw_attr_node *);
 static void output_abbrev_section (void);
@@ -3202,7 +3204,7 @@ static void add_enumerator_pubname (const char *,
 static void add_pubname_string (const char *, dw_die_ref);
 static void add_pubtype (tree, dw_die_ref);
 static void output_pubnames (vec<pubname_entry, va_gc> *);
-static void output_aranges (unsigned long);
+static void output_aranges (void);
 static unsigned int add_ranges_num (int);
 static unsigned int add_ranges (const_tree);
 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
@@ -8387,6 +8389,7 @@ include_pubname_in_output (vec<pubname_entry, va_g
           || !flag_eliminate_unused_debug_types);
 }

+#ifndef XCOFF_DEBUGGING_INFO
 /* Return the size of the .debug_pubnames or .debug_pubtypes table
    generated for the compilation unit.  */

@@ -8441,6 +8444,7 @@ size_of_aranges (void)
   size += 2 * DWARF2_ADDR_SIZE;
   return size;
 }
+#endif
 ^L
 /* Select the encoding of an attribute value.  */

@@ -9198,12 +9202,14 @@ output_compilation_unit_header (void)
      DWARFv5 draft DIE tags in DWARFv4 format.  */
   int ver = dwarf_version < 5 ? dwarf_version : 4;

+#ifndef XCOFF_DEBUGGING_INFO
   if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
     dw2_asm_output_data (4, 0xffffffff,
       "Initial length escape value indicating 64-bit DWARF extension");
   dw2_asm_output_data (DWARF_OFFSET_SIZE,
                       next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
                       "Length of Compilation Unit Info");
+#endif
   dw2_asm_output_data (2, ver, "DWARF version number");
   dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
                         debug_abbrev_section,
@@ -9630,13 +9636,16 @@ static void
 output_pubnames (vec<pubname_entry, va_gc> *names)
 {
   unsigned i;
-  unsigned long pubnames_length = size_of_pubnames (names);
   pubname_entry *pub;

+#ifndef XCOFF_DEBUGGING_INFO
+  unsigned long pubnames_length = size_of_pubnames (names);
+
   if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
     dw2_asm_output_data (4, 0xffffffff,
       "Initial length escape value indicating 64-bit DWARF extension");
   dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, "Pub Info Length");
+#endif

   /* Version number for pubnames/pubtypes is independent of dwarf version.  */
   dw2_asm_output_data (2, 2, "DWARF Version");
@@ -9706,15 +9715,19 @@ output_pubtables (void)
    text section generated for this compilation unit.  */

 static void
-output_aranges (unsigned long aranges_length)
+output_aranges (void)
 {
   unsigned i;

-  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+#ifndef XCOFF_DEBUGGING_INFO
+  unsigned long aranges_length = size_of_aranges ();
+
+if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
     dw2_asm_output_data (4, 0xffffffff,
       "Initial length escape value indicating 64-bit DWARF extension");
   dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
                       "Length of Address Ranges Info");
+#endif
   /* Version number for aranges is still 2, even up to DWARF5.  */
   dw2_asm_output_data (2, 2, "DWARF Version");
   if (dwarf_split_debug_info)
@@ -10398,11 +10411,13 @@ output_line_info (bool prologue_only)
   ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);

+#ifndef XCOFF_DEBUGGING_INFO
   if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
     dw2_asm_output_data (4, 0xffffffff,
       "Initial length escape value indicating 64-bit DWARF extension");
   dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
                        "Length of Source Line Info");
+#endif
   ASM_OUTPUT_LABEL (asm_out_file, l1);

   dw2_asm_output_data (2, ver, "DWARF Version");
@@ -25486,6 +25501,7 @@ dwarf2out_finish (const char *filename)
       output_abbrev_section ();
     }

+#ifndef XCOFF_DEBUGGING_INFO
   /* Output location list section if necessary.  */
   if (have_location_lists)
     {
@@ -25494,6 +25510,7 @@ dwarf2out_finish (const char *filename)
       ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
       output_location_lists (comp_unit_die ());
     }
+#endif

   output_pubtables ();

@@ -25504,10 +25521,8 @@ dwarf2out_finish (const char *filename)
      generate a table that would have contained data.  */
   if (info_section_emitted)
     {
-      unsigned long aranges_length = size_of_aranges ();
-
       switch_to_section (debug_aranges_section);
-      output_aranges (aranges_length);
+      output_aranges ();
     }

   /* Output ranges section if necessary.  */
@@ -25518,6 +25533,7 @@ dwarf2out_finish (const char *filename)
       output_ranges ();
     }

+#ifndef XCOFF_DEBUGGING_INFO
   /* Have to end the macro section.  */
   if (have_macinfo)
     {
@@ -25526,6 +25542,7 @@ dwarf2out_finish (const char *filename)
       output_macinfo ();
       dw2_asm_output_data (1, 0, "End compilation unit");
     }
+#endif

   /* Output the source line correspondence table.  We must do this
      even if there is no line information.  Otherwise, on an empty
Index: config/rs6000/rs6000.c
===================================================================
--- config/rs6000/rs6000.c      (revision 227937)
+++ config/rs6000/rs6000.c      (working copy)
@@ -30684,6 +30684,12 @@
 #endif

 #if TARGET_XCOFF
+static enum unwind_info_type
+rs6000_xcoff_debug_unwind_info (void)
+{
+  return UI_NONE;
+}
+
 static void
 rs6000_xcoff_asm_output_anchor (rtx symbol)
 {
@@ -30805,6 +30811,11 @@
   int smclass;
   static const char * const suffix[4] = { "PR", "RO", "RW", "TL" };

+  if (flags & SECTION_DEBUG)
+    {
+      fprintf (asm_out_file, "\t.dwsect %s\n", name);
+      return;
+    }
   if (flags & SECTION_CODE)
     smclass = 0;
   else if (flags & SECTION_TLS)
@@ -31140,8 +31151,16 @@
   fputs (":\n", file);
   data.function_descriptor = true;
   symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, &
data, true);
-  if (write_symbols != NO_DEBUG && !DECL_IGNORED_P (decl))
-    xcoffout_declare_function (file, decl, buffer);
+  if (!DECL_IGNORED_P (decl))
+    {
+      if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
+       xcoffout_declare_function (file, decl, buffer);
+      else if (write_symbols == DWARF2_DEBUG)
+       {
+         name = (*targetm.strip_name_encoding) (name);
+         fprintf (file, "\t.function .%s,.%s,2,0\n", name, name);
+       }
+    }
   return;
 }

Index: config/rs6000/xcoff.h
===================================================================
--- config/rs6000/xcoff.h       (revision 227937)
+++ config/rs6000/xcoff.h       (working copy)
@@ -86,6 +86,8 @@
               || (SCALAR_FLOAT_MODE_P (GET_MODE (X))                   \
                   && ! TARGET_NO_FP_IN_TOC)))))

+#undef TARGET_DEBUG_UNWIND_INFO
+#define TARGET_DEBUG_UNWIND_INFO  rs6000_xcoff_debug_unwind_info
 #define TARGET_ASM_OUTPUT_ANCHOR  rs6000_xcoff_asm_output_anchor
 #define TARGET_ASM_GLOBALIZE_LABEL  rs6000_xcoff_asm_globalize_label
 #define TARGET_ASM_INIT_SECTIONS  rs6000_xcoff_asm_init_sections
Index: config/rs6000/aix71.h
===================================================================
+/* AIX 7.1 supports DWARF debugging, but XCOFF remains the default.  */
+#define DWARF2_DEBUGGING_INFO 1
+#define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
+#define DEBUG_INFO_SECTION      "0x10000"
+#define DEBUG_ABBREV_SECTION    "0x60000"
+#define DEBUG_ARANGES_SECTION   "0x50000"
+#define DEBUG_LINE_SECTION      "0x20000"
+#define DEBUG_PUBNAMES_SECTION  "0x30000"
+#define DEBUG_PUBTYPES_SECTION  "0x40000"
+#define DEBUG_STR_SECTION       "0x70000"
+#define DEBUG_RANGES_SECTION    "0x80000"



More information about the Gcc-patches mailing list