Skip to content

Compiling with debuginfo causes incorrect output on wasm32-unknown-unknown target #46339

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
Herschel opened this issue Nov 28, 2017 · 2 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@Herschel
Copy link
Contributor

Herschel commented Nov 28, 2017

The following example will incorrectly return 1 instead of 10 when compiling with the wasm32-unknown-unknown target and -C debuginfo=2:

fn add_one(i: i32) -> i32 {
	i + 1
}

#[no_mangle]
pub fn run() -> i32 {
	add_one(9)
}

HTML:

<!DOCTYPE html>

<html>
	<head>
		<title>Test</title>
		<script>
			fetch('lib.wasm')
				.then(response => response.arrayBuffer())
				.then(bytes => WebAssembly.instantiate(bytes, {
					'env': {}
				}))
				.then(results => {
				    console.log(results.instance.exports.run());
				});
		</script>
	</head>
	<body>
	</body>
</html>

rustc command:

rustc lib.rs --crate-type cdylib --target wasm32-unknown-unknown -C debuginfo=2

Removing -C debuginfo=2 gives the correct output

rustc version:
rustc 1.24.0-nightly (560a5da9f 2017-11-27)

@kennytm kennytm added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Nov 28, 2017
@alexcrichton
Copy link
Member

This looks to be an LLVM bug fixed in LLVM 5, the upgrade to which is tracked by #43370

@alexcrichton
Copy link
Member

Upon more recent testing I believe this isn't actually fixed in LLVM 5 (an LLVM assertion still trips). To help consolidate though I'm going to close this in favor of #46367 which I believe is the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

3 participants