mirror of
https://github.com/golang/go
synced 2024-11-11 18:21:40 -07:00
cmd/go: check for errors reading gccgo package list
Previously if there was something invalid about the package list cmd/go would crash rather than reporting a useful error. For #60798 Change-Id: I502facf41442ab49217405b5b1874fff52a6d416 Reviewed-on: https://go-review.googlesource.com/c/go/+/503496 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
b01cd41b46
commit
da94586aa3
@ -382,16 +382,23 @@ func (b *Builder) NewObjdir() string {
|
||||
func readpkglist(shlibpath string) (pkgs []*load.Package) {
|
||||
var stk load.ImportStack
|
||||
if cfg.BuildToolchainName == "gccgo" {
|
||||
f, _ := elf.Open(shlibpath)
|
||||
f, err := elf.Open(shlibpath)
|
||||
if err != nil {
|
||||
base.Fatal(fmt.Errorf("failed to open shared library: %v", err))
|
||||
}
|
||||
sect := f.Section(".go_export")
|
||||
data, _ := sect.Data()
|
||||
scanner := bufio.NewScanner(bytes.NewBuffer(data))
|
||||
for scanner.Scan() {
|
||||
t := scanner.Text()
|
||||
var found bool
|
||||
if t, found = strings.CutPrefix(t, "pkgpath "); found {
|
||||
t = strings.TrimSuffix(t, ";")
|
||||
pkgs = append(pkgs, load.LoadPackageWithFlags(t, base.Cwd(), &stk, nil, 0))
|
||||
if sect == nil {
|
||||
base.Fatal(fmt.Errorf("%s: missing .go_export section", shlibpath))
|
||||
}
|
||||
data, err := sect.Data()
|
||||
if err != nil {
|
||||
base.Fatal(fmt.Errorf("%s: failed to read .go_export section: %v", shlibpath, err))
|
||||
}
|
||||
pkgpath := []byte("pkgpath ")
|
||||
for _, line := range bytes.Split(data, []byte{'\n'}) {
|
||||
if path, found := bytes.CutPrefix(line, pkgpath); found {
|
||||
path = bytes.TrimSuffix(path, []byte{';'})
|
||||
pkgs = append(pkgs, load.LoadPackageWithFlags(string(path), base.Cwd(), &stk, nil, 0))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user