]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: don't generate DW_AT_type attr for unsafe.Pointer to match gcc behavior
authorShenghou Ma <minux.ma@gmail.com>
Thu, 21 Mar 2013 19:58:35 +0000 (03:58 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 21 Mar 2013 19:58:35 +0000 (03:58 +0800)
gcc generates only attr DW_AT_byte_size for DW_TAG_pointer_type of "void *",
but we used to also generate DW_AT_type pointing to imaginary unspecified
type "void", which confuses some gdb.
This change makes old Apple gdb 6.x (specifically, Apple version gdb-1515)
accepts our binary without issue like this:
(gdb) b 'main.main'
Die: DW_TAG_unspecified_type (abbrev = 10, offset = 47079)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_string) string: "void"
Dwarf Error: Cannot find type of die [in module /Users/minux/go/go2.hg/bin/go]

Special thanks to Russ Cox for pointing out the problem in comment #6 of
CL 7891044.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7744051

src/cmd/ld/dwarf.c

index 3f55340560adf0eee3aecf057f03df5b97496ac5..4bf788e64e6647621fa8372e854281a7e0ba2ffb 100644 (file)
@@ -154,6 +154,7 @@ enum
        DW_ABRV_IFACETYPE,
        DW_ABRV_MAPTYPE,
        DW_ABRV_PTRTYPE,
+       DW_ABRV_BARE_PTRTYPE, // only for void*, no DW_AT_type attr to please gdb 6.
        DW_ABRV_SLICETYPE,
        DW_ABRV_STRINGTYPE,
        DW_ABRV_STRUCTTYPE,
@@ -307,6 +308,12 @@ static struct DWAbbrev {
                DW_AT_type,     DW_FORM_ref_addr,
                0, 0
        },
+       /* BARE_PTRTYPE */
+       {
+               DW_TAG_pointer_type, DW_CHILDREN_no,
+               DW_AT_name,     DW_FORM_string,
+               0, 0
+       },
 
        /* SLICETYPE */
        {
@@ -717,7 +724,7 @@ putattrs(int abbrev, DWAttr* attr)
                                attrs[af->attr]->value,
                                attrs[af->attr]->data);
                else
-                       putattr(abbrev, af->form, 0, 0, 0);
+                       putattr(abbrev, af->form, 0, 0, nil);
 }
 
 static void putdie(DWDie* die);
@@ -1009,8 +1016,7 @@ defgotype(Sym *gotype)
                break;
 
        case KindUnsafePointer:
-               die = newdie(&dwtypes, DW_ABRV_PTRTYPE, name);
-               newrefattr(die, DW_AT_type, find(&dwtypes, "void"));
+               die = newdie(&dwtypes, DW_ABRV_BARE_PTRTYPE, name);
                break;
 
        default:
@@ -2126,8 +2132,7 @@ dwarfemitdebugsections(void)
        // Some types that must exist to define other ones.
        newdie(&dwtypes, DW_ABRV_NULLTYPE, "<unspecified>");
        newdie(&dwtypes, DW_ABRV_NULLTYPE, "void");
-       newrefattr(newdie(&dwtypes, DW_ABRV_PTRTYPE, "unsafe.Pointer"),
-               DW_AT_type, find(&dwtypes, "void"));
+       newdie(&dwtypes, DW_ABRV_BARE_PTRTYPE, "unsafe.Pointer");
        die = newdie(&dwtypes, DW_ABRV_BASETYPE, "uintptr");  // needed for array size
        newattr(die, DW_AT_encoding,  DW_CLS_CONSTANT, DW_ATE_unsigned, 0);
        newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, PtrSize, 0);