]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile, etc: use nameOff in uncommonType
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 8 Apr 2016 01:37:45 +0000 (21:37 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 22 Apr 2016 13:51:29 +0000 (13:51 +0000)
linux/amd64 PIE:
cmd/go:  -62KB (0.5%)
jujud:  -550KB (0.7%)

For #6853.

Change-Id: Ieb67982abce5832e24b997506f0ae7108f747108
Reviewed-on: https://go-review.googlesource.com/22371
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/cmd/link/internal/ld/decodesym.go
src/cmd/link/internal/ld/symtab.go
src/reflect/type.go
src/runtime/heapdump.go
src/runtime/iface.go
src/runtime/type.go

index 1643c2ce4b3220b0295f4415535f7c8a1a6a12d9..3cd769fd2d96cb05543d59d96526ed4c9f57688b 100644 (file)
@@ -75,7 +75,7 @@ func uncommonSize(t *Type) int { // Sizeof(runtime.uncommontype{})
        if t.Sym == nil && len(methods(t)) == 0 {
                return 0
        }
-       return 2 * Widthptr
+       return 4 + 2 + 2
 }
 
 func makefield(name string, t *Type) *Field {
@@ -463,6 +463,9 @@ func dgopkgpathLSym(s *obj.LSym, ot int, pkg *Pkg) int {
 
 // dgopkgpathOffLSym writes an offset relocation in s at offset ot to the pkg path symbol.
 func dgopkgpathOffLSym(s *obj.LSym, ot int, pkg *Pkg) int {
+       if pkg == nil {
+               return duintxxLSym(s, ot, 0, 4)
+       }
        if pkg == localpkg && myimportpath == "" {
                // If we don't know the full import path of the package being compiled
                // (i.e. -p was not passed on the compiler command line), emit a reference to
@@ -597,12 +600,9 @@ func dextratype(s *Sym, ot int, t *Type, dataAdd int) int {
                dtypesym(a.type_)
        }
 
-       ot = dgopkgpath(s, ot, typePkg(t))
+       ot = dgopkgpathOffLSym(Linksym(s), ot, typePkg(t))
 
-       dataAdd += Widthptr + 2 + 2
-       if Widthptr == 8 {
-               dataAdd += 4
-       }
+       dataAdd += 4 + 2 + 2
        mcount := len(m)
        if mcount != int(uint16(mcount)) {
                Fatalf("too many methods on %s: %d", t, mcount)
@@ -613,9 +613,6 @@ func dextratype(s *Sym, ot int, t *Type, dataAdd int) int {
 
        ot = duint16(s, ot, uint16(mcount))
        ot = duint16(s, ot, uint16(dataAdd))
-       if Widthptr == 8 {
-               ot = duint32(s, ot, 0) // align for following pointers
-       }
        return ot
 }
 
index 330aa6dc13c3e0e69e37832c267def48877acaba..3ec488bbe8da0fd23e367aecc5a47cc33d338363 100644 (file)
@@ -61,7 +61,7 @@ func decode_inuxi(p []byte, sz int) uint64 {
 
 func commonsize() int      { return 4*SysArch.PtrSize + 8 + 8 } // runtime._type
 func structfieldSize() int { return 3 * SysArch.PtrSize }       // runtime.structfield
-func uncommonSize() int    { return 2 * SysArch.PtrSize }       // runtime.uncommontype
+func uncommonSize() int    { return 4 + 2 + 2 }                 // runtime.uncommontype
 
 // Type.commonType.kind
 func decodetype_kind(s *LSym) uint8 {
@@ -361,8 +361,8 @@ func decodetype_methods(s *LSym) []methodsig {
                // just Sizeof(rtype)
        }
 
-       mcount := int(decode_inuxi(s.P[off+SysArch.PtrSize:], 2))
-       moff := int(decode_inuxi(s.P[off+SysArch.PtrSize+2:], 2))
+       mcount := int(decode_inuxi(s.P[off+4:], 2))
+       moff := int(decode_inuxi(s.P[off+4+2:], 2))
        off += moff                // offset to array of reflect.method values
        const sizeofMethod = 4 * 4 // sizeof reflect.method in program
        return decode_methodsig(s, off, sizeofMethod, mcount)
index acc238f69829beb0c92857be89c61419205e29ab..94a6d0ab290087ef979693d394f73b36d2eb0576 100644 (file)
@@ -435,6 +435,11 @@ func symtab() {
                                s.Outer = symtype
                        }
 
+               case strings.HasPrefix(s.Name, "go.importpath.") && UseRelro():
+                       // Keep go.importpath symbols in the same section as types and
+                       // names, as they can be referred to by a section offset.
+                       s.Type = obj.STYPERELRO
+
                case strings.HasPrefix(s.Name, "go.typelink."):
                        ntypelinks++
                        s.Type = obj.STYPELINK
index b1758e6913d44af5487c1538e34cc0b73ac41242..ff6ff14c836cac0b76cf5e2f4dde9b49a25bbeb7 100644 (file)
@@ -311,9 +311,9 @@ type method struct {
 // Using a pointer to this struct reduces the overall size required
 // to describe an unnamed type with no methods.
 type uncommonType struct {
-       pkgPath name   // import path; empty for built-in types like int, string
-       mcount  uint16 // number of methods
-       moff    uint16 // offset from this uncommontype to [mcount]method
+       pkgPath nameOff // import path; empty for built-in types like int, string
+       mcount  uint16  // number of methods
+       moff    uint16  // offset from this uncommontype to [mcount]method
 }
 
 // ChanDir represents a channel type's direction.
@@ -613,13 +613,6 @@ func (t *uncommonType) methods() []method {
        return (*[1 << 16]method)(add(unsafe.Pointer(t), uintptr(t.moff)))[:t.mcount:t.mcount]
 }
 
-func (t *uncommonType) PkgPath() string {
-       if t == nil {
-               return ""
-       }
-       return t.pkgPath.name()
-}
-
 // resolveNameOff resolves a name offset from a base pointer.
 // The (*rtype).nameOff method is a convenience wrapper for this function.
 // Implemented in the runtime package.
@@ -799,7 +792,7 @@ func (t *rtype) Method(i int) (m Method) {
        if !pname.isExported() {
                m.PkgPath = pname.pkgPath()
                if m.PkgPath == "" {
-                       m.PkgPath = ut.pkgPath.name()
+                       m.PkgPath = t.nameOff(ut.pkgPath).name()
                }
                fl |= flagStickyRO
        }
@@ -846,7 +839,11 @@ func (t *rtype) MethodByName(name string) (m Method, ok bool) {
 }
 
 func (t *rtype) PkgPath() string {
-       return t.uncommon().PkgPath()
+       ut := t.uncommon()
+       if ut == nil {
+               return ""
+       }
+       return t.nameOff(ut.pkgPath).name()
 }
 
 func hasPrefix(s, prefix string) bool {
index 1db29d7cb497dc582ddb39ec1ef94f24b6657b63..0afab0909511ceb8cfe7676079fd6ba7f5f483d3 100644 (file)
@@ -183,10 +183,10 @@ func dumptype(t *_type) {
        dumpint(tagType)
        dumpint(uint64(uintptr(unsafe.Pointer(t))))
        dumpint(uint64(t.size))
-       if x := t.uncommon(); x == nil || x.pkgpath.name() == "" {
+       if x := t.uncommon(); x == nil || t.nameOff(x.pkgpath).name() == "" {
                dumpstr(t.string())
        } else {
-               pkgpathstr := x.pkgpath.name()
+               pkgpathstr := t.nameOff(x.pkgpath).name()
                pkgpath := stringStructOf(&pkgpathstr)
                namestr := t.name()
                name := stringStructOf(&namestr)
index 007c1ed17489728ecba776280a23e7c39bad93ce..b57d1cc63c3e8b32fec2a4c9c4b071aa2f15b11e 100644 (file)
@@ -112,7 +112,7 @@ func additab(m *itab, locked, canfail bool) {
                        if typ.typeOff(t.mtyp) == itype && tname.name() == iname {
                                pkgPath := tname.pkgPath()
                                if pkgPath == "" {
-                                       pkgPath = x.pkgpath.name()
+                                       pkgPath = typ.nameOff(x.pkgpath).name()
                                }
                                if tname.isExported() || pkgPath == ipkg {
                                        if m != nil {
index 0b28fa6d434085aa35810104288dd7a7e7fd91a9..9e4c40553a40672982b322888b0dd18d1c87612f 100644 (file)
@@ -304,7 +304,7 @@ type method struct {
 }
 
 type uncommontype struct {
-       pkgpath name
+       pkgpath nameOff
        mcount  uint16 // number of methods
        moff    uint16 // offset from this uncommontype to [mcount]method
 }
@@ -524,7 +524,9 @@ func typesEqual(t, v *_type) bool {
                if ut == nil || uv == nil {
                        return false
                }
-               if ut.pkgpath.name() != uv.pkgpath.name() {
+               pkgpatht := t.nameOff(ut.pkgpath).name()
+               pkgpathv := v.nameOff(uv.pkgpath).name()
+               if pkgpatht != pkgpathv {
                        return false
                }
        }