]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: export to DWARF types only referenced through interfaces
authorAlessandro Arzilli <alessandro.arzilli@gmail.com>
Mon, 18 Aug 2025 13:49:50 +0000 (15:49 +0200)
committerGopher Robot <gobot@golang.org>
Wed, 3 Sep 2025 22:13:15 +0000 (15:13 -0700)
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 #46670).
Prior to commit f4de2ecf 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 f4de2ecf such autotemps are no longer being generated and
go1.25.0 ends up having many more instances of interfaces with
unreadable runtime type  (https://github.com/go-delve/delve/issues/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 #46670

Change-Id: I3e9db1c0d1662905373239816a72604ac533b09e
Reviewed-on: https://go-review.googlesource.com/c/go/+/696955
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Than McIntosh <thanm@golang.org>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
src/cmd/compile/internal/dwarfgen/dwarf.go

index 6ab39d2aaad1cf8708c13af0a12406f8baeee3aa..9d975e0bc1ac7d2d8865b87933df2028d50d0522 100644 (file)
@@ -128,14 +128,29 @@ func Info(ctxt *obj.Link, fnsym *obj.LSym, infosym *obj.LSym, curfn obj.Func) (s
        // already referenced by a dwarf var, attach an R_USETYPE relocation to
        // the function symbol to insure that the type included in DWARF
        // processing during linking.
+       // Do the same with R_USEIFACE relocations from the function symbol for the
+       // same reason.
+       // All these R_USETYPE relocations are only looked at if the function
+       // survives deadcode elimination in the linker.
        typesyms := []*obj.LSym{}
        for t := range fnsym.Func().Autot {
                typesyms = append(typesyms, t)
        }
+       for i := range fnsym.R {
+               if fnsym.R[i].Type == objabi.R_USEIFACE && !strings.HasPrefix(fnsym.R[i].Sym.Name, "go:itab.") {
+                       // Types referenced through itab will be referenced from somewhere else
+                       typesyms = append(typesyms, fnsym.R[i].Sym)
+               }
+       }
        slices.SortFunc(typesyms, func(a, b *obj.LSym) int {
                return strings.Compare(a.Name, b.Name)
        })
+       var lastsym *obj.LSym
        for _, sym := range typesyms {
+               if sym == lastsym {
+                       continue
+               }
+               lastsym = sym
                infosym.AddRel(ctxt, obj.Reloc{Type: objabi.R_USETYPE, Sym: sym})
        }
        fnsym.Func().Autot = nil