Commit a891b916 authored by Shenghou Ma's avatar Shenghou Ma

cmd/ld: don't generate DW_AT_type attr for unsafe.Pointer to match gcc behavior

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
parent f74b4d3d
...@@ -154,6 +154,7 @@ enum ...@@ -154,6 +154,7 @@ enum
DW_ABRV_IFACETYPE, DW_ABRV_IFACETYPE,
DW_ABRV_MAPTYPE, DW_ABRV_MAPTYPE,
DW_ABRV_PTRTYPE, DW_ABRV_PTRTYPE,
DW_ABRV_BARE_PTRTYPE, // only for void*, no DW_AT_type attr to please gdb 6.
DW_ABRV_SLICETYPE, DW_ABRV_SLICETYPE,
DW_ABRV_STRINGTYPE, DW_ABRV_STRINGTYPE,
DW_ABRV_STRUCTTYPE, DW_ABRV_STRUCTTYPE,
...@@ -307,6 +308,12 @@ static struct DWAbbrev { ...@@ -307,6 +308,12 @@ static struct DWAbbrev {
DW_AT_type, DW_FORM_ref_addr, DW_AT_type, DW_FORM_ref_addr,
0, 0 0, 0
}, },
/* BARE_PTRTYPE */
{
DW_TAG_pointer_type, DW_CHILDREN_no,
DW_AT_name, DW_FORM_string,
0, 0
},
/* SLICETYPE */ /* SLICETYPE */
{ {
...@@ -717,7 +724,7 @@ putattrs(int abbrev, DWAttr* attr) ...@@ -717,7 +724,7 @@ putattrs(int abbrev, DWAttr* attr)
attrs[af->attr]->value, attrs[af->attr]->value,
attrs[af->attr]->data); attrs[af->attr]->data);
else else
putattr(abbrev, af->form, 0, 0, 0); putattr(abbrev, af->form, 0, 0, nil);
} }
static void putdie(DWDie* die); static void putdie(DWDie* die);
...@@ -1009,8 +1016,7 @@ defgotype(Sym *gotype) ...@@ -1009,8 +1016,7 @@ defgotype(Sym *gotype)
break; break;
case KindUnsafePointer: case KindUnsafePointer:
die = newdie(&dwtypes, DW_ABRV_PTRTYPE, name); die = newdie(&dwtypes, DW_ABRV_BARE_PTRTYPE, name);
newrefattr(die, DW_AT_type, find(&dwtypes, "void"));
break; break;
default: default:
...@@ -2126,8 +2132,7 @@ dwarfemitdebugsections(void) ...@@ -2126,8 +2132,7 @@ dwarfemitdebugsections(void)
// Some types that must exist to define other ones. // Some types that must exist to define other ones.
newdie(&dwtypes, DW_ABRV_NULLTYPE, "<unspecified>"); newdie(&dwtypes, DW_ABRV_NULLTYPE, "<unspecified>");
newdie(&dwtypes, DW_ABRV_NULLTYPE, "void"); newdie(&dwtypes, DW_ABRV_NULLTYPE, "void");
newrefattr(newdie(&dwtypes, DW_ABRV_PTRTYPE, "unsafe.Pointer"), newdie(&dwtypes, DW_ABRV_BARE_PTRTYPE, "unsafe.Pointer");
DW_AT_type, find(&dwtypes, "void"));
die = newdie(&dwtypes, DW_ABRV_BASETYPE, "uintptr"); // needed for array size 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_encoding, DW_CLS_CONSTANT, DW_ATE_unsigned, 0);
newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, PtrSize, 0); newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, PtrSize, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment