[PATCH] [lld] [mach-o] make lld respect alignment constraints more
Tim Northover
t.p.northover at gmail.com
Wed Oct 15 16:16:42 PDT 2014
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.
http://reviews.llvm.org/D5811
Files:
lib/ReaderWriter/MachO/ArchHandler.cpp
lib/ReaderWriter/MachO/ArchHandler.h
lib/ReaderWriter/MachO/ArchHandler_arm.cpp
lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
lib/ReaderWriter/MachO/ArchHandler_x86.cpp
lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
lib/ReaderWriter/MachO/CompactUnwindPass.cpp
lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h
lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5811.14969.patch
Type: text/x-patch
Size: 77876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141015/6eeff2d2/attachment.bin>
More information about the llvm-commits
mailing list