From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gq-0000pW-WD for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WV5gm-0007VB-7W for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:48 -0400 Received: from mail-qc0-x22a.google.com ([2607:f8b0:400d:c01::22a]:55979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gm-0007V5-2U for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:44 -0400 Received: by mail-qc0-f170.google.com with SMTP id x13so1459234qcv.29 for ; Tue, 01 Apr 2014 13:53:43 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Tue, 1 Apr 2014 13:53:26 -0700 Message-Id: <1396385614-19267-2-git-send-email-rth@twiddle.net> In-Reply-To: <1396385614-19267-1-git-send-email-rth@twiddle.net> References: <1396385614-19267-1-git-send-email-rth@twiddle.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org From: Peter Maydell The code which patches x86 jump instructions assumes it can do an unaligned write of a uint32_t. This is actually safe on x86, but it's still undefined behaviour. We have infrastructure for doing efficient unaligned accesses which doesn't engage in undefined behaviour, so use it. This is technically fractionally less efficient, at least with gcc 4.6; instead of one instruction: 7b2: 89 3e mov %edi,(%rsi) we get an extra spurious store to the stack slot: 7b2: 89 7c 24 64 mov %edi,0x64(%rsp) 7b6: 89 3e mov %edi,(%rsi) Reviewed-by: Alex Bennée Signed-off-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index f9ac332..1c49a21 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -229,7 +229,7 @@ void ppc_tb_set_jmp_target(unsigned long jmp_addr, unsigned long addr); static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) { /* patch the branch destination */ - *(uint32_t *)jmp_addr = addr - (jmp_addr + 4); + stl_p((void*)jmp_addr, addr - (jmp_addr + 4)); /* no need to flush icache explicitly */ } #elif defined(__aarch64__) -- 1.9.0