1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

cmd/link: replace interface{} fields with concrete types

The LSym.Section and Section.Elfsect fields were defined as interface{} but
always had the same concrete type (*Section and *ElfShdr respectively) so just
define them with that type. Reduces size of LSym from 328 to 320 bytes and
reduces best-of-10 maxresident size from 246028k to 238036k when linking
libstd.so.

Change-Id: Ie7112c53e4c2c7ce5fe233b81372aa5633f572e8
Reviewed-on: https://go-review.googlesource.com/10410
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2015-05-27 12:04:25 +12:00 committed by Ian Lance Taylor
parent bc89ad598e
commit cf2736c4c5
10 changed files with 18 additions and 18 deletions

View File

@ -405,9 +405,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32((rs.Sect.(*ld.Section)).Extnum)
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, (rs.Sect.(*ld.Section)).Name, rs.Type)
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}

View File

@ -279,9 +279,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32((rs.Sect.(*ld.Section)).Extnum)
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, (rs.Sect.(*ld.Section)).Name, rs.Type)
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}

View File

@ -107,9 +107,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32((rs.Sect.(*ld.Section)).Extnum)
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, (rs.Sect.(*ld.Section)).Name, rs.Type)
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}

View File

@ -522,7 +522,7 @@ func relocsym(s *LSym) {
} else if HEADTYPE == obj.Hdarwin {
if r.Type == obj.R_CALL {
if rs.Type != obj.SHOSTOBJ {
o += int64(uint64(Symaddr(rs)) - (rs.Sect.(*Section)).Vaddr)
o += int64(uint64(Symaddr(rs)) - rs.Sect.Vaddr)
}
o -= int64(r.Off) // relative to section offset, not symbol
} else {
@ -534,7 +534,7 @@ func relocsym(s *LSym) {
o += int64(r.Siz)
// GNU ld always add VirtualAddress of the .text section to the
// relocated address, compensate that.
o -= int64(s.Sect.(*Section).Vaddr - PEBASE)
o -= int64(s.Sect.Vaddr - PEBASE)
} else {
Diag("unhandled pcrel relocation for %s", headstring)
}
@ -1681,7 +1681,7 @@ func address() {
for sym := datap; sym != nil; sym = sym.Next {
Ctxt.Cursym = sym
if sym.Sect != nil {
sym.Value += int64((sym.Sect.(*Section)).Vaddr)
sym.Value += int64(sym.Sect.Vaddr)
}
for sub = sym.Sub; sub != nil; sub = sub.Sub {
sub.Value += sym.Value

View File

@ -1517,7 +1517,7 @@ func elfshreloc(sect *Section) *ElfShdr {
sh.entsize += uint64(Thearch.Regsize)
}
sh.link = uint32(elfshname(".symtab").shnum)
sh.info = uint32((sect.Elfsect.(*ElfShdr)).shnum)
sh.info = uint32(sect.Elfsect.shnum)
sh.off = sect.Reloff
sh.size = sect.Rellen
sh.addralign = uint64(Thearch.Regsize)

View File

@ -162,7 +162,7 @@ type Section struct {
Length uint64
Next *Section
Seg *Segment
Elfsect interface{}
Elfsect *ElfShdr
Reloff uint64
Rellen uint64
}

View File

@ -78,7 +78,7 @@ type LSym struct {
File string
Dynimplib string
Dynimpvers string
Sect interface{}
Sect *Section
Autom *Auto
Pcln *Pcln
P []byte

View File

@ -706,7 +706,7 @@ func machosymtab() {
Diag("missing section for %s", s.Name)
Adduint8(Ctxt, symtab, 0)
} else {
Adduint8(Ctxt, symtab, uint8((o.Sect.(*Section)).Extnum))
Adduint8(Ctxt, symtab, uint8(o.Sect.Extnum))
}
Adduint16(Ctxt, symtab, 0) // desc
adduintxx(Ctxt, symtab, uint64(Symaddr(s)), Thearch.Ptrsize)

View File

@ -132,12 +132,12 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L
Diag("missing section in putelfsym")
return
}
if xo.Sect.(*Section).Elfsect == nil {
if xo.Sect.Elfsect == nil {
Ctxt.Cursym = x
Diag("missing ELF section in putelfsym")
return
}
elfshnum = xo.Sect.(*Section).Elfsect.(*ElfShdr).shnum
elfshnum = xo.Sect.Elfsect.shnum
}
// One pass for each binding: STB_LOCAL, STB_GLOBAL,
@ -163,7 +163,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L
off := putelfstr(s)
if Linkmode == LinkExternal && elfshnum != SHN_UNDEF {
addr -= int64(xo.Sect.(*Section).Vaddr)
addr -= int64(xo.Sect.Vaddr)
}
other := STV_DEFAULT
if x.Type&obj.SHIDDEN != 0 {

View File

@ -276,9 +276,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
v = uint32(rs.Dynid)
v |= 1 << 27 // external relocation
} else {
v = uint32((rs.Sect.(*ld.Section)).Extnum)
v = uint32(rs.Sect.Extnum)
if v == 0 {
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, (rs.Sect.(*ld.Section)).Name, rs.Type)
ld.Diag("reloc %d to symbol %s in non-macho section %s type=%d", r.Type, rs.Name, rs.Sect.Name, rs.Type)
return -1
}
}