-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alignment issues in serializers #305
Comments
We'll need to do some research to check whether |
I should've searched for existing memcpy occurrences. Please, let me know if I can be of help. |
Consider using |
This is currently broken. Initial attempt at fixing microsoft#305
|
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305 TODO: * [ ] Check how performance has changed, if at all
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305 TODO: * [ ] Check how performance has changed, if at all
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305
We now use memcpy to pun from one type to another, avoiding aliasing violations as well as alignment errors. x86-like chips never failed due to the alignment errors, but others, like some ARM chips, did. This should also fix emscripten cross-compilation. Fixes microsoft#305 Closes microsoft#375
We began using Bond in a project compiled with emscripten. [1]
Running deserializers for CompactBinary, FastBinary and SimpleJson always resulted in an "alignment fault" when executing the resulting asm.js code.
The following exemplary piece of code demonstrates the issue and a possible fix. (There are other similar pieces of code here and there.)
It is located in
cpp/inc/bond/stream/input_buffer.h
:Emscripten is a platform requiring loads and stores to be aligned (like MIPS, PowerPC, etc. but not like x86 which allows unaligned access though not without impact).
Also, I think, the original code violates the C++ strict aliasing rules...
Using
std::memcpy
should be safe and most compilers should detect the use ofstd::memcpy
and generate properly optimized code.I do not understand this part of C++ deep enough to be a 100% sure that this is the right approach as I'm developing for x86 and x86_64 where unaligned access just works. Otherwise I would've prepared a PR already. :)
I also tested SimpleJson (when the others failed) and also ran into alignment issues but this time most likely due to RapidJson itself. A fix for RapidJson ( Tencent/rapidjson#353 ) has been merged into
master
and should be included in the next release ( http://rapidjson.org/md__c_h_a_n_g_e_l_o_g.html ).->
If you could provide some guidance on how to deal with this issue, whether that's the right direction or whether there's a different solution... that'd be much appreciated.
[1] This is part of an experimental web app sharing code and data between our desktop applications and existing services talking Bond.Comm.
The text was updated successfully, but these errors were encountered: