Skip to content

Commit ddfc32d

Browse files
committed
ir: Use the mangling hack in win32 too.
Fixes #593 Fixes #728
1 parent 5444bab commit ddfc32d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/ir/function.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> {
109109
}
110110
}
111111

112-
// Mac os needs __ for mangled symbols but rust will automatically prepend the extra _.
113-
// We need to make sure that we don't include __ because rust will turn into ___.
112+
// Mac os and Win32 need __ for mangled symbols but rust will automatically
113+
// prepend the extra _.
114114
//
115-
// TODO(emilio): This is wrong when the target system is not the host
116-
// system. See https://github.com/servo/rust-bindgen/issues/593
117-
fn macos_mangling(symbol: &mut String) {
118-
if cfg!(target_os = "macos") && symbol.starts_with("_") {
115+
// We need to make sure that we don't include __ because rust will turn into
116+
// ___.
117+
fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) {
118+
// NB: win64 also contains the substring "win32" in the target triple, so
119+
// we need to actually check for i686...
120+
if ctx.target().contains("macos") ||
121+
(ctx.target().contains("i686") && ctx.target().contains("windows")) {
119122
symbol.remove(0);
120123
}
121124
}
@@ -138,7 +141,7 @@ pub fn cursor_mangling(ctx: &BindgenContext,
138141

139142
if let Ok(mut manglings) = cursor.cxx_manglings() {
140143
if let Some(mut m) = manglings.pop() {
141-
macos_mangling(&mut m);
144+
mangling_hack_if_needed(ctx, &mut m);
142145
return Some(m);
143146
}
144147
}
@@ -148,7 +151,7 @@ pub fn cursor_mangling(ctx: &BindgenContext,
148151
return None;
149152
}
150153

151-
macos_mangling(&mut mangling);
154+
mangling_hack_if_needed(ctx, &mut mangling);
152155

153156
if cursor.kind() == clang_sys::CXCursor_Destructor {
154157
// With old (3.8-) libclang versions, and the Itanium ABI, clang returns

0 commit comments

Comments
 (0)