HomePhabricator

[WebAssembly] Add a pass to create wrappers for function bitcasts.

Description

[WebAssembly] Add a pass to create wrappers for function bitcasts.

WebAssembly requires caller and callee signatures to match exactly. In LLVM,
there are a variety of circumstances where signatures may be mismatched in
practice, and one can bitcast a function address to another type to call it
as that type. This patch adds a pass which replaces bitcasted function
addresses with wrappers to replace the bitcasts.

This doesn't catch everything, but it does match many common cases.

Details

Committed
djgJan 6 2017, 4:34 PM
Parents
rL291314: Enable weak hooks on darwin
Branches
Unknown
Tags
Unknown

Event Timeline

dschuff added a subscriber: sunfish.Jan 6 2017, 5:23 PM
dschuff added inline comments.
/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
113

Does this mean that we will crash if we encounter user code with this kind of mismatch? shouldn't we just report an error instead? Or ignore it (to get a successful compiler) and let it fail at runtime if it's ever executed (which I guess would be more strictly in line with C/C++ UB)?

sunfish added inline comments.Jan 6 2017, 6:01 PM
/llvm/trunk/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
113

Good point, ignoring it seems the right thing to do, since it is "just" UB ;-). Fixed in r291326.