1
0
mirror of https://github.com/golang/go synced 2024-11-12 10:30:23 -07:00

cmd/internal/*: only call ctx.Bso.Flush when something has been written

In many places where ctx.Bso.Flush is used as the target for some debug
logging, ctx.Bso.Flush is called unconditionally. In the majority of
cases where debug logging is not enabled, this means Flush is called
many times when there is nothing to be flushed (it will be called anyway
when ctx.Bso is eventually closed), sometimes in a loop.

Avoid this by moving the ctx.Bso.Flush call into the same condition
block as the debug print. This pattern was previously applied
sporadically.

Change-Id: I0444cb235cc8b9bac51a59b2e44e59872db2be06
Reviewed-on: https://go-review.googlesource.com/27579
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Dave Cheney 2016-08-24 20:44:09 +10:00
parent 1472221a77
commit 3167ff7ca9
14 changed files with 47 additions and 48 deletions

View File

@ -714,8 +714,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
if ctxt.Autosize == 0 && !(cursym.Text.Mark&LEAF != 0) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "save suppressed in: %s\n", cursym.Text.From.Sym.Name)
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
cursym.Text.Mark |= LEAF
}

View File

@ -145,8 +145,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
*/
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f noops\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
var q *obj.Prog
var q1 *obj.Prog

View File

@ -276,8 +276,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
*/
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f noops\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
var q *obj.Prog
var q1 *obj.Prog

View File

@ -243,8 +243,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
*/
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f noops\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
var q *obj.Prog
var q1 *obj.Prog

View File

@ -601,13 +601,13 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f codeblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -625,8 +625,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -634,8 +634,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -679,8 +679,8 @@ func asmb(ctxt *ld.Link) {
if !*ld.FlagS {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
case obj.Hplan9:
@ -751,8 +751,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f headr\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -584,8 +584,8 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -602,8 +602,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -611,8 +611,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -634,8 +634,8 @@ func asmb(ctxt *ld.Link) {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
@ -690,8 +690,8 @@ func asmb(ctxt *ld.Link) {
ctxt.Cursym = nil
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -393,8 +393,8 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -411,8 +411,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -420,8 +420,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -443,8 +443,8 @@ func asmb(ctxt *ld.Link) {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
@ -499,8 +499,8 @@ func asmb(ctxt *ld.Link) {
ctxt.Cursym = nil
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -649,8 +649,8 @@ func relocsym(ctxt *Link, s *Symbol) {
func (ctxt *Link) reloc() {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f reloc\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
for _, s := range ctxt.Textp {
relocsym(ctxt, s)
@ -725,8 +725,8 @@ func dynreloc(ctxt *Link, data *[obj.SXREF][]*Symbol) {
}
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f reloc\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
for _, s := range ctxt.Textp {
dynrelocsym(ctxt, s)
@ -805,9 +805,8 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
for ; addr < eaddr; addr++ {
fmt.Fprintf(ctxt.Bso, " %.2x", 0)
}
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
}
func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
@ -1191,8 +1190,8 @@ var datap []*Symbol
func (ctxt *Link) dodata() {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f dodata\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
// Collect data symbols by type into data.
var data [obj.SXREF][]*Symbol

View File

@ -655,8 +655,8 @@ func objfile(ctxt *Link, lib *Library) {
if ctxt.Debugvlog > 1 {
fmt.Fprintf(ctxt.Bso, "%5.2f ldobj: %s (%s)\n", obj.Cputime(), lib.File, pkg)
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
f, err := bio.Open(lib.File)
if err != nil {
Exitf("cannot open file %s: %v", lib.File, err)
@ -1945,8 +1945,8 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, i
// Something underhanded is going on. Say nothing.
if ctxt.Debugvlog != 0 || *flagN {
fmt.Fprintf(ctxt.Bso, "%5.2f symsize = %d\n", obj.Cputime(), uint32(Symsize))
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
}
func Symaddr(ctxt *Link, s *Symbol) int64 {

View File

@ -176,8 +176,8 @@ func Main() {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "HEADER = -H%d -T0x%x -D0x%x -R0x%x\n", HEADTYPE, uint64(*FlagTextAddr), uint64(*FlagDataAddr), uint32(*FlagRound))
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if Buildmode == BuildmodeShared {
for i := 0; i < flag.NArg(); i++ {

View File

@ -185,8 +185,8 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -203,8 +203,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -212,8 +212,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -230,8 +230,8 @@ func asmb(ctxt *ld.Link) {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
@ -278,8 +278,8 @@ func asmb(ctxt *ld.Link) {
ctxt.Cursym = nil
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -806,8 +806,8 @@ func ensureglinkresolver(ctxt *ld.Link) *ld.Symbol {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -824,8 +824,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -833,8 +833,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -851,8 +851,8 @@ func asmb(ctxt *ld.Link) {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
@ -899,8 +899,8 @@ func asmb(ctxt *ld.Link) {
ctxt.Cursym = nil
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -501,8 +501,8 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -519,8 +519,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -528,8 +528,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -548,8 +548,8 @@ func asmb(ctxt *ld.Link) {
}
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
@ -573,8 +573,8 @@ func asmb(ctxt *ld.Link) {
ctxt.Cursym = nil
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default:

View File

@ -627,8 +627,8 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
if ld.Iself {
ld.Asmbelfsetup(ctxt)
@ -646,8 +646,8 @@ func asmb(ctxt *ld.Link) {
if ld.Segrodata.Filelen > 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segrodata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
@ -655,8 +655,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(int64(ld.Segdata.Fileoff))
ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
@ -677,8 +677,8 @@ func asmb(ctxt *ld.Link) {
// TODO: rationalize
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
switch ld.HEADTYPE {
default:
if ld.Iself {
@ -741,8 +741,8 @@ func asmb(ctxt *ld.Link) {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f headr\n", obj.Cputime())
ctxt.Bso.Flush()
}
ctxt.Bso.Flush()
ld.Cseek(0)
switch ld.HEADTYPE {
default: