diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-01 14:24:38 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-01 14:50:35 +0200 |
commit | ddfc32d9e304a5179f3474b2732da97612cc7637 (patch) | |
tree | bfb09a4d2ed908cdd34783b287afbeced2002ba7 | |
parent | 5444bab8ecd2c702442e412012f5fb7c415b92b4 (diff) |
ir: Use the mangling hack in win32 too.
Fixes #593
Fixes #728
-rw-r--r-- | src/ir/function.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs index 10a791d8..30f76944 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -109,13 +109,16 @@ fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> { } } -// Mac os needs __ for mangled symbols but rust will automatically prepend the extra _. -// We need to make sure that we don't include __ because rust will turn into ___. +// Mac os and Win32 need __ for mangled symbols but rust will automatically +// prepend the extra _. // -// TODO(emilio): This is wrong when the target system is not the host -// system. See https://github.com/servo/rust-bindgen/issues/593 -fn macos_mangling(symbol: &mut String) { - if cfg!(target_os = "macos") && symbol.starts_with("_") { +// We need to make sure that we don't include __ because rust will turn into +// ___. +fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) { + // NB: win64 also contains the substring "win32" in the target triple, so + // we need to actually check for i686... + if ctx.target().contains("macos") || + (ctx.target().contains("i686") && ctx.target().contains("windows")) { symbol.remove(0); } } @@ -138,7 +141,7 @@ pub fn cursor_mangling(ctx: &BindgenContext, if let Ok(mut manglings) = cursor.cxx_manglings() { if let Some(mut m) = manglings.pop() { - macos_mangling(&mut m); + mangling_hack_if_needed(ctx, &mut m); return Some(m); } } @@ -148,7 +151,7 @@ pub fn cursor_mangling(ctx: &BindgenContext, return None; } - macos_mangling(&mut mangling); + mangling_hack_if_needed(ctx, &mut mangling); if cursor.kind() == clang_sys::CXCursor_Destructor { // With old (3.8-) libclang versions, and the Itanium ABI, clang returns |