Skip to content

Commit 8003858

Browse files
aarzilligopherbot
authored andcommitted
cmd/compile: export to DWARF types only referenced through interfaces
Delve and viewcore use DWARF type DIEs to display and explore the runtime value of interface variables. This has always been slightly problematic since the runtime type of an interface variable might only be reachable through interfaces and thus be missing from debug_info (see issue golang#46670). Prior to commit f4de2ec this was not a severe problem since a struct literal caused the allocation of a struct into an autotemp variable, which was then used by dwarfgen to make sure that the DIE for that type would be generated. After f4de2ec such autotemps are no longer being generated and go1.25.0 ends up having many more instances of interfaces with unreadable runtime type (go-delve/delve#4080). This commit fixes this problem by scanning the relocation of the function symbol and adding to the function's DIE symbol references to all types used by the function to create interfaces. Fixes go-delve/delve#4080 Updates golang#46670 Change-Id: I3e9db1c0d1662905373239816a72604ac533b09e Reviewed-on: https://go-review.googlesource.com/c/go/+/696955 Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Florian Lehner <[email protected]>
1 parent 91e76a5 commit 8003858

File tree

1 file changed

+15
-0
lines changed
  • src/cmd/compile/internal/dwarfgen

1 file changed

+15
-0
lines changed

src/cmd/compile/internal/dwarfgen/dwarf.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,29 @@ func Info(ctxt *obj.Link, fnsym *obj.LSym, infosym *obj.LSym, curfn obj.Func) (s
128128
// already referenced by a dwarf var, attach an R_USETYPE relocation to
129129
// the function symbol to insure that the type included in DWARF
130130
// processing during linking.
131+
// Do the same with R_USEIFACE relocations from the function symbol for the
132+
// same reason.
133+
// All these R_USETYPE relocations are only looked at if the function
134+
// survives deadcode elimination in the linker.
131135
typesyms := []*obj.LSym{}
132136
for t := range fnsym.Func().Autot {
133137
typesyms = append(typesyms, t)
134138
}
139+
for i := range fnsym.R {
140+
if fnsym.R[i].Type == objabi.R_USEIFACE && !strings.HasPrefix(fnsym.R[i].Sym.Name, "go:itab.") {
141+
// Types referenced through itab will be referenced from somewhere else
142+
typesyms = append(typesyms, fnsym.R[i].Sym)
143+
}
144+
}
135145
slices.SortFunc(typesyms, func(a, b *obj.LSym) int {
136146
return strings.Compare(a.Name, b.Name)
137147
})
148+
var lastsym *obj.LSym
138149
for _, sym := range typesyms {
150+
if sym == lastsym {
151+
continue
152+
}
153+
lastsym = sym
139154
infosym.AddRel(ctxt, obj.Reloc{Type: objabi.R_USETYPE, Sym: sym})
140155
}
141156
fnsym.Func().Autot = nil

0 commit comments

Comments
 (0)