Commit 02c1d8a1 authored by Alex Brainman's avatar Alex Brainman

cmd/link/internal/ld: remove goto from ldpe.go

Updates #15345

Change-Id: I447d133512e99a9900928a910e161a85db6e8b75
Reviewed-on: https://go-review.googlesource.com/31792Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c0e2318f
...@@ -117,9 +117,14 @@ func (f *peBiobuf) ReadAt(p []byte, off int64) (int, error) { ...@@ -117,9 +117,14 @@ func (f *peBiobuf) ReadAt(p []byte, off int64) (int, error) {
return n, nil return n, nil
} }
// TODO(brainman): remove 'goto bad' everywhere inside ldpe
func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
err := ldpeError(ctxt, input, pkg, length, pn)
if err != nil {
Errorf(nil, "%s: malformed pe file: %v", pn, err)
}
}
func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) error {
if ctxt.Debugvlog != 0 { if ctxt.Debugvlog != 0 {
ctxt.Logf("%5.2f ldpe %s\n", obj.Cputime(), pn) ctxt.Logf("%5.2f ldpe %s\n", obj.Cputime(), pn)
} }
...@@ -129,8 +134,6 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -129,8 +134,6 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
sectsyms := make(map[*pe.Section]*Symbol) sectsyms := make(map[*pe.Section]*Symbol)
sectdata := make(map[*pe.Section][]byte) sectdata := make(map[*pe.Section][]byte)
var err error
// Some input files are archives containing multiple of // Some input files are archives containing multiple of
// object files, and pe.NewFile seeks to the start of // object files, and pe.NewFile seeks to the start of
// input file and get confused. Create section reader // input file and get confused. Create section reader
...@@ -140,7 +143,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -140,7 +143,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
// TODO: replace pe.NewFile with pe.Load (grep for "add Load function" in debug/pe for details) // TODO: replace pe.NewFile with pe.Load (grep for "add Load function" in debug/pe for details)
f, err := pe.NewFile(sr) f, err := pe.NewFile(sr)
if err != nil { if err != nil {
goto bad return err
} }
defer f.Close() defer f.Close()
...@@ -158,10 +161,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -158,10 +161,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
continue continue
} }
data, err2 := sect.Data() data, err := sect.Data()
if err2 != nil { if err != nil {
err = err2 return err
goto bad
} }
sectdata[sect] = data sectdata[sect] = data
...@@ -182,8 +184,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -182,8 +184,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
s.Type = obj.STEXT s.Type = obj.STEXT
default: default:
err = fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name) return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name)
goto bad
} }
s.P = data s.P = data
...@@ -215,22 +216,19 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -215,22 +216,19 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
for j, r := range rsect.Relocs { for j, r := range rsect.Relocs {
rp := &rs[j] rp := &rs[j]
if int(r.SymbolTableIndex) >= len(f.COFFSymbols) { if int(r.SymbolTableIndex) >= len(f.COFFSymbols) {
err = fmt.Errorf("relocation number %d symbol index idx=%d cannot be large then number of symbols %d", j, r.SymbolTableIndex, len(f.COFFSymbols)) return fmt.Errorf("relocation number %d symbol index idx=%d cannot be large then number of symbols %d", j, r.SymbolTableIndex, len(f.COFFSymbols))
goto bad
} }
pesym := &f.COFFSymbols[r.SymbolTableIndex] pesym := &f.COFFSymbols[r.SymbolTableIndex]
gosym, err2 := readpesym(ctxt, f, pesym, sectsyms, localSymVersion) gosym, err := readpesym(ctxt, f, pesym, sectsyms, localSymVersion)
if err2 != nil { if err != nil {
err = err2 return err
goto bad
} }
if gosym == nil { if gosym == nil {
name, err2 := pesym.FullName(f.StringTable) name, err := pesym.FullName(f.StringTable)
if err2 != nil { if err != nil {
name = string(pesym.Name[:]) name = string(pesym.Name[:])
} }
err = fmt.Errorf("reloc of invalid sym %s idx=%d type=%d", name, r.SymbolTableIndex, pesym.Type) return fmt.Errorf("reloc of invalid sym %s idx=%d type=%d", name, r.SymbolTableIndex, pesym.Type)
goto bad
} }
rp.Sym = gosym rp.Sym = gosym
...@@ -284,10 +282,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -284,10 +282,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
numaux = int(pesym.NumberOfAuxSymbols) numaux = int(pesym.NumberOfAuxSymbols)
name, err2 := pesym.FullName(f.StringTable) name, err := pesym.FullName(f.StringTable)
if err2 != nil { if err != nil {
err = err2 return err
goto bad
} }
if name == "" { if name == "" {
continue continue
...@@ -309,10 +306,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -309,10 +306,9 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
} }
} }
s, err2 := readpesym(ctxt, f, pesym, sectsyms, localSymVersion) s, err := readpesym(ctxt, f, pesym, sectsyms, localSymVersion)
if err2 != nil { if err != nil {
err = err2 return err
goto bad
} }
if pesym.SectionNumber == 0 { // extern if pesym.SectionNumber == 0 { // extern
...@@ -335,7 +331,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -335,7 +331,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
} }
if sect == nil { if sect == nil {
return return nil
} }
if s.Outer != nil { if s.Outer != nil {
...@@ -386,10 +382,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) { ...@@ -386,10 +382,7 @@ func ldpe(ctxt *Link, input *bio.Reader, pkg string, length int64, pn string) {
} }
} }
return return nil
bad:
Errorf(nil, "%s: malformed pe file: %v", pn, err)
} }
func issect(s *pe.COFFSymbol) bool { func issect(s *pe.COFFSymbol) bool {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment