-
Notifications
You must be signed in to change notification settings - Fork 967
Open
Labels
Description
$ cat precomp.go
package main
import (
"crypto/sha256"
"fmt"
"os"
)
var (
tag = sha256.Sum256(nil)
globalMap = map[string][32]byte{
"": tag,
}
)
func main() {
localMap := map[string][32]byte{
"": tag,
}
if localMap[""] != globalMap[""] {
fmt.Printf("global %.32x\nlocal %.32x\n", globalMap, localMap)
os.Exit(1)
}
}
$ go run precomp.go
$ tinygo run precomp.go
global map[:0000000000000000000000000000000000000000000000000000000000000000]
local map[:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855]
failed to run compiled binary /tmp/nix-shell.HWhNg6/tinygo1488071277/main: exit status 1
This breaks anything relying on https://github.com/btcsuite/btcd/blob/67b8efd3ba53b60ff0eba5d79babe2c3d82f6c54/chaincfg/chainhash/hash.go#L50.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
dgryski commentedon Oct 7, 2024
Interestingly, switching the runtime hash to
tsip
allows this code to pass. I wonder if it's because interp decides not to run the tsip code for some reason.eliasnaur commentedon Nov 16, 2024
Can you say where to look into a fix, however hacky? This is a miscompilation of an external package that is impractical to change.
dgryski commentedon Nov 16, 2024
When building with
-tags=runtime_memhash_tsip
I see the following:So now at least we know why switching the hash function works.
dgryski commentedon Nov 16, 2024
Here's a simpler reproducer:
So what's happening here is that
sum()
function is unable to be interpreted atinterp
time and so is pushed off to runtime, but we're not holding off the construction of the map that depends on that value.So while we should probably add the rotate instructions to interp, the underlying issue is that the map initialization doens't seem to be reverted when one of the values used during construction is.
dgryski commentedon Nov 16, 2024
@niaow @aykevl I haven't done any work debugging
interp
, so any pointers here would be helpful.dkegel-fastly commentedon Nov 17, 2024
@eliasnaur You could disable interp as a hacky workaround...?