mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
bc89ad598e
commit
cf2736c4c5
10 changed files with 18 additions and 18 deletions
|
|
@ -405,9 +405,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
|
||||||
v = uint32(rs.Dynid)
|
v = uint32(rs.Dynid)
|
||||||
v |= 1 << 27 // external relocation
|
v |= 1 << 27 // external relocation
|
||||||
} else {
|
} else {
|
||||||
v = uint32((rs.Sect.(*ld.Section)).Extnum)
|
v = uint32(rs.Sect.Extnum)
|
||||||
if v == 0 {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -279,9 +279,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
|
||||||
v = uint32(rs.Dynid)
|
v = uint32(rs.Dynid)
|
||||||
v |= 1 << 27 // external relocation
|
v |= 1 << 27 // external relocation
|
||||||
} else {
|
} else {
|
||||||
v = uint32((rs.Sect.(*ld.Section)).Extnum)
|
v = uint32(rs.Sect.Extnum)
|
||||||
if v == 0 {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,9 +107,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
|
||||||
v = uint32(rs.Dynid)
|
v = uint32(rs.Dynid)
|
||||||
v |= 1 << 27 // external relocation
|
v |= 1 << 27 // external relocation
|
||||||
} else {
|
} else {
|
||||||
v = uint32((rs.Sect.(*ld.Section)).Extnum)
|
v = uint32(rs.Sect.Extnum)
|
||||||
if v == 0 {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -522,7 +522,7 @@ func relocsym(s *LSym) {
|
||||||
} else if HEADTYPE == obj.Hdarwin {
|
} else if HEADTYPE == obj.Hdarwin {
|
||||||
if r.Type == obj.R_CALL {
|
if r.Type == obj.R_CALL {
|
||||||
if rs.Type != obj.SHOSTOBJ {
|
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
|
o -= int64(r.Off) // relative to section offset, not symbol
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -534,7 +534,7 @@ func relocsym(s *LSym) {
|
||||||
o += int64(r.Siz)
|
o += int64(r.Siz)
|
||||||
// GNU ld always add VirtualAddress of the .text section to the
|
// GNU ld always add VirtualAddress of the .text section to the
|
||||||
// relocated address, compensate that.
|
// relocated address, compensate that.
|
||||||
o -= int64(s.Sect.(*Section).Vaddr - PEBASE)
|
o -= int64(s.Sect.Vaddr - PEBASE)
|
||||||
} else {
|
} else {
|
||||||
Diag("unhandled pcrel relocation for %s", headstring)
|
Diag("unhandled pcrel relocation for %s", headstring)
|
||||||
}
|
}
|
||||||
|
|
@ -1681,7 +1681,7 @@ func address() {
|
||||||
for sym := datap; sym != nil; sym = sym.Next {
|
for sym := datap; sym != nil; sym = sym.Next {
|
||||||
Ctxt.Cursym = sym
|
Ctxt.Cursym = sym
|
||||||
if sym.Sect != nil {
|
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 {
|
for sub = sym.Sub; sub != nil; sub = sub.Sub {
|
||||||
sub.Value += sym.Value
|
sub.Value += sym.Value
|
||||||
|
|
|
||||||
|
|
@ -1517,7 +1517,7 @@ func elfshreloc(sect *Section) *ElfShdr {
|
||||||
sh.entsize += uint64(Thearch.Regsize)
|
sh.entsize += uint64(Thearch.Regsize)
|
||||||
}
|
}
|
||||||
sh.link = uint32(elfshname(".symtab").shnum)
|
sh.link = uint32(elfshname(".symtab").shnum)
|
||||||
sh.info = uint32((sect.Elfsect.(*ElfShdr)).shnum)
|
sh.info = uint32(sect.Elfsect.shnum)
|
||||||
sh.off = sect.Reloff
|
sh.off = sect.Reloff
|
||||||
sh.size = sect.Rellen
|
sh.size = sect.Rellen
|
||||||
sh.addralign = uint64(Thearch.Regsize)
|
sh.addralign = uint64(Thearch.Regsize)
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ type Section struct {
|
||||||
Length uint64
|
Length uint64
|
||||||
Next *Section
|
Next *Section
|
||||||
Seg *Segment
|
Seg *Segment
|
||||||
Elfsect interface{}
|
Elfsect *ElfShdr
|
||||||
Reloff uint64
|
Reloff uint64
|
||||||
Rellen uint64
|
Rellen uint64
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ type LSym struct {
|
||||||
File string
|
File string
|
||||||
Dynimplib string
|
Dynimplib string
|
||||||
Dynimpvers string
|
Dynimpvers string
|
||||||
Sect interface{}
|
Sect *Section
|
||||||
Autom *Auto
|
Autom *Auto
|
||||||
Pcln *Pcln
|
Pcln *Pcln
|
||||||
P []byte
|
P []byte
|
||||||
|
|
|
||||||
|
|
@ -706,7 +706,7 @@ func machosymtab() {
|
||||||
Diag("missing section for %s", s.Name)
|
Diag("missing section for %s", s.Name)
|
||||||
Adduint8(Ctxt, symtab, 0)
|
Adduint8(Ctxt, symtab, 0)
|
||||||
} else {
|
} else {
|
||||||
Adduint8(Ctxt, symtab, uint8((o.Sect.(*Section)).Extnum))
|
Adduint8(Ctxt, symtab, uint8(o.Sect.Extnum))
|
||||||
}
|
}
|
||||||
Adduint16(Ctxt, symtab, 0) // desc
|
Adduint16(Ctxt, symtab, 0) // desc
|
||||||
adduintxx(Ctxt, symtab, uint64(Symaddr(s)), Thearch.Ptrsize)
|
adduintxx(Ctxt, symtab, uint64(Symaddr(s)), Thearch.Ptrsize)
|
||||||
|
|
|
||||||
|
|
@ -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")
|
Diag("missing section in putelfsym")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if xo.Sect.(*Section).Elfsect == nil {
|
if xo.Sect.Elfsect == nil {
|
||||||
Ctxt.Cursym = x
|
Ctxt.Cursym = x
|
||||||
Diag("missing ELF section in putelfsym")
|
Diag("missing ELF section in putelfsym")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
elfshnum = xo.Sect.(*Section).Elfsect.(*ElfShdr).shnum
|
elfshnum = xo.Sect.Elfsect.shnum
|
||||||
}
|
}
|
||||||
|
|
||||||
// One pass for each binding: STB_LOCAL, STB_GLOBAL,
|
// 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)
|
off := putelfstr(s)
|
||||||
if Linkmode == LinkExternal && elfshnum != SHN_UNDEF {
|
if Linkmode == LinkExternal && elfshnum != SHN_UNDEF {
|
||||||
addr -= int64(xo.Sect.(*Section).Vaddr)
|
addr -= int64(xo.Sect.Vaddr)
|
||||||
}
|
}
|
||||||
other := STV_DEFAULT
|
other := STV_DEFAULT
|
||||||
if x.Type&obj.SHIDDEN != 0 {
|
if x.Type&obj.SHIDDEN != 0 {
|
||||||
|
|
|
||||||
|
|
@ -276,9 +276,9 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
|
||||||
v = uint32(rs.Dynid)
|
v = uint32(rs.Dynid)
|
||||||
v |= 1 << 27 // external relocation
|
v |= 1 << 27 // external relocation
|
||||||
} else {
|
} else {
|
||||||
v = uint32((rs.Sect.(*ld.Section)).Extnum)
|
v = uint32(rs.Sect.Extnum)
|
||||||
if v == 0 {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue