diff --git a/src/cmd/link/internal/ld/objfile.go b/src/cmd/link/internal/ld/objfile.go index dffb7a3d9b..566c949040 100644 --- a/src/cmd/link/internal/ld/objfile.go +++ b/src/cmd/link/internal/ld/objfile.go @@ -112,6 +112,8 @@ import ( "bytes" "cmd/internal/bio" "cmd/internal/obj" + "crypto/sha1" + "encoding/base64" "io" "log" "strconv" @@ -555,6 +557,28 @@ func (r *objReader) readSymName() string { r.readFull(r.rdBuf[:n]) } r.rdBuf = adjName[:0] // in case 2*n wasn't enough + + if DynlinkingGo() { + // These types are included in the symbol + // table when dynamically linking. To keep + // binary size down, we replace the names + // with SHA-1 prefixes. + // + // Keep the type.. prefix, which parts of the + // linker (like the DWARF generator) know means + // the symbol is not decodable. + // + // Leave type.runtime. symbols alone, because + // other parts of the linker manipulates them. + if strings.HasPrefix(s, "type.") && !strings.HasPrefix(s, "type.runtime.") { + hash := sha1.Sum([]byte(s)) + prefix := "type." + if s[5] == '.' { + prefix = "type.." + } + s = prefix + base64.StdEncoding.EncodeToString(hash[:6]) + } + } return s } adjName = append(adjName, origName[:i]...)