From b5e43e669a5e1591c9a6c7157b4dd0d2796d3037 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 12 Aug 2016 10:31:17 +1200 Subject: [PATCH] cmd/link: when dynlinking, do not mangle short symbol names When dynamically linking, a type symbol's name is replaced with a name based on the SHA1 of the name as type symbol's names can be very long. However, this can make a type's symbol name longer in some cases. So skip it in that case. One of the symbols this changes the treatment of is 'type.string' and that fixes a bug where -X doesn't work when dynamically linking. Fixes #16671 Change-Id: If5269038261b76fb0ec52e25a9c1d64129631e3c Reviewed-on: https://go-review.googlesource.com/26890 Run-TryBot: Michael Hudson-Doyle TryBot-Result: Gobot Gobot Reviewed-by: David Crawshaw --- src/cmd/link/internal/ld/objfile.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/objfile.go b/src/cmd/link/internal/ld/objfile.go index be9832dc45..4db6489d00 100644 --- a/src/cmd/link/internal/ld/objfile.go +++ b/src/cmd/link/internal/ld/objfile.go @@ -564,8 +564,10 @@ func (r *objReader) readSymName() string { // 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.") { + // other parts of the linker manipulates them, + // and also symbols whose names would not be + // shortened by this process. + if len(s) > 14 && strings.HasPrefix(s, "type.") && !strings.HasPrefix(s, "type.runtime.") { hash := sha1.Sum([]byte(s)) prefix := "type." if s[5] == '.' { -- 2.48.1