mirror of
https://github.com/golang/go.git
synced 2025-05-31 04:02:58 +00: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:
parent
7830a19a4f
commit
966c459fa4
@ -266,7 +266,7 @@ func reverselist(list **dwarf.DWDie) {
|
|||||||
curr := *list
|
curr := *list
|
||||||
var prev *dwarf.DWDie
|
var prev *dwarf.DWDie
|
||||||
for curr != nil {
|
for curr != nil {
|
||||||
var next *dwarf.DWDie = curr.Link
|
next := curr.Link
|
||||||
curr.Link = prev
|
curr.Link = prev
|
||||||
prev = curr
|
prev = curr
|
||||||
curr = next
|
curr = next
|
||||||
@ -1077,7 +1077,6 @@ func writelines(ctxt *Link, syms []*sym.Symbol) ([]*sym.Symbol, []*sym.Symbol) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
epc = s.Value + s.Size
|
|
||||||
epcs = s
|
epcs = s
|
||||||
|
|
||||||
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
|
dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
|
||||||
|
@ -810,7 +810,6 @@ type ElfShdr struct {
|
|||||||
addralign uint64
|
addralign uint64
|
||||||
entsize uint64
|
entsize uint64
|
||||||
shnum int
|
shnum int
|
||||||
secsym *sym.Symbol
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -888,7 +887,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
Iself bool
|
Iself bool
|
||||||
|
|
||||||
Nelfsym int = 1
|
Nelfsym = 1
|
||||||
|
|
||||||
elf64 bool
|
elf64 bool
|
||||||
// Either ".rel" or ".rela" depending on which type of relocation the
|
// 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 {
|
func elfshname(name string) *ElfShdr {
|
||||||
for i := 0; i < nelfstr; i++ {
|
for i := 0; i < nelfstr; i++ {
|
||||||
if name == elfstr[i].s {
|
if name != elfstr[i].s {
|
||||||
off := elfstr[i].off
|
continue
|
||||||
for i = 0; i < int(ehdr.shnum); i++ {
|
|
||||||
sh := shdr[i]
|
|
||||||
if sh.name == uint32(off) {
|
|
||||||
return sh
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newElfShdr(int64(off))
|
|
||||||
}
|
}
|
||||||
|
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)
|
Exitf("cannot find elf name %s", name)
|
||||||
return nil
|
return nil
|
||||||
|
@ -279,7 +279,6 @@ type ElfObj struct {
|
|||||||
e binary.ByteOrder
|
e binary.ByteOrder
|
||||||
sect []ElfSect
|
sect []ElfSect
|
||||||
nsect uint
|
nsect uint
|
||||||
shstrtab string
|
|
||||||
nsymtab int
|
nsymtab int
|
||||||
symtab *ElfSect
|
symtab *ElfSect
|
||||||
symstr *ElfSect
|
symstr *ElfSect
|
||||||
@ -426,19 +425,20 @@ func parseArmAttributes(ctxt *Link, e binary.ByteOrder, data []byte) {
|
|||||||
subsectiondata := sectiondata[sz+4 : subsectionsize]
|
subsectiondata := sectiondata[sz+4 : subsectionsize]
|
||||||
sectiondata = sectiondata[subsectionsize:]
|
sectiondata = sectiondata[subsectionsize:]
|
||||||
|
|
||||||
if subsectiontag == TagFile {
|
if subsectiontag != TagFile {
|
||||||
attrList := elfAttributeList{data: subsectiondata}
|
continue
|
||||||
for !attrList.done() {
|
}
|
||||||
attr := attrList.armAttr()
|
attrList := elfAttributeList{data: subsectiondata}
|
||||||
if attr.tag == TagABIVFPArgs && attr.ival == 1 {
|
for !attrList.done() {
|
||||||
ehdr.flags = 0x5000402 // has entry point, Version5 EABI, hard-float ABI
|
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 attrList.err != nil {
|
||||||
|
// TODO(dfc) should this be ctxt.Diag ?
|
||||||
|
ctxt.Logf("could not parse .ARM.attributes\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -574,7 +574,7 @@ func (ctxt *Link) loadlib() {
|
|||||||
if typeSymbolMangling(ctxt) {
|
if typeSymbolMangling(ctxt) {
|
||||||
*FlagW = true // disable DWARF generation
|
*FlagW = true // disable DWARF generation
|
||||||
for _, s := range ctxt.Syms.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
newName := typeSymbolMangle(ctxt.Syms, s.Name)
|
newName := typeSymbolMangle(s.Name)
|
||||||
if newName != s.Name {
|
if newName != s.Name {
|
||||||
ctxt.Syms.Rename(s.Name, newName, int(s.Version))
|
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.
|
// 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.") {
|
if !strings.HasPrefix(name, "type.") {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,9 @@ func (ctxt *Link) FixedFrameSize() int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Link) Logf(format string, args ...interface{}) {
|
func (ctxt *Link) Logf(format string, args ...interface{}) {
|
||||||
fmt.Fprintf(l.Bso, format, args...)
|
fmt.Fprintf(ctxt.Bso, format, args...)
|
||||||
l.Bso.Flush()
|
ctxt.Bso.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func addImports(ctxt *Link, l *sym.Library, pn string) {
|
func addImports(ctxt *Link, l *sym.Library, pn string) {
|
||||||
|
@ -180,7 +180,7 @@ var nsortsym int
|
|||||||
// "big enough" header size. The initial header is
|
// "big enough" header size. The initial header is
|
||||||
// one page, the non-dynamic library stuff takes
|
// one page, the non-dynamic library stuff takes
|
||||||
// up about 1300 bytes; we overestimate that as 2k.
|
// 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 {
|
func getMachoHdr() *MachoHdr {
|
||||||
return &machohdr
|
return &machohdr
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
var realdwarf, linkseg *macho.Segment
|
var realdwarf, linkseg *macho.Segment
|
||||||
var dwarfstart, linkstart int64
|
var dwarfstart, linkstart int64
|
||||||
var dwarfaddr, linkaddr int64
|
var dwarfaddr int64
|
||||||
var linkoffset uint32
|
var linkoffset uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -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
|
var elfbind int
|
||||||
|
|
||||||
@ -592,7 +592,7 @@ func (ctxt *Link) symtab() {
|
|||||||
// pkghashes[i].name
|
// pkghashes[i].name
|
||||||
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkgname.%d", i), l.Pkg)
|
addgostring(ctxt, pkghashes, fmt.Sprintf("go.link.pkgname.%d", i), l.Pkg)
|
||||||
// pkghashes[i].linktimehash
|
// 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
|
// pkghashes[i].runtimehash
|
||||||
hash := ctxt.Syms.ROLookup("go.link.pkghash."+l.Pkg, 0)
|
hash := ctxt.Syms.ROLookup("go.link.pkghash."+l.Pkg, 0)
|
||||||
pkghashes.AddAddr(ctxt.Arch, hash)
|
pkghashes.AddAddr(ctxt.Arch, hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user