qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 0/3] tcg: Avoid undefined behaviour on unaligned stores
@ 2014-03-28 15:29 Peter Maydell
  2014-03-28 15:29 ` [Qemu-devel] [RFC 1/3] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps Peter Maydell
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Peter Maydell @ 2014-03-28 15:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, patches

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-03-28 18:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-28 15:29 [Qemu-devel] [RFC 0/3] tcg: Avoid undefined behaviour on unaligned stores Peter Maydell
2014-03-28 15:29 ` [Qemu-devel] [RFC 1/3] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps Peter Maydell
2014-03-28 15:29 ` [Qemu-devel] [RFC 2/3] tcg: Avoid stores to unaligned addresses Peter Maydell
2014-03-28 16:00   ` Andreas Färber
2014-03-28 15:29 ` [Qemu-devel] [RFC 3/3] tcg: Avoid undefined behaviour patching code at " Peter Maydell
2014-03-28 18:06 ` [Qemu-devel] [RFC 0/3] tcg: Avoid undefined behaviour on unaligned stores Richard Henderson
2014-03-28 18:18   ` Peter Maydell
2014-03-28 18:48     ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).