]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: initialize hash algs before typemap
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 4 Aug 2016 17:09:29 +0000 (13:09 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 4 Aug 2016 17:39:05 +0000 (17:39 +0000)
When compiling with -buildmode=shared, a map[int32]*_type is created for
each extra module mapping duplicate types back to a canonical object.
This is done in the function typelinksinit, which is called before the
init function that sets up the hash functions for the map
implementation. The result is typemap becomes unusable after
runtime initialization.

The fix in this CL is to move algorithm init before typelinksinit in
the runtime setup process. (For 1.8, we may want to turn typemap into
a sorted slice of types and use binary search.)

Manually tested on GOOS=linux with:

GOHOSTARCH=386 GOARCH=386 ./make.bash && \
go install -buildmode=shared std && \
cd ../test && \
go run run.go -linkshared

Fixes #16590

Change-Id: Idc08c50cc70d20028276fbf564509d2cd5405210
Reviewed-on: https://go-review.googlesource.com/25469
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/alg.go
src/runtime/proc.go

index 66943495b597456be62d50fed1f651f3db54bf88..147332e1fd93bbbdada9f7ef7277dbf905eba759 100644 (file)
@@ -289,7 +289,7 @@ var aeskeysched [hashRandomBytes]byte
 // used in hash{32,64}.go to seed the hash function
 var hashkey [4]uintptr
 
-func init() {
+func alginit() {
        // Install aes hash algorithm if we have the instructions we need
        if (GOARCH == "386" || GOARCH == "amd64") &&
                GOOS != "nacl" &&
index 1d00930ac5d312c05d43a3148786747fa951dbfe..e693f7e05f868a715e95094c8709f9d7d4e9a91a 100644 (file)
@@ -439,7 +439,8 @@ func schedinit() {
        stackinit()
        mallocinit()
        mcommoninit(_g_.m)
-       typelinksinit()
+       alginit()       // maps must not be used before this call
+       typelinksinit() // uses maps
        itabsinit()
 
        msigsave(_g_.m)