@@ -382,16 +382,23 @@ func (b *Builder) NewObjdir() string {
382
382
func readpkglist (shlibpath string ) (pkgs []* load.Package ) {
383
383
var stk load.ImportStack
384
384
if cfg .BuildToolchainName == "gccgo" {
385
- f , _ := elf .Open (shlibpath )
385
+ f , err := elf .Open (shlibpath )
386
+ if err != nil {
387
+ base .Fatal (fmt .Errorf ("failed to open shared library: %v" , err ))
388
+ }
386
389
sect := f .Section (".go_export" )
387
- data , _ := sect .Data ()
388
- scanner := bufio .NewScanner (bytes .NewBuffer (data ))
389
- for scanner .Scan () {
390
- t := scanner .Text ()
391
- var found bool
392
- if t , found = strings .CutPrefix (t , "pkgpath " ); found {
393
- t = strings .TrimSuffix (t , ";" )
394
- pkgs = append (pkgs , load .LoadPackageWithFlags (t , base .Cwd (), & stk , nil , 0 ))
390
+ if sect == nil {
391
+ base .Fatal (fmt .Errorf ("%s: missing .go_export section" , shlibpath ))
392
+ }
393
+ data , err := sect .Data ()
394
+ if err != nil {
395
+ base .Fatal (fmt .Errorf ("%s: failed to read .go_export section: %v" , shlibpath , err ))
396
+ }
397
+ pkgpath := []byte ("pkgpath " )
398
+ for _ , line := range bytes .Split (data , []byte {'\n' }) {
399
+ if path , found := bytes .CutPrefix (line , pkgpath ); found {
400
+ path = bytes .TrimSuffix (path , []byte {';' })
401
+ pkgs = append (pkgs , load .LoadPackageWithFlags (string (path ), base .Cwd (), & stk , nil , 0 ))
395
402
}
396
403
}
397
404
} else {
0 commit comments