qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 0/3] tcg: Avoid undefined behaviour on unaligned store


From: Peter Maydell
Subject: [Qemu-devel] [RFC 0/3] tcg: Avoid undefined behaviour on unaligned stores
Date: Fri, 28 Mar 2014 15:29:45 +0000

These patches fix various cases in the x86 backend and the runtime
TB-jump-patching code where we cast an unaligned pointer to a uint32_t*
and store into it. Unaligned accesses are OK on x86 hardware, of
course, but this is still undefined behaviour in C, and the clang
sanitizer complains.

Sent out as an RFC to get a feel for whether we want to go
down some road like this. Personally I think it is worthwhile
for two reasons:
 (1) it's easier to see sanitizer warnings that actually matter if
they're not hidden in among a lot of warnings that don't.
 (2) it's increasingly clear that it's a bad idea to trust
compiler engineers, who will happily throw real applications
under the bus for a 0.05% improvement in Dhrystone scores;
so if we can reasonably avoid undefined behaviour we should.

It would probably be better to split the tcg_out functions into
separate ones for "I know this pointer is aligned" and "may be
unaligned", to avoid overhead on hosts which don't have cheap
unaligned stores. Also I haven't tried to extend the tcg_patch*
usage to the other backends.


Peter Maydell (3):
  exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps
  tcg: Avoid stores to unaligned addresses
  tcg: Avoid undefined behaviour patching code at unaligned addresses

 include/exec/exec-all.h |  2 +-
 tcg/i386/tcg-target.c   | 12 ++++++------
 tcg/tcg.c               | 26 +++++++++++++++++++++++---
 3 files changed, 30 insertions(+), 10 deletions(-)

-- 
1.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]