Skip to content

Commit 595b9a3

Browse files
author
bors-servo
authored
Auto merge of #717 - photoszzt:fix_osx_mangling, r=emilio
Fix osx mangling hack Rust automatically adds one _ in the symbol. If we don't remove it, we will endup getting three _. r? @emilio
2 parents 754d2f4 + 26b9143 commit 595b9a3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/ir/function.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> {
110110
}
111111
}
112112

113+
// Mac os needs __ for mangled symbols but rust will automatically prepend the extra _.
114+
// We need to make sure that we don't include __ because rust will turn into ___.
115+
//
116+
// TODO(emilio): This is wrong when the target system is not the host
117+
// system. See https://github.com/servo/rust-bindgen/issues/593
118+
fn macos_mangling(symbol: &mut String) {
119+
if cfg!(target_os = "macos") && symbol.starts_with("_") {
120+
symbol.remove(0);
121+
}
122+
}
123+
113124
/// Get the mangled name for the cursor's referent.
114125
pub fn cursor_mangling(ctx: &BindgenContext,
115126
cursor: &clang::Cursor)
@@ -127,7 +138,8 @@ pub fn cursor_mangling(ctx: &BindgenContext,
127138
}
128139

129140
if let Ok(mut manglings) = cursor.cxx_manglings() {
130-
if let Some(m) = manglings.pop() {
141+
if let Some(mut m) = manglings.pop() {
142+
macos_mangling(&mut m);
131143
return Some(m);
132144
}
133145
}
@@ -137,13 +149,7 @@ pub fn cursor_mangling(ctx: &BindgenContext,
137149
return None;
138150
}
139151

140-
// Try to undo backend linkage munging (prepended _, generally)
141-
//
142-
// TODO(emilio): This is wrong when the target system is not the host
143-
// system. See https://github.com/servo/rust-bindgen/issues/593
144-
if cfg!(target_os = "macos") {
145-
mangling.remove(0);
146-
}
152+
macos_mangling(&mut mangling);
147153

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

0 commit comments

Comments
 (0)