summaryrefslogtreecommitdiff
path: root/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go')
-rw-r--r--vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go
index f7c0450ae..e49353dc8 100644
--- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go
+++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go
@@ -31,6 +31,13 @@ func fileCacheKey(m *wasm.Module) (ret filecache.Key) {
s := sha256.New()
s.Write(m.ID[:])
s.Write(magic)
+ // Write the CPU features so that we can cache the compiled module for the same CPU.
+ // This prevents the incompatible CPU features from being used.
+ cpu := platform.CpuFeatures.Raw()
+ // Reuse the `ret` buffer to write the first 8 bytes of the CPU features so that we can avoid the allocation.
+ binary.LittleEndian.PutUint64(ret[:8], cpu)
+ s.Write(ret[:8])
+ // Finally, write the hash to the ret buffer.
s.Sum(ret[:0])
return
}