Closed tuxmark5 closed 4 years ago
Hmm... Is this a wasm-only thing? Or do actual C++ constructors end up with a this
return type in clang too?
I've seen similar behavior on ARM a while ago, when trying to disassemble a certain binary.
However after digging for a bit in compiler explorer, it seems that this is wasm (or even wasm + clang) specific behavior.
Would it be possible to fix this issue? As I have to maintain a local version of bindgen to get skia-safe to compile for emscripten.
I'm using such patch to src/ir/function.rs:
- let ret = Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx);
+ let ret = if is_constructor {
+ let void = Item::builtin_type(TypeKind::Void, false, ctx);
+ Item::builtin_type(TypeKind::Pointer(void), false, ctx)
+ } else {
+ Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx)
+ };
For actual implementation it would need to be guarded to only activate on wasm32 builds
We have access to the target triple when we construct the BindgenContext, so it should be relatively easy to keep track of it and check it there. If you send a PR I'd happily merge it :)
Bindgen generates incorrect return types for C++ class constructors in
wasm32-unknown-emscripten
, which causes linker warnings or even errors (when linking with-Wl,--fatal-warnings
)Input C/C++ Header
custom.rs
bindings.rs
Bindgen Invocation
Actual Results
Expected Results
No warnings/errors.
It appears that C++ constructors have an internal return value (which seemingly equals to
this
). However bindgen assumes that C++ constructors always returnvoid
, which causes function signature mismatches when linking code generated with bindgen with actual C++ object files.I encountered this issue when trying to port
skia-safe
(which uses bindgen) towasm32-unknown-emscripten
.