Skip to content
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

Mismatched wasm output on darwin vs Ubuntu #97919

Open
nmattia opened this issue Jun 9, 2022 · 5 comments
Open

Mismatched wasm output on darwin vs Ubuntu #97919

nmattia opened this issue Jun 9, 2022 · 5 comments
Labels
A-reproducibility Area: Reproducible / Deterministic builds C-bug Category: This is a bug.

Comments

@nmattia
Copy link

nmattia commented Jun 9, 2022

I tried this code:

// Crate A
use std::cell::{RefCell};
use std::collections::HashMap;

use internet_identity_interface as other;

#[export_name = "the name"]
fn dummy()
{
    let _err_info = "hello".to_string(); // Removing this makes the outputs match

    other::unreachable(); // Calling unreachable! from this crate makes the outputs match
}


pub type SomeType = u8; // Inlining 'u8' in the ASSETS below makes the outputs match

thread_local! {
    static ASSETS: RefCell<HashMap<&'static str, (Vec<SomeType>, &'static [u8])>> = RefCell::new(HashMap::default());
}

fn main() {}
// Crate B ("other")
pub fn unreachable() {
    unreachable!();
}

When building using the wasm32-unknown-unknown target, I expect the output to be the same on Ubuntu and macOS. Instead, I'm getting different outputs. I've tried on different Ubuntu and macOS versions, and the output is consistent across all versions of the same platform. What's really odd is that the slightest various of the code above makes the output match again.

This is the command I use to build:

cargo build --manifest-path ./src/path/to/Crate/A/Cargo.toml --target wasm32-unknown-unknown --release -j1

This could be a cargo issue, I'm not sure of what's happening under the hood.

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-apple-darwin
release: 1.58.1
LLVM version: 13.0.0

---

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
@nmattia nmattia added the C-bug Category: This is a bug. label Jun 9, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 9, 2022

When you refer to "matching outputs" do you mean the compiled wasm binaries?

I don't think rustc guarantees binary stability between compilations performed on the same machine, let alone those performed on different host platforms.

@nagisa nagisa added the A-reproducibility Area: Reproducible / Deterministic builds label Jun 10, 2022
@nagisa
Copy link
Member

nagisa commented Jun 10, 2022

Rust does not guarantee reproducible builds between compilers built from different commits, but you should be able to rely on getting reproducible builds given the same target, same toolchain versions and some --remap-path-prefix action.


Are you sure this isn't just an example of some host paths leaking into the wasm output?

@nmattia
Copy link
Author

nmattia commented Jun 23, 2022

When you refer to "matching outputs" do you mean the compiled wasm binaries?

Yes!

Are you sure this isn't just an example of some host paths leaking into the wasm output?

Maybe, but when I looked at the wasm (or rather .wat) code there seemed to be differences in the code itself, not just the strings. Will have another go at it with --remap-path-prefix!

@shkoo
Copy link
Contributor

shkoo commented Jul 1, 2022

Is "B" specified by relative path? It doesn't look like you included your Cargo.toml.

If it's specified by relative path my #98185 might be a duplicate of this issue.

@mraszyk
Copy link

mraszyk commented Jul 19, 2022

Building this (simpler) library also results in mismatching WASM hashes on Ubuntu and macOS:

#[no_mangle]
pub fn greet(name: i32) -> usize {
  aux(name.to_string()).len()
}

fn aux(x: String) -> String {
  format!("Hello, {}", x)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reproducibility Area: Reproducible / Deterministic builds C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants