From cf42b785b701e48260e1b4785e270fe81e2e1bb2 Mon Sep 17 00:00:00 2001 From: matloob Date: Mon, 25 Aug 2025 17:16:05 -0400 Subject: [PATCH] cmd/cgo: run recordTypes for each of the debugs at the end of Translate Save the debug information in a slice and then process all of them at the end of the loop. For #75167 Change-Id: I6a6a6964dffa784b0aa776334562333ecf247023 Reviewed-on: https://go-review.googlesource.com/c/go/+/699019 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Matloob Auto-Submit: Michael Matloob Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Pratt --- src/cmd/cgo/gcc.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index c1530b9f154..aa418af93b8 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -192,9 +192,7 @@ func (p *Package) Translate(f *File) { cref.Name.C = cname(cref.Name.Go) } - var conv typeConv - conv.Init(p.PtrSize, p.IntSize) - + var debugs []*debug // debug data from iterations of gccDebug ft := fileTypedefs{typedefs: make(map[string]bool)} numTypedefs := -1 for len(ft.typedefs) > numTypedefs { @@ -213,8 +211,7 @@ func (p *Package) Translate(f *File) { } needType := p.guessKinds(f) if len(needType) > 0 { - d := p.loadDWARF(f, &ft, needType) - p.recordTypes(f, d, &conv) + debugs = append(debugs, p.loadDWARF(f, &ft, needType)) } // In godefs mode we're OK with the typedefs, which @@ -224,6 +221,12 @@ func (p *Package) Translate(f *File) { break } } + + var conv typeConv + conv.Init(p.PtrSize, p.IntSize) + for _, d := range debugs { + p.recordTypes(f, d, &conv) + } p.prepareNames(f) if p.rewriteCalls(f) { // Add `import _cgo_unsafe "unsafe"` after the package statement.