Hi all,
At the moment, lld is very lax about casting random pointers to ones with ABI alignment requirements, and even dereferencing them afterwards. This is not good, and we spend a lot of our time telling other developers not to do that (and that it's their fault their program now crashes), so we should probably get it right ourselves. Preferably *before* it bites us.
One big part of this (but not the only one) is the interface presented by the endian utility functions "readN" and "writeN", which effectively forces the creation of dodgy pointers. This patch attempts to fix them.
I also change the functions to have a more consistent interface (all use uintN_t) and change the "swap" parameter ("are we compiling for an architecture that's different to our own?") into an absolute "isBig" ("are we compiling for a big-endian target?").
The interfaces are still ugly, and if anyone has a better suggestion I'd love to hear it (this patch catches all uses, so it would be a good time to refactor it properly if there's a better way). Ideas I've considered so far:
- read<uint32_t>(...). Slightly nicer implementation, but even more verbose usage. Might be worth it if structs could be accommodated.
- "typedef ulittle32_t utarget32_t" in ArchHandler or similar. Would require making *everything* a template.
- virtual functions in ArchHandler. Would eliminate passing isBig around, but may not always have an ArchHandler.
How does it look?
Tim.
This is sad that the casts are needed. Perhaps, read32() can be overloaded to take a uint32_t* so all these casts can be removed.