Skip to content

Reproducible .wasm file builds #4772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kennu opened this issue Aug 12, 2022 · 5 comments
Closed

Reproducible .wasm file builds #4772

kennu opened this issue Aug 12, 2022 · 5 comments

Comments

@kennu
Copy link

kennu commented Aug 12, 2022

While I was building .wasm files with various languages (AssemblyScript, C, C++, C#, Go, Grain, Haskell, Motoko, Rust, Zig), I noticed that Swift is the only one that generates a different .wasm file after every build.

In practice, if you store .wasm files in Git or otherwise rely on change detection, you get a new version after every build, even if the source code didn't change.

This is not a big problem for me, but I thought I'd mention it, since it appears to be unique to Swift. Please feel free to close the issue if it's out of scope of the project.

@kennu
Copy link
Author

kennu commented Aug 12, 2022

With a hex dump, the difference is 16 bytes somewhere deep in the middle of the .wasm files:

diff 1.txt 2.txt       
295713c295713
< 22154160 20 fc 5f a5 fa 0f ef 97 26 dd cf b7 b2 d7 e9 60
---
> 22154160 e5 3b 7a d5 5b e6 4a 9e 7d 2f f0 d9 03 35 15 c5

@kateinoigakukun
Copy link
Member

Thank you for reporting :) The differential section is .swift_modhash, which is a metadata section for incremental compilation, but I'm not sure why it changes for every build.
As far as I checked, Swift toolchain for Linux also produce different hash for each build, so I guess it's not wasm specific problem.
But we should keep this track on apple/swift repository 👍

@ephemer
Copy link

ephemer commented Sep 29, 2022

I'm curious whether this also occurs during release builds?

@gregcotten
Copy link

@ephemer

Answer: yes

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Mar 1, 2024

--gc-sections support resolved this issue #5128 because it enabled GCing .swift_modhash section which is always unused at runtime. I've confirmed swift build emits exactly same binaries for the same inputs with the latest nightly toolchain https://github.com/swiftwasm/swift/releases/tag/swift-wasm-DEVELOPMENT-SNAPSHOT-2024-03-01-a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants