aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/link/internal')
-rw-r--r--src/cmd/link/internal/ld/dwarf.go16
-rw-r--r--src/cmd/link/internal/ld/dwarf_test.go23
-rw-r--r--src/cmd/link/internal/loader/loader.go9
3 files changed, 45 insertions, 3 deletions
diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go
index 839609339f..d72846a691 100644
--- a/src/cmd/link/internal/ld/dwarf.go
+++ b/src/cmd/link/internal/ld/dwarf.go
@@ -1890,6 +1890,8 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
// global variables. For each global of this sort, locate
// the corresponding compiler-generated DIE symbol and tack
// it onto the list associated with the unit.
+ // Also looks for dictionary symbols and generates DIE symbols for each
+ // type they reference.
for idx := loader.Sym(1); idx < loader.Sym(d.ldr.NDef()); idx++ {
if !d.ldr.AttrReachable(idx) ||
d.ldr.AttrNotInSymbolTable(idx) ||
@@ -1903,9 +1905,21 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
default:
continue
}
- // Skip things with no type
+ // Skip things with no type, unless it's a dictionary
gt := d.ldr.SymGoType(idx)
if gt == 0 {
+ if t == sym.SRODATA {
+ if d.ldr.IsDict(idx) {
+ // This is a dictionary, make sure that all types referenced by this dictionary are reachable
+ relocs := d.ldr.Relocs(idx)
+ for i := 0; i < relocs.Count(); i++ {
+ reloc := relocs.At(i)
+ if reloc.Type() == objabi.R_USEIFACE {
+ d.defgotype(reloc.Sym())
+ }
+ }
+ }
+ }
continue
}
// Skip file local symbols (this includes static tmps, stack
diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go
index 3d112d97a4..db9002491e 100644
--- a/src/cmd/link/internal/ld/dwarf_test.go
+++ b/src/cmd/link/internal/ld/dwarf_test.go
@@ -1749,7 +1749,9 @@ func main() {
}
func TestDictIndex(t *testing.T) {
- // Check that variables with a parametric type have a dictionary index attribute
+ // Check that variables with a parametric type have a dictionary index
+ // attribute and that types that are only referenced through dictionaries
+ // have DIEs.
testenv.MustHaveGoBuild(t)
if runtime.GOOS == "plan9" {
@@ -1765,6 +1767,8 @@ package main
import "fmt"
+type CustomInt int
+
func testfn[T any](arg T) {
var mapvar = make(map[int]T)
mapvar[0] = arg
@@ -1772,7 +1776,7 @@ func testfn[T any](arg T) {
}
func main() {
- testfn("test")
+ testfn(CustomInt(3))
}
`
@@ -1829,4 +1833,19 @@ func main() {
t.Errorf("could not find DW_AT_go_dict_index attribute offset %#x (%T)", off, entry.Val(intdwarf.DW_AT_go_dict_index))
}
}
+
+ rdr.Seek(0)
+ ex := examiner{}
+ if err := ex.populate(rdr); err != nil {
+ t.Fatalf("error reading DWARF: %v", err)
+ }
+ for _, typeName := range []string{"main.CustomInt", "map[int]main.CustomInt"} {
+ dies := ex.Named(typeName)
+ if len(dies) != 1 {
+ t.Errorf("wanted 1 DIE named %s, found %v", typeName, len(dies))
+ }
+ if dies[0].Val(intdwarf.DW_AT_go_runtime_type).(uint64) == 0 {
+ t.Errorf("type %s does not have DW_AT_go_runtime_type", typeName)
+ }
+ }
}
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index f144e00f37..b9a1da6f45 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -1209,6 +1209,15 @@ func (l *Loader) IsItab(i Sym) bool {
return r.Sym(li).IsItab()
}
+// Returns whether this symbol is a dictionary symbol.
+func (l *Loader) IsDict(i Sym) bool {
+ if l.IsExternal(i) {
+ return false
+ }
+ r, li := l.toLocal(i)
+ return r.Sym(li).IsDict()
+}
+
// Return whether this is a trampoline of a deferreturn call.
func (l *Loader) IsDeferReturnTramp(i Sym) bool {
return l.deferReturnTramp[i]