@@ -131,10 +131,36 @@ pub fn cursor_mangling(ctx: &BindgenContext,
131
131
}
132
132
133
133
// Try to undo backend linkage munging (prepended _, generally)
134
+ //
135
+ // TODO(emilio): This is wrong when the target system is not the host
136
+ // system. See https://github.com/servo/rust-bindgen/issues/593
134
137
if cfg ! ( target_os = "macos" ) {
135
138
mangling. remove ( 0 ) ;
136
139
}
137
140
141
+ if cursor. kind ( ) == clang_sys:: CXCursor_Destructor {
142
+ // With old (3.8-) libclang versions, and the Itanium ABI, clang returns
143
+ // the "destructor group 0" symbol, which means that it'll try to free
144
+ // memory, which definitely isn't what we want.
145
+ //
146
+ // Explicitly force the destructor group 1 symbol.
147
+ //
148
+ // See http://refspecs.linuxbase.org/cxxabi-1.83.html#mangling-special
149
+ // for the reference, and http://stackoverflow.com/a/6614369/1091587 for
150
+ // a more friendly explanation.
151
+ //
152
+ // We don't need to do this for constructors since clang seems to always
153
+ // have returned the C1 constructor.
154
+ //
155
+ // FIXME(emilio): Can a legit symbol in other ABIs end with this string?
156
+ // I don't think so, but if it can this would become a linker error
157
+ // anyway, not an invalid free at runtime.
158
+ if mangling. ends_with ( "D0Ev" ) {
159
+ mangling. truncate ( mangling. len ( ) - 4 ) ;
160
+ mangling. push_str ( "D1Ev" ) ;
161
+ }
162
+ }
163
+
138
164
Some ( mangling)
139
165
}
140
166
0 commit comments