1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:00:06 -07:00

cmd/link: various cleanups using tools

* remove unnecessary explicit types
* remove dead assignments
* remove unused fields
* unindent code using early continues
* remove some unnecessary type conversions
* remove some unused func parameters

Change-Id: I202c67e92940beacbd80fc2dc179f9556dc5d9e5
Reviewed-on: https://go-review.googlesource.com/69118
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Daniel Martí 2017-10-09 10:11:00 +01:00
parent 7830a19a4f
commit 966c459fa4
8 changed files with 33 additions and 34 deletions

View File

@ -266,7 +266,7 @@ func reverselist(list **dwarf.DWDie) {
curr := *list
var prev *dwarf.DWDie
for curr != nil {
var next *dwarf.DWDie = curr.Link
next := curr.Link
curr.Link = prev
prev = curr
curr = next
@ -1077,7 +1077,6 @@ func writelines(ctxt *Link, syms []*sym.Symbol) ([]*sym.Symbol, []*sym.Symbol) {
continue
}
epc = s.Value + s.Size
epcs = s
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))

View File

@ -810,7 +810,6 @@ type ElfShdr struct {
addralign uint64
entsize uint64
shnum int
secsym *sym.Symbol
}
/*
@ -888,7 +887,7 @@ const (
var (
Iself bool
Nelfsym int = 1
Nelfsym = 1
elf64 bool
// Either ".rel" or ".rela" depending on which type of relocation the
@ -1611,16 +1610,17 @@ func elfphrelro(seg *sym.Segment) {
func elfshname(name string) *ElfShdr {
for i := 0; i < nelfstr; i++ {
if name == elfstr[i].s {
off := elfstr[i].off
for i = 0; i < int(ehdr.shnum); i++ {
sh := shdr[i]
if sh.name == uint32(off) {
return sh
}
}
return newElfShdr(int64(off))
if name != elfstr[i].s {
continue
}
off := elfstr[i].off
for i = 0; i < int(ehdr.shnum); i++ {
sh := shdr[i]
if sh.name == uint32(off) {
return sh
}
}
return newElfShdr(int64(off))
}
Exitf("cannot find elf name %s", name)
return nil

View File

@ -279,7 +279,6 @@ type ElfObj struct {
e binary.ByteOrder
sect []ElfSect
nsect uint
shstrtab string
nsymtab int
symtab *ElfSect
symstr *ElfSect
@ -426,19 +425,20 @@ func parseArmAttributes(ctxt *Link, e binary.ByteOrder, data []byte) {
subsectiondata := sectiondata[sz+4 : subsectionsize]
sectiondata = sectiondata[subsectionsize:]
if subsectiontag == TagFile {
attrList := elfAttributeList{data: subsectiondata}
for !attrList.done() {
attr := attrList.armAttr()
if attr.tag == TagABIVFPArgs && attr.ival == 1 {
ehdr.flags = 0x5000402 // has entry point, Version5 EABI, hard-float ABI
}
}
if attrList.err != nil {
// TODO(dfc) should this be ctxt.Diag ?
ctxt.Logf("could not parse .ARM.attributes\n")
if subsectiontag != TagFile {
continue
}
attrList := elfAttributeList{data: subsectiondata}
for !attrList.done() {
attr := attrList.armAttr()
if attr.tag == TagABIVFPArgs && attr.ival == 1 {
ehdr.flags = 0x5000402 // has entry point, Version5 EABI, hard-float ABI
}
}
if attrList.err != nil {
// TODO(dfc) should this be ctxt.Diag ?
ctxt.Logf("could not parse .ARM.attributes\n")
}
}
}
}

View File

@ -574,7 +574,7 @@ func (ctxt *Link) loadlib() {
if typeSymbolMangling(ctxt) {
*FlagW = true // disable DWARF generation
for _, s := range ctxt.Syms.Allsym {
newName := typeSymbolMangle(ctxt.Syms, s.Name)
newName := typeSymbolMangle(s.Name)
if newName != s.Name {
ctxt.Syms.Rename(s.Name, newName, int(s.Version))
}
@ -657,7 +657,7 @@ func typeSymbolMangling(ctxt *Link) bool {
}
// typeSymbolMangle mangles the given symbol name into something shorter.
func typeSymbolMangle(syms *sym.Symbols, name string) string {
func typeSymbolMangle(name string) string {
if !strings.HasPrefix(name, "type.") {
return name
}

View File

@ -96,9 +96,9 @@ func (ctxt *Link) FixedFrameSize() int64 {
}
}
func (l *Link) Logf(format string, args ...interface{}) {
fmt.Fprintf(l.Bso, format, args...)
l.Bso.Flush()
func (ctxt *Link) Logf(format string, args ...interface{}) {
fmt.Fprintf(ctxt.Bso, format, args...)
ctxt.Bso.Flush()
}
func addImports(ctxt *Link, l *sym.Library, pn string) {

View File

@ -180,7 +180,7 @@ var nsortsym int
// "big enough" header size. The initial header is
// one page, the non-dynamic library stuff takes
// up about 1300 bytes; we overestimate that as 2k.
var loadBudget int = INITIAL_MACHO_HEADR - 2*1024
var loadBudget = INITIAL_MACHO_HEADR - 2*1024
func getMachoHdr() *MachoHdr {
return &machohdr

View File

@ -17,7 +17,7 @@ import (
var realdwarf, linkseg *macho.Segment
var dwarfstart, linkstart int64
var dwarfaddr, linkaddr int64
var dwarfaddr int64
var linkoffset uint32
const (

View File

@ -73,7 +73,7 @@ func putelfsyment(out *OutBuf, off int, addr int64, size int64, info int, shndx
}
}
var numelfsym int = 1 // 0 is reserved
var numelfsym = 1 // 0 is reserved
var elfbind int
@ -592,7 +592,7 @@ func (ctxt *Link) symtab() {
// pkghashes[i].name
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkgname.%d", i), l.Pkg)
// pkghashes[i].linktimehash
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkglinkhash.%d", i), string(l.Hash))
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkglinkhash.%d", i), l.Hash)
// pkghashes[i].runtimehash
hash := ctxt.Syms.ROLookup("go.link.pkghash."+l.Pkg, 0)
pkghashes.AddAddr(ctxt.Arch, hash)