]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: split loadDWARF into two parts
authormatloob <matloob@golang.org>
Mon, 25 Aug 2025 21:07:41 +0000 (17:07 -0400)
committerMichael Matloob <matloob@google.com>
Fri, 29 Aug 2025 23:58:58 +0000 (16:58 -0700)
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 <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/cgo/gcc.go

index 716db08d2bccf69a50404383725f97479493ab14..c1530b9f15489874e037e29bce36d3f6a32daefa 100644 (file)
@@ -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" {