]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: replace interface{} fields with concrete types
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 27 May 2015 00:04:25 +0000 (12:04 +1200)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 May 2015 04:03:32 +0000 (04:03 +0000)
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>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/macho.go
src/cmd/link/internal/ld/symtab.go
src/cmd/link/internal/x86/asm.go

index a4883f1a33c26244027c3c9ee72e2211c8db86e9..74ec9dd3ea6ef8dc5e98b91a8f25ae726f2ccc82 100644 (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
                }
        }
index e310d29e9af0e8948a01d0a6458fccef6ffa3e54..39d4550917b6a15a6172df53cfdf7153b7b87ce6 100644 (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
                }
        }
index 9d76f0e0c3c388b6a1a73948e4b9fedfd96f230a..3aebd8a2232efd27cbfae1702463cf54561337ee 100644 (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
                }
        }
index f9aacf0e196f0b594c7e6e765e6c2d23491dda0c..cf28e7b384645d96ce44879676414d541bd8df5b 100644 (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
index b73a75b59b5b7485f05519b9e0a83618dc50b212..d26a82e64a64c5f145fc595df22427845f406569 100644 (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)
index 80c01538ac1a83f503df528e8cc3fbf6ab02b629..ea82ea5995fff1c0ffd03324cd8dce7d35996fbe 100644 (file)
@@ -162,7 +162,7 @@ type Section struct {
        Length  uint64
        Next    *Section
        Seg     *Segment
-       Elfsect interface{}
+       Elfsect *ElfShdr
        Reloff  uint64
        Rellen  uint64
 }
index 3098147819f118f321753e948cbf846112f7a534..4b034a4e81cb117fce159ed82c2c4d365c776f7c 100644 (file)
@@ -78,7 +78,7 @@ type LSym struct {
        File        string
        Dynimplib   string
        Dynimpvers  string
-       Sect        interface{}
+       Sect        *Section
        Autom       *Auto
        Pcln        *Pcln
        P           []byte
index 0258aff10452c2b16e7b1a635b369a2bcb295713..3a8a881d97beecf5e1114e51095248dd5eb207ab 100644 (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)
index ca6654193510502ae9bbfc33285d0ae85772242a..12476f79a29e6ee50d4ac51624aa7e1f2f1327b8 100644 (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 {
index 7bb99ca8b5eee1a4f8d47180ab78e5391fbe33b1..d30bd48b4e61d60f3016a58a6b2269802a6000a5 100644 (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
                }
        }