Introduce support::ulittleX_t::ref type to Support/Endian.h and use it in x86 JIT
to enforce correct endianness and fix unaligned accesses.
Details
Diff Detail
Event Timeline
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
266–267 | What about using something like this instead? |
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
266–267 | It would still be an unaligned write of ulittle_64_t, which is UB. |
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
266–267 | operator= is overloaded for support::ulittle64_t and should call support::endian::write<uint64_t, support::little, 1> for you. |
Follow Juergen's suggestion.
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
266–267 | Oh, right, my bad =/ |
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
266–267 | This might be a good argument for adding some extra types to Endian.h that take the address of the storage. Then we could write something like: ulittle8_ref(Address) = <expr> ; | |
266–267 | Juergen - I believe you're right. I had misread your original code. Samsonov - The assignment in Juergen's suggested code should go to the explicit assignment operator for ulittle64_t, no? Though in either case, I'd prefer to provide a convenience wrapper along the lines I described. Having explicit reinterpret_casts everywhere would be awful. | |
307 | Unfortunately this isn't safe: The remaining pointer arithmetic will be carried out with the type of Placeholder being ulittle32_t*, and sizeof(ulittle32_t) != sizeof(char). I think the best thing to do is leave the pointer types as they are and introduce read and write methods to RuntimeDyldELF along the same lines as the ones you added to the JIT. |
LGTM. Thanks Alexey!
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | ||
---|---|---|
307 | Oh right - I missed the dereference on placeholder. Sorry about that: this is all good. :) |
What about using something like this instead?
auto *Target = reinterpret_cast<support::ulittle64_t *>(Section.Address + Offset);
*Target = Value + Addend;