|
From: John R.
|
> Lucky for us, so does the x86. There is a flag you can set in some > register or other which makes the CPU trap on unaligned access. So long > as we don't do it internally, you could set that and watch all the > unaligned accesses in your program (even without Valgrind). Yes, it's the AC [Alignment Check] bit of the processor flags, which is bit 18 (the bit with positional value (1<<18) or 0x40000). It checks for unaligned access in user mode. $ cat foo.S _start: .globl _start pushf orl $1<<18,(%esp) popf movl 1(%esp),%eax nop $ gcc -o foo -nostartfiles -nostdlib foo.S $ gdb foo (gdb) run Program received signal SIGBUS, Bus error. 0x0804807d in _start () (gdb) x/i $pc 0x804807d <_start+9>: mov 0x1(%esp,1),%eax (gdb) q $ |