@@ -110,6 +110,17 @@ fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> {
110
110
}
111
111
}
112
112
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
+
113
124
/// Get the mangled name for the cursor's referent.
114
125
pub fn cursor_mangling ( ctx : & BindgenContext ,
115
126
cursor : & clang:: Cursor )
@@ -127,7 +138,8 @@ pub fn cursor_mangling(ctx: &BindgenContext,
127
138
}
128
139
129
140
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) ;
131
143
return Some ( m) ;
132
144
}
133
145
}
@@ -137,13 +149,7 @@ pub fn cursor_mangling(ctx: &BindgenContext,
137
149
return None ;
138
150
}
139
151
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) ;
147
153
148
154
if cursor. kind ( ) == clang_sys:: CXCursor_Destructor {
149
155
// With old (3.8-) libclang versions, and the Itanium ABI, clang returns
0 commit comments