From e1e80a9b7eb8c8d6d2b77f4fcd4e6c8ce1d5cac2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 Jul 2018 13:44:41 -0700 Subject: [PATCH] Work around #483 This commit adds a hack to the `wasm-bindgen` CLI tool to work around #483 which is present on nightly Rust with the recent LLVM upgrade. Hopefully this'll carry us forward until the [upstream bug][1] is fixed. Closes #483 [1]: https://bugs.llvm.org/show_bug.cgi?id=38184 --- crates/cli-support/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index a9a88769..353866f4 100644 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -291,6 +291,7 @@ fn extract_programs(module: &mut Module) -> Result, Error> to_remove.push(i); let mut payload = custom.payload(); + let mut added_programs = Vec::new(); while payload.len() > 0 { let len = ((payload[0] as usize) << 0) | ((payload[1] as usize) << 8) @@ -298,6 +299,20 @@ fn extract_programs(module: &mut Module) -> Result, Error> | ((payload[3] as usize) << 24); let (a, b) = payload[4..].split_at(len as usize); payload = b; + + // Due to a nasty LLVM bug it's currently possible for LLVM to + // duplicate custom section directives in intermediate object files. + // This means that we could see multiple program directives when in + // fact we were originally only meant to see one! + // + // Work around the issue here until the upstream bug, + // https://bugs.llvm.org/show_bug.cgi?id=38184, is hopefully fixed + // via some other means. + if added_programs.iter().any(|p| a == *p) { + continue + } + added_programs.push(a); + let p: shared::ProgramOnlySchema = match serde_json::from_slice(&a) { Ok(f) => f, Err(e) => bail!("failed to decode what looked like wasm-bindgen data: {}", e),