From a891b916bd6d284fba0349804da46ad2135e370c Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Fri, 22 Mar 2013 03:58:35 +0800 Subject: [PATCH] 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 --- src/cmd/ld/dwarf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c index 3f55340560..4bf788e64e 100644 --- a/src/cmd/ld/dwarf.c +++ b/src/cmd/ld/dwarf.c @@ -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, ""); 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); -- 2.50.0