diff --git a/src/cmd/5l/asm.go b/src/cmd/5l/asm.go index abe91fd484..d1e80b52a1 100644 --- a/src/cmd/5l/asm.go +++ b/src/cmd/5l/asm.go @@ -93,9 +93,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { return case 256 + ld.R_ARM_THM_PC22: // R_ARM_THM_CALL - ld.Diag("R_ARM_THM_CALL, are you using -marm?") - - ld.Errorexit() + ld.Exitf("R_ARM_THM_CALL, are you using -marm?") return case 256 + ld.R_ARM_GOT32: // R_ARM_GOT_BREL diff --git a/src/cmd/5l/obj.go b/src/cmd/5l/obj.go index 075f15f20c..ed462dbdf0 100644 --- a/src/cmd/5l/obj.go +++ b/src/cmd/5l/obj.go @@ -105,9 +105,7 @@ func archinit() { switch ld.HEADTYPE { default: - ld.Diag("unknown -H option") - ld.Errorexit() - fallthrough + ld.Exitf("unknown -H option: %v", ld.HEADTYPE) case ld.Hplan9: /* plan 9 */ ld.HEADR = 32 diff --git a/src/cmd/6l/obj.go b/src/cmd/6l/obj.go index a1e012bec7..2b556a2e2b 100644 --- a/src/cmd/6l/obj.go +++ b/src/cmd/6l/obj.go @@ -118,9 +118,7 @@ func archinit() { switch ld.HEADTYPE { default: - ld.Diag("unknown -H option") - ld.Errorexit() - fallthrough + ld.Exitf("unknown -H option: %v", ld.HEADTYPE) case ld.Hplan9: /* plan 9 */ ld.HEADR = 32 + 8 diff --git a/src/cmd/7l/obj.go b/src/cmd/7l/obj.go index 1e03fa8e75..13acc8f81b 100644 --- a/src/cmd/7l/obj.go +++ b/src/cmd/7l/obj.go @@ -107,9 +107,7 @@ func archinit() { switch ld.HEADTYPE { default: - ld.Diag("unknown -H option") - ld.Errorexit() - fallthrough + ld.Exitf("unknown -H option: %v", ld.HEADTYPE) case ld.Hplan9: /* plan 9 */ ld.HEADR = 32 diff --git a/src/cmd/8l/obj.go b/src/cmd/8l/obj.go index 938a77700a..a160b25b98 100644 --- a/src/cmd/8l/obj.go +++ b/src/cmd/8l/obj.go @@ -107,9 +107,7 @@ func archinit() { switch ld.HEADTYPE { default: - ld.Diag("unknown -H option") - ld.Errorexit() - fallthrough + ld.Exitf("unknown -H option: %v", ld.HEADTYPE) case ld.Hplan9: /* plan 9 */ ld.HEADR = 32 diff --git a/src/cmd/9l/obj.go b/src/cmd/9l/obj.go index 29b384a1a6..4bd6f6d65f 100644 --- a/src/cmd/9l/obj.go +++ b/src/cmd/9l/obj.go @@ -111,9 +111,7 @@ func archinit() { switch ld.HEADTYPE { default: - ld.Diag("unknown -H option") - ld.Errorexit() - fallthrough + ld.Exitf("unknown -H option: %v", ld.HEADTYPE) case ld.Hplan9: /* plan 9 */ ld.HEADR = 32 diff --git a/src/cmd/internal/ld/data.go b/src/cmd/internal/ld/data.go index 1b4f319ff9..97b962afe1 100644 --- a/src/cmd/internal/ld/data.go +++ b/src/cmd/internal/ld/data.go @@ -482,7 +482,7 @@ func relocsym(s *LSym) { // 64-bit architectures so as to be future-proof. if int32(o) < 0 && Thearch.Ptrsize > 4 && siz == 4 { Diag("non-pc-relative relocation address is too big: %#x (%#x + %#x)", uint64(o), Symaddr(r.Sym), r.Add) - Errorexit() + errorexit() } // r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call. @@ -713,7 +713,7 @@ func blk(start *LSym, addr int64, size int64) { Ctxt.Cursym = sym if sym.Value < addr { Diag("phase error: addr=%#x but sym=%#x type=%d", int64(addr), int64(sym.Value), sym.Type) - Errorexit() + errorexit() } for ; addr < sym.Value; addr++ { @@ -731,7 +731,7 @@ func blk(start *LSym, addr int64, size int64) { } if addr != sym.Value+sym.Size { Diag("phase error: addr=%#x value+size=%#x", int64(addr), int64(sym.Value)+sym.Size) - Errorexit() + errorexit() } if sym.Value+sym.Size >= eaddr { diff --git a/src/cmd/internal/ld/decodesym.go b/src/cmd/internal/ld/decodesym.go index e960f101b9..4bad549fd4 100644 --- a/src/cmd/internal/ld/decodesym.go +++ b/src/cmd/internal/ld/decodesym.go @@ -35,10 +35,10 @@ func decode_inuxi(p []byte, sz int) uint64 { return uint64(Ctxt.Arch.ByteOrder.Uint32(p)) case 8: return Ctxt.Arch.ByteOrder.Uint64(p) + default: + Exitf("dwarf: decode inuxi %d", sz) + panic("unreachable") } - Diag("dwarf: decode inuxi %d", sz) - Errorexit() - return 0 } func commonsize() int { diff --git a/src/cmd/internal/ld/dwarf.go b/src/cmd/internal/ld/dwarf.go index 8f74e7979b..8460593e80 100644 --- a/src/cmd/internal/ld/dwarf.go +++ b/src/cmd/internal/ld/dwarf.go @@ -674,13 +674,11 @@ notfound: return nil } -func find_or_diag(die *DWDie, name string) *DWDie { +func mustFind(die *DWDie, name string) *DWDie { r := find(die, name) if r == nil { - Diag("dwarf find: %s %p has no %s", getattr(die, DW_AT_name).data, die, name) - Errorexit() + Exitf("dwarf find: %s %p has no %s", getattr(die, DW_AT_name).data, die, name) } - return r } @@ -843,9 +841,7 @@ func putattr(abbrev int, form int, cls int, value int64, data interface{}) { DW_FORM_indirect: // (see Section 7.5.3) fallthrough default: - Diag("dwarf: unsupported attribute form %d / class %d", form, cls) - - Errorexit() + Exitf("dwarf: unsupported attribute form %d / class %d", form, cls) } } @@ -924,8 +920,7 @@ func newabslocexprattr(die *DWDie, addr int64, sym *LSym) { func lookup_or_diag(n string) *LSym { s := Linkrlookup(Ctxt, n, 0) if s == nil || s.Size == 0 { - Diag("dwarf: missing type: %s", n) - Errorexit() + Exitf("dwarf: missing type: %s", n) } return s @@ -961,12 +956,12 @@ func dotypedef(parent *DWDie, name string, def *DWDie) { // Define gotype, for composite ones recurse into constituents. func defgotype(gotype *LSym) *DWDie { if gotype == nil { - return find_or_diag(&dwtypes, "") + return mustFind(&dwtypes, "") } if !strings.HasPrefix(gotype.Name, "type.") { Diag("dwarf: type name doesn't start with \".type\": %s", gotype.Name) - return find_or_diag(&dwtypes, "") + return mustFind(&dwtypes, "") } name := gotype.Name[5:] // could also decode from Type.string @@ -1032,7 +1027,7 @@ func defgotype(gotype *LSym) *DWDie { // use actual length not upper bound; correct for 0-length arrays. newattr(fld, DW_AT_count, DW_CLS_CONSTANT, decodetype_arraylen(gotype), 0) - newrefattr(fld, DW_AT_type, find_or_diag(&dwtypes, "uintptr")) + newrefattr(fld, DW_AT_type, mustFind(&dwtypes, "uintptr")) case obj.KindChan: die = newdie(&dwtypes, DW_ABRV_CHANTYPE, name) @@ -1043,7 +1038,7 @@ func defgotype(gotype *LSym) *DWDie { case obj.KindFunc: die = newdie(&dwtypes, DW_ABRV_FUNCTYPE, name) dotypedef(&dwtypes, name, die) - newrefattr(die, DW_AT_type, find_or_diag(&dwtypes, "void")) + newrefattr(die, DW_AT_type, mustFind(&dwtypes, "void")) nfields := decodetype_funcincount(gotype) var fld *DWDie var s *LSym @@ -1125,7 +1120,7 @@ func defgotype(gotype *LSym) *DWDie { default: Diag("dwarf: definition of unknown kind %d: %s", kind, gotype.Name) die = newdie(&dwtypes, DW_ABRV_TYPEDECL, name) - newrefattr(die, DW_AT_type, find_or_diag(&dwtypes, "")) + newrefattr(die, DW_AT_type, mustFind(&dwtypes, "")) } newattr(die, DW_AT_go_kind, DW_CLS_CONSTANT, int64(kind), 0) @@ -1173,7 +1168,7 @@ func copychildren(dst *DWDie, src *DWDie) { // Search children (assumed to have DW_TAG_member) for the one named // field and set its DW_AT_type to dwtype func substitutetype(structdie *DWDie, field string, dwtype *DWDie) { - child := find_or_diag(structdie, field) + child := mustFind(structdie, field) if child == nil { return } @@ -1302,7 +1297,7 @@ func synthesizemaptypes(die *DWDie) { newrefattr(dwhk, DW_AT_type, t) fld = newdie(dwhk, DW_ABRV_ARRAYRANGE, "size") newattr(fld, DW_AT_count, DW_CLS_CONSTANT, BucketSize, 0) - newrefattr(fld, DW_AT_type, find_or_diag(&dwtypes, "uintptr")) + newrefattr(fld, DW_AT_type, mustFind(&dwtypes, "uintptr")) // Construct type to represent an array of BucketSize values dwhv = newdie(&dwtypes, DW_ABRV_ARRAYTYPE, mkinternaltypename("[]val", getattr(valtype, DW_AT_name).data.(string), "")) @@ -1315,7 +1310,7 @@ func synthesizemaptypes(die *DWDie) { newrefattr(dwhv, DW_AT_type, t) fld = newdie(dwhv, DW_ABRV_ARRAYRANGE, "size") newattr(fld, DW_AT_count, DW_CLS_CONSTANT, BucketSize, 0) - newrefattr(fld, DW_AT_type, find_or_diag(&dwtypes, "uintptr")) + newrefattr(fld, DW_AT_type, mustFind(&dwtypes, "uintptr")) // Construct bucket dwhb = newdie(&dwtypes, DW_ABRV_STRUCTTYPE, mkinternaltypename("bucket", getattr(keytype, DW_AT_name).data.(string), getattr(valtype, DW_AT_name).data.(string))) @@ -1335,7 +1330,7 @@ func synthesizemaptypes(die *DWDie) { newmemberoffsetattr(fld, BucketSize+BucketSize*(int32(keysize)+int32(valsize))) if Thearch.Regsize > Thearch.Ptrsize { fld = newdie(dwhb, DW_ABRV_STRUCTFIELD, "pad") - newrefattr(fld, DW_AT_type, find_or_diag(&dwtypes, "uintptr")) + newrefattr(fld, DW_AT_type, mustFind(&dwtypes, "uintptr")) newmemberoffsetattr(fld, BucketSize+BucketSize*(int32(keysize)+int32(valsize))+int32(Thearch.Ptrsize)) } @@ -1804,8 +1799,7 @@ func writeframes() { pad := CIERESERVE + frameo + 4 - Cpos() if pad < 0 { - Diag("dwarf: CIERESERVE too small by %d bytes.", -pad) - Errorexit() + Exitf("dwarf: CIERESERVE too small by %d bytes.", -pad) } strnput("", int(pad)) @@ -2150,13 +2144,11 @@ func Dwarfemitdebugsections() { Cseek(infoo) writeinfo() if fwdcount > 0 { - Diag("dwarf: unresolved references after first dwarf info pass") - Errorexit() + Exitf("dwarf: unresolved references after first dwarf info pass") } if infoe != Cpos() { - Diag("dwarf: inconsistent second dwarf info pass") - Errorexit() + Exitf("dwarf: inconsistent second dwarf info pass") } } diff --git a/src/cmd/internal/ld/elf.go b/src/cmd/internal/ld/elf.go index 790c8713de..c94d1564a4 100644 --- a/src/cmd/internal/ld/elf.go +++ b/src/cmd/internal/ld/elf.go @@ -7,7 +7,6 @@ package ld import ( "encoding/binary" "fmt" - "os" ) /* @@ -870,7 +869,7 @@ func elfwriteshdrs() uint32 { func elfsetstring(s string, off int) { if nelfstr >= len(elfstr) { Diag("too many elf strings") - Errorexit() + errorexit() } elfstr[nelfstr].s = s @@ -1133,8 +1132,7 @@ func addbuildinfo(val string) { var j int if val[0] != '0' || val[1] != 'x' { - fmt.Fprintf(os.Stderr, "%s: -B argument must start with 0x: %s\n", os.Args[0], val) - Exit(2) + Exitf("-B argument must start with 0x: %s", val) } ov := val @@ -1143,8 +1141,7 @@ func addbuildinfo(val string) { var b int for val != "" { if len(val) == 1 { - fmt.Fprintf(os.Stderr, "%s: -B argument must have even number of digits: %s\n", os.Args[0], ov) - Exit(2) + Exitf("-B argument must have even number of digits: %s", ov) } b = 0 @@ -1157,15 +1154,13 @@ func addbuildinfo(val string) { } else if val[0] >= 'A' && val[0] <= 'F' { b += int(val[0]) - 'A' + 10 } else { - fmt.Fprintf(os.Stderr, "%s: -B argument contains invalid hex digit %c: %s\n", os.Args[0], val[0], ov) - Exit(2) + Exitf("-B argument contains invalid hex digit %c: %s", val[0], ov) } } const maxLen = 32 if i >= maxLen { - fmt.Fprintf(os.Stderr, "%s: -B option too long (max %d digits): %s\n", os.Args[0], maxLen, ov) - Exit(2) + Exitf("-B option too long (max %d digits): %s", maxLen, ov) } buildinfo = append(buildinfo, uint8(b)) @@ -1264,21 +1259,7 @@ func elfdynhash() { need := make([]*Elfaux, nsym) chain := make([]uint32, nsym) buckets := make([]uint32, nbucket) - if need == nil || chain == nil || buckets == nil { - Ctxt.Cursym = nil - Diag("out of memory") - Errorexit() - } - for i := 0; i < nsym; i++ { - need[i] = nil - } - for i := 0; i < nsym; i++ { - chain[i] = 0 - } - for i := 0; i < nbucket; i++ { - buckets[i] = 0 - } var b int var hc uint32 var name string @@ -1434,7 +1415,7 @@ func elfshname(name string) *ElfShdr { } Diag("cannot find elf name %s", name) - Errorexit() + errorexit() return nil } @@ -1884,22 +1865,15 @@ func Asmbelf(symo int64) { eh := getElfEhdr() switch Thearch.Thechar { default: - Diag("unknown architecture in asmbelf") - Errorexit() - fallthrough - + Exitf("unknown architecture in asmbelf: %v", Thearch.Thechar) case '5': eh.machine = EM_ARM - case '6': eh.machine = EM_X86_64 - case '7': eh.machine = EM_AARCH64 - case '8': eh.machine = EM_386 - case '9': eh.machine = EM_PPC64 } diff --git a/src/cmd/internal/ld/go.go b/src/cmd/internal/ld/go.go index f24a9e4e74..80b2c34548 100644 --- a/src/cmd/internal/ld/go.go +++ b/src/cmd/internal/ld/go.go @@ -67,7 +67,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if int64(int(length)) != length { fmt.Fprintf(os.Stderr, "%s: too much pkg data in %s\n", os.Args[0], filename) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -76,7 +76,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if int64(Bread(f, bdata)) != length { fmt.Fprintf(os.Stderr, "%s: short pkg read %s\n", os.Args[0], filename) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -86,8 +86,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { p0 = strings.Index(data, "\n$$") if p0 < 0 { if Debug['u'] != 0 && whence != ArchiveObj { - fmt.Fprintf(os.Stderr, "%s: cannot find export data in %s\n", os.Args[0], filename) - Errorexit() + Exitf("cannot find export data in %s", filename) } return } @@ -102,7 +101,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if p1 < 0 { fmt.Fprintf(os.Stderr, "%s: cannot find end of exports in %s\n", os.Args[0], filename) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -115,7 +114,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if !strings.HasPrefix(data[p0:], "package ") { fmt.Fprintf(os.Stderr, "%s: bad package section in %s - %.20s\n", os.Args[0], filename, data[p0:]) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -129,9 +128,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { p0++ } if Debug['u'] != 0 && whence != ArchiveObj && (p0+6 > p1 || !strings.HasPrefix(data[p0:], " safe\n")) { - fmt.Fprintf(os.Stderr, "%s: load of unsafe package %s\n", os.Args[0], filename) - nerrors++ - Errorexit() + Exitf("load of unsafe package %s", filename) } name := data[pname:p0] @@ -143,9 +140,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { } if pkg == "main" && name != "main" { - fmt.Fprintf(os.Stderr, "%s: %s: not package main (package %s)\n", os.Args[0], filename, name) - nerrors++ - Errorexit() + Exitf("%s: not package main (package %s)", filename, name) } loadpkgdata(filename, pkg, data[p0:p1]) @@ -164,7 +159,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if i < 0 { fmt.Fprintf(os.Stderr, "%s: found $$ // cgo but no newline in %s\n", os.Args[0], filename) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -177,7 +172,7 @@ func ldpkg(f *Biobuf, pkg string, length int64, filename string, whence int) { if p1 < 0 { fmt.Fprintf(os.Stderr, "%s: cannot find end of // cgo section in %s\n", os.Args[0], filename) if Debug['u'] != 0 { - Errorexit() + errorexit() } return } @@ -832,7 +827,6 @@ func setlinkmode(arg string) { } else if arg == "auto" { Linkmode = LinkAuto } else { - fmt.Fprintf(os.Stderr, "unknown link mode -linkmode %s\n", arg) - Errorexit() + Exitf("unknown link mode -linkmode %s", arg) } } diff --git a/src/cmd/internal/ld/ldelf.go b/src/cmd/internal/ld/ldelf.go index beb62b7c7c..7698483b23 100644 --- a/src/cmd/internal/ld/ldelf.go +++ b/src/cmd/internal/ld/ldelf.go @@ -597,11 +597,6 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { // symbol 0 is the null symbol. symbols = make([]*LSym, elfobj.nsymtab) - if symbols == nil { - Diag("out of memory") - Errorexit() - } - for i := 1; i < elfobj.nsymtab; i++ { if err = readelfsym(elfobj, i, &sym, 1); err != nil { goto bad @@ -643,8 +638,7 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { if s.Dupok != 0 { continue } - Diag("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) - Errorexit() + Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) } s.Sub = sect.sym.Sub diff --git a/src/cmd/internal/ld/ldmacho.go b/src/cmd/internal/ld/ldmacho.go index 9ed40935e2..e63ff8ea5a 100644 --- a/src/cmd/internal/ld/ldmacho.go +++ b/src/cmd/internal/ld/ldmacho.go @@ -641,8 +641,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { if s.Dupok != 0 { continue } - Diag("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) - Errorexit() + Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) } s.Type = outer.Type | SSUB diff --git a/src/cmd/internal/ld/ldpe.go b/src/cmd/internal/ld/ldpe.go index e124d8164e..010f640cf0 100644 --- a/src/cmd/internal/ld/ldpe.go +++ b/src/cmd/internal/ld/ldpe.go @@ -399,8 +399,7 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { if s.Dupok != 0 { continue } - Diag("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) - Errorexit() + Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) } s.Sub = sect.sym.Sub diff --git a/src/cmd/internal/ld/lib.go b/src/cmd/internal/ld/lib.go index c18ae86cb5..048556a5fc 100644 --- a/src/cmd/internal/ld/lib.go +++ b/src/cmd/internal/ld/lib.go @@ -356,8 +356,7 @@ func libinit() { mayberemoveoutfile() f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775) if err != nil { - Diag("cannot create %s: %v", outfile, err) - Errorexit() + Exitf("cannot create %s: %v", outfile, err) } cout = f @@ -381,7 +380,16 @@ func libinit() { } } -func Errorexit() { +func Exitf(format string, a ...interface{}) { + fmt.Fprintf(os.Stderr, os.Args[0]+": "+format+"\n", a...) + if cout != nil { + cout.Close() + mayberemoveoutfile() + } + Exit(2) +} + +func errorexit() { if cout != nil { // For rmtemp run at atexit time on Windows. cout.Close() @@ -621,8 +629,7 @@ func objfile(file string, pkg string) { var f *Biobuf f, err = Bopenr(file) if err != nil { - Diag("cannot open file %s: %v", file, err) - Errorexit() + Exitf("cannot open file %s: %v", file, err) } magbuf := make([]byte, len(ARMAG)) @@ -686,9 +693,7 @@ func objfile(file string, pkg string) { break } if l < 0 { - Diag("%s: malformed archive", file) - Errorexit() - goto out + Exitf("%s: malformed archive", file) } off += l @@ -767,9 +772,7 @@ func hostobjs() { var err error f, err = Bopenr(h.file) if f == nil { - Ctxt.Cursym = nil - Diag("cannot reopen %s: %v", h.pn, err) - Errorexit() + Exitf("cannot reopen %s: %v", h.pn, err) } Bseek(f, h.off, 0) @@ -806,8 +809,7 @@ func hostlinksetup() { var err error cout, err = os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775) if err != nil { - Diag("cannot create %s: %v", p, err) - Errorexit() + Exitf("cannot create %s: %v", p, err) } coutbuf = *Binitw(cout) @@ -819,33 +821,23 @@ func hostobjCopy() (paths []string) { for i, h := range hostobj { f, err := os.Open(h.file) if err != nil { - Ctxt.Cursym = nil - Diag("cannot reopen %s: %v", h.pn, err) - Errorexit() + Exitf("cannot reopen %s: %v", h.pn, err) } if _, err := f.Seek(h.off, 0); err != nil { - Ctxt.Cursym = nil - Diag("cannot seek %s: %v", h.pn, err) - Errorexit() + Exitf("cannot seek %s: %v", h.pn, err) } p := fmt.Sprintf("%s/%06d.o", tmpdir, i) paths = append(paths, p) w, err := os.Create(p) if err != nil { - Ctxt.Cursym = nil - Diag("cannot create %s: %v", p, err) - Errorexit() + Exitf("cannot create %s: %v", p, err) } if _, err := io.CopyN(w, f, h.length); err != nil { - Ctxt.Cursym = nil - Diag("cannot write %s: %v", p, err) - Errorexit() + Exitf("cannot write %s: %v", p, err) } if err := w.Close(); err != nil { - Ctxt.Cursym = nil - Diag("cannot close %s: %v", p, err) - Errorexit() + Exitf("cannot close %s: %v", p, err) } } return paths @@ -868,9 +860,7 @@ func archive() { } if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil { - Ctxt.Cursym = nil - Diag("%s: running %s failed: %v\n%s", os.Args[0], argv[0], err, out) - Errorexit() + Exitf("running %s failed: %v\n%s", argv[0], err, out) } } @@ -1014,9 +1004,7 @@ func hostlink() { } if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil { - Ctxt.Cursym = nil - Diag("%s: running %s failed: %v\n%s", os.Args[0], argv[0], err, out) - Errorexit() + Exitf("running %s failed: %v\n%s", argv[0], err, out) } } @@ -1050,39 +1038,32 @@ func ldobj(f *Biobuf, pkg string, length int64, pn string, file string, whence i /* check the header */ line := Brdline(f, '\n') - - var import0 int64 - var import1 int64 - var t string if line == "" { if Blinelen(f) > 0 { Diag("%s: not an object file", pn) return } - - goto eof + Diag("truncated object file: %s", pn) + return } if !strings.HasPrefix(line, "go object ") { if strings.HasSuffix(pn, ".go") { - fmt.Printf("%cl: input %s is not .%c file (use %cg to compile .go files)\n", Thearch.Thechar, pn, Thearch.Thechar, Thearch.Thechar) - Errorexit() + Exitf("%cl: input %s is not .%c file (use %cg to compile .go files)", Thearch.Thechar, pn, Thearch.Thechar, Thearch.Thechar) } if line == Thestring { // old header format: just $GOOS Diag("%s: stale object file", pn) - return } Diag("%s: not an object file", pn) - return } // First, check that the basic goos, goarch, and version match. - t = fmt.Sprintf("%s %s %s ", goos, obj.Getgoarch(), obj.Getgoversion()) + t := fmt.Sprintf("%s %s %s ", goos, obj.Getgoarch(), obj.Getgoversion()) line = strings.TrimRight(line, "\n") if !strings.HasPrefix(line[10:]+" ", t) && Debug['f'] == 0 { @@ -1103,7 +1084,7 @@ func ldobj(f *Biobuf, pkg string, length int64, pn string, file string, whence i } /* skip over exports and other info -- ends with \n!\n */ - import0 = Boffset(f) + import0 := Boffset(f) c1 = '\n' // the last line ended in \n c2 = Bgetc(f) @@ -1113,22 +1094,18 @@ func ldobj(f *Biobuf, pkg string, length int64, pn string, file string, whence i c2 = c3 c3 = Bgetc(f) if c3 == Beof { - goto eof + Diag("truncated object file: %s", pn) + return } } - import1 = Boffset(f) + import1 := Boffset(f) Bseek(f, import0, 0) ldpkg(f, pkg, import1-import0-2, pn, whence) // -2 for !\n Bseek(f, import1, 0) ldobjfile(Ctxt, f, pkg, eof-Boffset(f), pn) - - return - -eof: - Diag("truncated object file: %s", pn) } func ldshlibsyms(shlib string) { @@ -1553,8 +1530,7 @@ func usage() { func setheadtype(s string) { h := headtype(s) if h < 0 { - fmt.Fprintf(os.Stderr, "unknown header type -H %s\n", s) - Errorexit() + Exitf("unknown header type -H %s", s) } headstring = s @@ -1567,8 +1543,7 @@ func setinterp(s string) { } func doversion() { - fmt.Printf("%cl version %s\n", Thearch.Thechar, obj.Getgoversion()) - Errorexit() + Exitf("version %s", obj.Getgoversion()) } func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { @@ -1756,7 +1731,7 @@ func undef() { undefsym(s) } if nerrors > 0 { - Errorexit() + errorexit() } } @@ -1791,8 +1766,7 @@ func Diag(format string, args ...interface{}) { nerrors++ if nerrors > 20 { - fmt.Printf("too many errors\n") - Errorexit() + Exitf("too many errors") } } diff --git a/src/cmd/internal/ld/macho.go b/src/cmd/internal/ld/macho.go index e7ad8e2d85..ee4eb7a455 100644 --- a/src/cmd/internal/ld/macho.go +++ b/src/cmd/internal/ld/macho.go @@ -159,8 +159,7 @@ func newMachoLoad(type_ uint32, ndata uint32) *MachoLoad { func newMachoSeg(name string, msect int) *MachoSeg { if nseg >= len(seg) { - Diag("too many segs") - Errorexit() + Exitf("too many segs") } s := &seg[nseg] @@ -173,8 +172,7 @@ func newMachoSeg(name string, msect int) *MachoSeg { func newMachoSect(seg *MachoSeg, name string, segname string) *MachoSect { if seg.nsect >= seg.msect { - Diag("too many sects in segment %s", seg.name) - Errorexit() + Exitf("too many sects in segment %s", seg.name) } s := &seg.sect[seg.nsect] @@ -419,9 +417,7 @@ func Asmbmacho() { mh := getMachoHdr() switch Thearch.Thechar { default: - Diag("unknown mach architecture") - Errorexit() - fallthrough + Exitf("unknown macho architecture: %v", Thearch.Thechar) case '5': mh.cpu = MACHO_CPU_ARM @@ -491,9 +487,7 @@ func Asmbmacho() { if Linkmode != LinkExternal { switch Thearch.Thechar { default: - Diag("unknown macho architecture") - Errorexit() - fallthrough + Exitf("unknown macho architecture: %v", Thearch.Thechar) case '5': ml := newMachoLoad(5, 17+2) /* unix thread */ @@ -572,7 +566,7 @@ func Asmbmacho() { a := machowrite() if int32(a) > HEADR { - Diag("HEADR too small: %d > %d", a, HEADR) + Exitf("HEADR too small: %d > %d", a, HEADR) } } diff --git a/src/cmd/internal/ld/pcln.go b/src/cmd/internal/ld/pcln.go index 5a03b83fcc..5bc9f556cc 100644 --- a/src/cmd/internal/ld/pcln.go +++ b/src/cmd/internal/ld/pcln.go @@ -298,7 +298,7 @@ func pclntab() { for pciterinit(Ctxt, &it, &pcln.Pcfile); it.done == 0; pciternext(&it) { if it.value < 1 || it.value > Ctxt.Nhistfile { Diag("bad file number in pcfile: %d not in range [1, %d]\n", it.value, Ctxt.Nhistfile) - Errorexit() + errorexit() } } } @@ -337,7 +337,7 @@ func pclntab() { if off != end { Diag("bad math in functab: funcstart=%d off=%d but end=%d (npcdata=%d nfuncdata=%d ptrsize=%d)", funcstart, off, end, pcln.Npcdata, pcln.Nfuncdata, Thearch.Ptrsize) - Errorexit() + errorexit() } nfunc++ diff --git a/src/cmd/internal/ld/pe.go b/src/cmd/internal/ld/pe.go index 53bf0af387..de6788d2ae 100644 --- a/src/cmd/internal/ld/pe.go +++ b/src/cmd/internal/ld/pe.go @@ -389,7 +389,7 @@ var ncoffsym int func addpesection(name string, sectsize int, filesize int) *IMAGE_SECTION_HEADER { if pensect == 16 { Diag("too many sections") - Errorexit() + errorexit() } h := &sh[pensect] @@ -410,19 +410,19 @@ func addpesection(name string, sectsize int, filesize int) *IMAGE_SECTION_HEADER func chksectoff(h *IMAGE_SECTION_HEADER, off int64) { if off != int64(h.PointerToRawData) { Diag("%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(off)) - Errorexit() + errorexit() } } func chksectseg(h *IMAGE_SECTION_HEADER, s *Segment) { if s.Vaddr-PEBASE != uint64(h.VirtualAddress) { Diag("%s.VirtualAddress = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.VirtualAddress)), uint64(int64(s.Vaddr-PEBASE))) - Errorexit() + errorexit() } if s.Fileoff != uint64(h.PointerToRawData) { Diag("%s.PointerToRawData = %#x, want %#x", cstring(h.Name[:]), uint64(int64(h.PointerToRawData)), uint64(int64(s.Fileoff))) - Errorexit() + errorexit() } } @@ -711,7 +711,7 @@ func initdynexport() { } if nexport+1 > len(dexport) { Diag("pe dynexport table is full") - Errorexit() + errorexit() } dexport[nexport] = s @@ -1096,13 +1096,9 @@ func addpersrc() { func Asmbpe() { switch Thearch.Thechar { default: - Diag("unknown PE architecture") - Errorexit() - fallthrough - + Exitf("unknown PE architecture: %v", Thearch.Thechar) case '6': fh.Machine = IMAGE_FILE_MACHINE_AMD64 - case '8': fh.Machine = IMAGE_FILE_MACHINE_I386 } diff --git a/src/cmd/internal/ld/pobj.go b/src/cmd/internal/ld/pobj.go index e6fb635690..36abe9da98 100644 --- a/src/cmd/internal/ld/pobj.go +++ b/src/cmd/internal/ld/pobj.go @@ -148,8 +148,7 @@ func Ldmain() { if Buildmode == BuildmodeExe { Buildmode = BuildmodeCShared } else if Buildmode != BuildmodeCShared { - Diag("-shared and -buildmode=%s are incompatible\n", Buildmode.String()) - Errorexit() + Exitf("-shared and -buildmode=%s are incompatible", Buildmode.String()) } } @@ -178,8 +177,7 @@ func Ldmain() { Thearch.Archinit() if Linkshared && !Iself { - Diag("-linkshared can only be used on elf systems") - Errorexit() + Exitf("-linkshared can only be used on elf systems") } if Debug['v'] != 0 { @@ -246,5 +244,5 @@ func Ldmain() { Bflush(&Bso) - Errorexit() + errorexit() }