if t.Sym == nil && len(methods(t)) == 0 {
return 0
}
- return 2 * Widthptr
+ return 4 + 2 + 2
}
func makefield(name string, t *Type) *Field {
// 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
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)
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
}
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 {
// 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)
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
// 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.
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.
if !pname.isExported() {
m.PkgPath = pname.pkgPath()
if m.PkgPath == "" {
- m.PkgPath = ut.pkgPath.name()
+ m.PkgPath = t.nameOff(ut.pkgPath).name()
}
fl |= flagStickyRO
}
}
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 {
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)
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 {
}
type uncommontype struct {
- pkgpath name
+ pkgpath nameOff
mcount uint16 // number of methods
moff uint16 // offset from this uncommontype to [mcount]method
}
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
}
}