Skip to content

Commit 0a15d95

Browse files
committed
cmd/link: use standard library flag package where possible
The obj library's flag functions are (mostly) light wrappers around the standard library flag package. Use the flag package directly where possible. Most uses of the 'count'-type flags (except for -v) only check against 0, so they can safely be replaced by bools. Only -v and the flagfns haven't been replaced. Debug has been turned into a slice of bools rather than ints. There was a copy of the -v verbosity in ctxt.Debugvlog, so don't use Debug['v'] and just use ctxt.Debugvlog. Updates #16818 Change-Id: Icf6473a4823c9d35513bbd0c34ea02d5676d782a Reviewed-on: https://go-review.googlesource.com/27471 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 65c5d62 commit 0a15d95

File tree

26 files changed

+181
-187
lines changed

26 files changed

+181
-187
lines changed

src/cmd/link/internal/amd64/asm.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,12 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
599599
}
600600

601601
func asmb(ctxt *ld.Link) {
602-
if ld.Debug['v'] != 0 {
602+
if ctxt.Debugvlog != 0 {
603603
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
604604
}
605605
ctxt.Bso.Flush()
606606

607-
if ld.Debug['v'] != 0 {
607+
if ctxt.Debugvlog != 0 {
608608
fmt.Fprintf(ctxt.Bso, "%5.2f codeblk\n", obj.Cputime())
609609
}
610610
ctxt.Bso.Flush()
@@ -623,7 +623,7 @@ func asmb(ctxt *ld.Link) {
623623
}
624624

625625
if ld.Segrodata.Filelen > 0 {
626-
if ld.Debug['v'] != 0 {
626+
if ctxt.Debugvlog != 0 {
627627
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
628628
}
629629
ctxt.Bso.Flush()
@@ -632,7 +632,7 @@ func asmb(ctxt *ld.Link) {
632632
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
633633
}
634634

635-
if ld.Debug['v'] != 0 {
635+
if ctxt.Debugvlog != 0 {
636636
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
637637
}
638638
ctxt.Bso.Flush()
@@ -657,15 +657,15 @@ func asmb(ctxt *ld.Link) {
657657
break
658658

659659
case obj.Hdarwin:
660-
ld.Debug['8'] = 1 /* 64-bit addresses */
660+
ld.Debug['8'] = true /* 64-bit addresses */
661661

662662
case obj.Hlinux,
663663
obj.Hfreebsd,
664664
obj.Hnetbsd,
665665
obj.Hopenbsd,
666666
obj.Hdragonfly,
667667
obj.Hsolaris:
668-
ld.Debug['8'] = 1 /* 64-bit addresses */
668+
ld.Debug['8'] = true /* 64-bit addresses */
669669

670670
case obj.Hnacl,
671671
obj.Hwindows:
@@ -676,15 +676,15 @@ func asmb(ctxt *ld.Link) {
676676
ld.Spsize = 0
677677
ld.Lcsize = 0
678678
symo := int64(0)
679-
if ld.Debug['s'] == 0 {
680-
if ld.Debug['v'] != 0 {
679+
if !ld.Debug['s'] {
680+
if ctxt.Debugvlog != 0 {
681681
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
682682
}
683683
ctxt.Bso.Flush()
684684
switch ld.HEADTYPE {
685685
default:
686686
case obj.Hplan9:
687-
ld.Debug['s'] = 1
687+
ld.Debug['s'] = true
688688
symo = int64(ld.Segdata.Fileoff + ld.Segdata.Filelen)
689689

690690
case obj.Hdarwin:
@@ -714,7 +714,7 @@ func asmb(ctxt *ld.Link) {
714714
ld.Cflush()
715715
ld.Cwrite(ld.Elfstrdat)
716716

717-
if ld.Debug['v'] != 0 {
717+
if ctxt.Debugvlog != 0 {
718718
fmt.Fprintf(ctxt.Bso, "%5.2f dwarf\n", obj.Cputime())
719719
}
720720

@@ -738,7 +738,7 @@ func asmb(ctxt *ld.Link) {
738738
}
739739

740740
case obj.Hwindows:
741-
if ld.Debug['v'] != 0 {
741+
if ctxt.Debugvlog != 0 {
742742
fmt.Fprintf(ctxt.Bso, "%5.2f dwarf\n", obj.Cputime())
743743
}
744744

@@ -749,7 +749,7 @@ func asmb(ctxt *ld.Link) {
749749
}
750750
}
751751

752-
if ld.Debug['v'] != 0 {
752+
if ctxt.Debugvlog != 0 {
753753
fmt.Fprintf(ctxt.Bso, "%5.2f headr\n", obj.Cputime())
754754
}
755755
ctxt.Bso.Flush()

src/cmd/link/internal/amd64/obj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func archinit(ctxt *ld.Link) {
166166

167167
case obj.Hnacl:
168168
ld.Elfinit(ctxt)
169-
ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway
169+
ld.Debug['w'] = true // disable dwarf, which gets confused and is useless anyway
170170
ld.HEADR = 0x10000
171171
ld.Funcalign = 32
172172
if ld.INITTEXT == -1 {

src/cmd/link/internal/arm/asm.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
582582
}
583583

584584
func asmb(ctxt *ld.Link) {
585-
if ld.Debug['v'] != 0 {
585+
if ctxt.Debugvlog != 0 {
586586
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
587587
}
588588
ctxt.Bso.Flush()
@@ -600,7 +600,7 @@ func asmb(ctxt *ld.Link) {
600600
}
601601

602602
if ld.Segrodata.Filelen > 0 {
603-
if ld.Debug['v'] != 0 {
603+
if ctxt.Debugvlog != 0 {
604604
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
605605
}
606606
ctxt.Bso.Flush()
@@ -609,7 +609,7 @@ func asmb(ctxt *ld.Link) {
609609
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
610610
}
611611

612-
if ld.Debug['v'] != 0 {
612+
if ctxt.Debugvlog != 0 {
613613
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
614614
}
615615
ctxt.Bso.Flush()
@@ -630,9 +630,9 @@ func asmb(ctxt *ld.Link) {
630630

631631
ld.Lcsize = 0
632632
symo := uint32(0)
633-
if ld.Debug['s'] == 0 {
633+
if !ld.Debug['s'] {
634634
// TODO: rationalize
635-
if ld.Debug['v'] != 0 {
635+
if ctxt.Debugvlog != 0 {
636636
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
637637
}
638638
ctxt.Bso.Flush()
@@ -654,7 +654,7 @@ func asmb(ctxt *ld.Link) {
654654
switch ld.HEADTYPE {
655655
default:
656656
if ld.Iself {
657-
if ld.Debug['v'] != 0 {
657+
if ctxt.Debugvlog != 0 {
658658
fmt.Fprintf(ctxt.Bso, "%5.2f elfsym\n", obj.Cputime())
659659
}
660660
ld.Asmelfsym(ctxt)
@@ -688,7 +688,7 @@ func asmb(ctxt *ld.Link) {
688688
}
689689

690690
ctxt.Cursym = nil
691-
if ld.Debug['v'] != 0 {
691+
if ctxt.Debugvlog != 0 {
692692
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
693693
}
694694
ctxt.Bso.Flush()
@@ -717,7 +717,7 @@ func asmb(ctxt *ld.Link) {
717717
}
718718

719719
ld.Cflush()
720-
if ld.Debug['c'] != 0 {
720+
if ld.Debug['c'] {
721721
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
722722
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
723723
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)

src/cmd/link/internal/arm/obj.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func archinit(ctxt *ld.Link) {
126126
obj.Hfreebsd,
127127
obj.Hnetbsd,
128128
obj.Hopenbsd:
129-
ld.Debug['d'] = 0
129+
ld.Debug['d'] = false
130130
// with dynamic linking
131131
ld.Elfinit(ctxt)
132132
ld.HEADR = ld.ELFRESERVE
@@ -155,7 +155,7 @@ func archinit(ctxt *ld.Link) {
155155
}
156156

157157
case obj.Hdarwin: /* apple MACH */
158-
ld.Debug['w'] = 1 // disable DWARF generation
158+
ld.Debug['w'] = true // disable DWARF generation
159159
ld.Machoinit()
160160
ld.HEADR = ld.INITIAL_MACHO_HEADR
161161
if ld.INITTEXT == -1 {

src/cmd/link/internal/arm64/asm.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
391391
}
392392

393393
func asmb(ctxt *ld.Link) {
394-
if ld.Debug['v'] != 0 {
394+
if ctxt.Debugvlog != 0 {
395395
fmt.Fprintf(ctxt.Bso, "%5.2f asmb\n", obj.Cputime())
396396
}
397397
ctxt.Bso.Flush()
@@ -409,7 +409,7 @@ func asmb(ctxt *ld.Link) {
409409
}
410410

411411
if ld.Segrodata.Filelen > 0 {
412-
if ld.Debug['v'] != 0 {
412+
if ctxt.Debugvlog != 0 {
413413
fmt.Fprintf(ctxt.Bso, "%5.2f rodatblk\n", obj.Cputime())
414414
}
415415
ctxt.Bso.Flush()
@@ -418,7 +418,7 @@ func asmb(ctxt *ld.Link) {
418418
ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
419419
}
420420

421-
if ld.Debug['v'] != 0 {
421+
if ctxt.Debugvlog != 0 {
422422
fmt.Fprintf(ctxt.Bso, "%5.2f datblk\n", obj.Cputime())
423423
}
424424
ctxt.Bso.Flush()
@@ -439,9 +439,9 @@ func asmb(ctxt *ld.Link) {
439439

440440
ld.Lcsize = 0
441441
symo := uint32(0)
442-
if ld.Debug['s'] == 0 {
442+
if !ld.Debug['s'] {
443443
// TODO: rationalize
444-
if ld.Debug['v'] != 0 {
444+
if ctxt.Debugvlog != 0 {
445445
fmt.Fprintf(ctxt.Bso, "%5.2f sym\n", obj.Cputime())
446446
}
447447
ctxt.Bso.Flush()
@@ -463,7 +463,7 @@ func asmb(ctxt *ld.Link) {
463463
switch ld.HEADTYPE {
464464
default:
465465
if ld.Iself {
466-
if ld.Debug['v'] != 0 {
466+
if ctxt.Debugvlog != 0 {
467467
fmt.Fprintf(ctxt.Bso, "%5.2f elfsym\n", obj.Cputime())
468468
}
469469
ld.Asmelfsym(ctxt)
@@ -497,7 +497,7 @@ func asmb(ctxt *ld.Link) {
497497
}
498498

499499
ctxt.Cursym = nil
500-
if ld.Debug['v'] != 0 {
500+
if ctxt.Debugvlog != 0 {
501501
fmt.Fprintf(ctxt.Bso, "%5.2f header\n", obj.Cputime())
502502
}
503503
ctxt.Bso.Flush()
@@ -526,7 +526,7 @@ func asmb(ctxt *ld.Link) {
526526
}
527527

528528
ld.Cflush()
529-
if ld.Debug['c'] != 0 {
529+
if ld.Debug['c'] {
530530
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
531531
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
532532
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)

src/cmd/link/internal/arm64/obj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func archinit(ctxt *ld.Link) {
138138
}
139139

140140
case obj.Hdarwin: /* apple MACH */
141-
ld.Debug['w'] = 1 // disable DWARF generation
141+
ld.Debug['w'] = true // disable DWARF generation
142142
ld.Machoinit()
143143
ld.HEADR = ld.INITIAL_MACHO_HEADR
144144
if ld.INITTEXT == -1 {

src/cmd/link/internal/ld/ar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func hostArchive(ctxt *Link, name string) {
6868
if err != nil {
6969
if os.IsNotExist(err) {
7070
// It's OK if we don't have a libgcc file at all.
71-
if Debug['v'] != 0 {
71+
if ctxt.Debugvlog != 0 {
7272
fmt.Fprintf(ctxt.Bso, "skipping libgcc file: %v\n", err)
7373
}
7474
return

src/cmd/link/internal/ld/data.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ func relocsym(ctxt *Link, s *Symbol) {
652652
}
653653

654654
func (ctxt *Link) reloc() {
655-
if Debug['v'] != 0 {
655+
if ctxt.Debugvlog != 0 {
656656
fmt.Fprintf(ctxt.Bso, "%5.2f reloc\n", obj.Cputime())
657657
}
658658
ctxt.Bso.Flush()
@@ -725,10 +725,10 @@ func dynrelocsym(ctxt *Link, s *Symbol) {
725725
func dynreloc(ctxt *Link, data *[obj.SXREF][]*Symbol) {
726726
// -d suppresses dynamic loader format, so we may as well not
727727
// compute these sections or mark their symbols as reachable.
728-
if Debug['d'] != 0 && HEADTYPE != obj.Hwindows {
728+
if Debug['d'] && HEADTYPE != obj.Hwindows {
729729
return
730730
}
731-
if Debug['v'] != 0 {
731+
if ctxt.Debugvlog != 0 {
732732
fmt.Fprintf(ctxt.Bso, "%5.2f reloc\n", obj.Cputime())
733733
}
734734
ctxt.Bso.Flush()
@@ -750,14 +750,14 @@ func Codeblk(ctxt *Link, addr int64, size int64) {
750750
CodeblkPad(ctxt, addr, size, zeros[:])
751751
}
752752
func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
753-
if Debug['a'] != 0 {
753+
if Debug['a'] {
754754
fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
755755
}
756756

757757
blk(ctxt, ctxt.Textp, addr, size, pad)
758758

759759
/* again for printing */
760-
if Debug['a'] == 0 {
760+
if !Debug['a'] {
761761
return
762762
}
763763

@@ -862,14 +862,14 @@ func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
862862
}
863863

864864
func Datblk(ctxt *Link, addr int64, size int64) {
865-
if Debug['a'] != 0 {
865+
if Debug['a'] {
866866
fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
867867
}
868868

869869
blk(ctxt, datap, addr, size, zeros[:])
870870

871871
/* again for printing */
872-
if Debug['a'] == 0 {
872+
if !Debug['a'] {
873873
return
874874
}
875875

@@ -933,7 +933,7 @@ func Datblk(ctxt *Link, addr int64, size int64) {
933933
}
934934

935935
func Dwarfblk(ctxt *Link, addr int64, size int64) {
936-
if Debug['a'] != 0 {
936+
if Debug['a'] {
937937
fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
938938
}
939939

@@ -1194,7 +1194,7 @@ func checkdatsize(ctxt *Link, datsize int64, symn int) {
11941194
var datap []*Symbol
11951195

11961196
func (ctxt *Link) dodata() {
1197-
if Debug['v'] != 0 {
1197+
if ctxt.Debugvlog != 0 {
11981198
fmt.Fprintf(ctxt.Bso, "%5.2f dodata\n", obj.Cputime())
11991199
}
12001200
ctxt.Bso.Flush()
@@ -1439,7 +1439,7 @@ func (ctxt *Link) dodata() {
14391439

14401440
if len(data[obj.STLSBSS]) > 0 {
14411441
var sect *Section
1442-
if Iself && (Linkmode == LinkExternal || Debug['d'] == 0) && HEADTYPE != obj.Hopenbsd {
1442+
if Iself && (Linkmode == LinkExternal || !Debug['d']) && HEADTYPE != obj.Hopenbsd {
14431443
sect = addsection(&Segdata, ".tbss", 06)
14441444
sect.Align = int32(SysArch.PtrSize)
14451445
sect.Vaddr = 0

src/cmd/link/internal/ld/deadcode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
//
4646
// Any unreached text symbols are removed from ctxt.Textp.
4747
func deadcode(ctxt *Link) {
48-
if Debug['v'] != 0 {
48+
if ctxt.Debugvlog != 0 {
4949
fmt.Fprintf(ctxt.Bso, "%5.2f deadcode\n", obj.Cputime())
5050
}
5151

@@ -180,7 +180,7 @@ func (d *deadcodepass) cleanupReloc(r *Reloc) {
180180
if r.Sym.Attr.Reachable() {
181181
r.Type = obj.R_ADDROFF
182182
} else {
183-
if Debug['v'] > 1 {
183+
if d.ctxt.Debugvlog > 1 {
184184
fmt.Fprintf(d.ctxt.Bso, "removing method %s\n", r.Sym.Name)
185185
}
186186
r.Sym = nil
@@ -264,7 +264,7 @@ func (d *deadcodepass) flood() {
264264
s := d.markQueue[0]
265265
d.markQueue = d.markQueue[1:]
266266
if s.Type == obj.STEXT {
267-
if Debug['v'] > 1 {
267+
if d.ctxt.Debugvlog > 1 {
268268
fmt.Fprintf(d.ctxt.Bso, "marktext %s\n", s.Name)
269269
}
270270
if s.FuncInfo != nil {
@@ -278,7 +278,7 @@ func (d *deadcodepass) flood() {
278278
if strings.HasPrefix(s.Name, "type.") && s.Name[5] != '.' {
279279
if decodetype_kind(s)&kindMask == kindInterface {
280280
for _, sig := range decodetype_ifacemethods(d.ctxt.Arch, s) {
281-
if Debug['v'] > 1 {
281+
if d.ctxt.Debugvlog > 1 {
282282
fmt.Fprintf(d.ctxt.Bso, "reached iface method: %s\n", sig)
283283
}
284284
d.ifaceMethod[sig] = true

0 commit comments

Comments
 (0)