]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: when dynlinking, do not mangle short symbol names
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Thu, 11 Aug 2016 22:31:17 +0000 (10:31 +1200)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 16 Aug 2016 00:37:09 +0000 (00:37 +0000)
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 <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/link/internal/ld/objfile.go

index be9832dc45483031e7a489af5356b32fa2cae830..4db6489d002db0a5b6b0e450a891a8183105118e 100644 (file)
@@ -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] == '.' {