Skip to content

Commit 8377ada

Browse files
committed
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 golang#75167 Change-Id: I6a6a6964769a47792892066d06c16f239f532858 Reviewed-on: https://go-review.googlesource.com/c/go/+/699018 Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent a7d9d5a commit 8377ada

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/cmd/cgo/gcc.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ func (p *Package) Translate(f *File) {
213213
}
214214
needType := p.guessKinds(f)
215215
if len(needType) > 0 {
216-
p.loadDWARF(f, &ft, &conv, needType)
216+
d := p.loadDWARF(f, &ft, needType)
217+
p.recordTypes(f, d, &conv)
217218
}
218219

219220
// In godefs mode we're OK with the typedefs, which
@@ -522,7 +523,7 @@ func (p *Package) guessKinds(f *File) []*Name {
522523
// loadDWARF parses the DWARF debug information generated
523524
// by gcc to learn the details of the constants, variables, and types
524525
// being referred to as C.xxx.
525-
func (p *Package) loadDWARF(f *File, ft *fileTypedefs, conv *typeConv, names []*Name) {
526+
func (p *Package) loadDWARF(f *File, ft *fileTypedefs, names []*Name) *debug {
526527
// Extract the types from the DWARF section of an object
527528
// from a well-formed C program. Gcc only generates DWARF info
528529
// 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 []*
643644
}
644645
}
645646

647+
return &debug{names, types, ints, floats, strs}
648+
}
649+
650+
// debug is the data extracted by running an iteration of loadDWARF on a file.
651+
type debug struct {
652+
names []*Name
653+
types []dwarf.Type
654+
ints []int64
655+
floats []float64
656+
strs []string
657+
}
658+
659+
func (p *Package) recordTypes(f *File, data *debug, conv *typeConv) {
660+
names, types, ints, floats, strs := data.names, data.types, data.ints, data.floats, data.strs
661+
646662
// Record types and typedef information.
647663
for i, n := range names {
648664
if strings.HasSuffix(n.Go, "GetTypeID") && types[i].String() == "func() CFTypeID" {

0 commit comments

Comments
 (0)