From 96b8f70e22e103c11fbb89ba6df9d229d24cdbc2 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Tue, 26 Apr 2016 10:53:25 -0400 Subject: [PATCH] cmd/link: correctly decode name length The linker was incorrectly decoding type name lengths, causing typelinks to be sorted out of order and in cases where the name was the exact right length, linker panics. Added a test to the reflect package that causes TestTypelinksSorted to fail before this CL. It's not the exact failure seen in #15448 but it has the same cause: decodetype_name calculating the wrong length. The equivalent decoders in reflect/type.go and runtime/type.go have the parenthesis in the right place. Fixes #15448 Change-Id: I33257633d812b7d2091393cb9d6cc8a73e0138c8 Reviewed-on: https://go-review.googlesource.com/22403 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick Reviewed-by: Russ Cox TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/decodesym.go | 2 +- src/reflect/all_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/decodesym.go b/src/cmd/link/internal/ld/decodesym.go index 3ec488bbe8..551ff802d7 100644 --- a/src/cmd/link/internal/ld/decodesym.go +++ b/src/cmd/link/internal/ld/decodesym.go @@ -239,7 +239,7 @@ func decodetype_name(s *LSym, off int) string { } data := r.Sym.P - namelen := int(uint16(data[1]<<8) | uint16(data[2])) + namelen := int(uint16(data[1])<<8 | uint16(data[2])) return string(data[3 : 3+namelen]) } diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index e88bc880e2..aff8ea253b 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -5651,6 +5651,8 @@ func TestChanAlloc(t *testing.T) { // allocs < 0.5 condition will trigger and this test should be fixed. } +type TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678 int + type nameTest struct { v interface{} want string @@ -5664,6 +5666,7 @@ var nameTests = []nameTest{ {(func() D1)(nil), ""}, {(<-chan D1)(nil), ""}, {(chan<- D1)(nil), ""}, + {TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678(0), "TheNameOfThisTypeIsExactly255BytesLongSoWhenTheCompilerPrependsTheReflectTestPackageNameAndExtraStarTheLinkerRuntimeAndReflectPackagesWillHaveToCorrectlyDecodeTheSecondLengthByte0123456789_0123456789_0123456789_0123456789_0123456789_012345678"}, } func TestNames(t *testing.T) { -- 2.48.1