From: matloob Date: Mon, 25 Aug 2025 21:07:41 +0000 (-0400) Subject: cmd/cgo: split loadDWARF into two parts X-Git-Tag: go1.26rc1~988 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8377adafc548a0d9dab831477923d25ce4b10710;p=gostls13.git cmd/cgo: split loadDWARF into two parts The first part runs gcc to get the debug information, and the second part processes the debug information. The first part doesn't touch the global and package level information that's computed so we can run it earlier and concurrently in a later CL. For #75167 Change-Id: I6a6a6964769a47792892066d06c16f239f532858 Reviewed-on: https://go-review.googlesource.com/c/go/+/699018 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 716db08d2b..c1530b9f15 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -213,7 +213,8 @@ func (p *Package) Translate(f *File) { } needType := p.guessKinds(f) if len(needType) > 0 { - p.loadDWARF(f, &ft, &conv, needType) + d := p.loadDWARF(f, &ft, needType) + p.recordTypes(f, d, &conv) } // In godefs mode we're OK with the typedefs, which @@ -522,7 +523,7 @@ func (p *Package) guessKinds(f *File) []*Name { // loadDWARF parses the DWARF debug information generated // by gcc to learn the details of the constants, variables, and types // being referred to as C.xxx. -func (p *Package) loadDWARF(f *File, ft *fileTypedefs, conv *typeConv, names []*Name) { +func (p *Package) loadDWARF(f *File, ft *fileTypedefs, names []*Name) *debug { // Extract the types from the DWARF section of an object // from a well-formed C program. Gcc only generates DWARF info // for symbols in the object file, so it is not enough to print the @@ -643,6 +644,21 @@ func (p *Package) loadDWARF(f *File, ft *fileTypedefs, conv *typeConv, names []* } } + return &debug{names, types, ints, floats, strs} +} + +// debug is the data extracted by running an iteration of loadDWARF on a file. +type debug struct { + names []*Name + types []dwarf.Type + ints []int64 + floats []float64 + strs []string +} + +func (p *Package) recordTypes(f *File, data *debug, conv *typeConv) { + names, types, ints, floats, strs := data.names, data.types, data.ints, data.floats, data.strs + // Record types and typedef information. for i, n := range names { if strings.HasSuffix(n.Go, "GetTypeID") && types[i].String() == "func() CFTypeID" {