|
|
Log in / Subscribe / Register

Signed overflow optimization hazards in the kernel

Signed overflow optimization hazards in the kernel

Posted Aug 22, 2012 13:21 UTC (Wed) by etienne (guest, #25256)
In reply to: Signed overflow optimization hazards in the kernel by mpr22
Parent article: Signed overflow optimization hazards in the kernel

Seems like -ftrapv can work, but it is far from just adding an "into" instruction after each signed "add" on ia32 - note that "into" has disappeared in amd64 instruction set.

$ cat test.c
int a, b, c;
void main (void) {
c = a + b;
}
$ gcc -m32 -O2 -ftrapv test.c
$ objdump -d a.out

a.out: file format elf32-i386
....
080483f0 <main>:
push %ebp
mov %esp,%ebp
and $0xfffffff0,%esp
sub $0x10,%esp
mov 0x804a01c,%eax
mov %eax,0x4(%esp)
mov 0x804a020,%eax
mov %eax,(%esp)
call 8048420 <__addvsi3>
mov %eax,0x804a024
leave
ret
....
08048420 <__addvsi3>:
push %ebp
mov %esp,%ebp
push %ebx
sub $0x4,%esp
mov 0xc(%ebp),%ecx
mov 0x8(%ebp),%edx
call 804845c <__i686.get_pc_thunk.bx>
add $0x1bc2,%ebx
test %ecx,%ecx
lea (%ecx,%edx,1),%eax
js 8048450 <__addvsi3+0x30>
cmp %edx,%eax
setl %dl
test %dl,%dl
jne 8048457 <__addvsi3+0x37>
add $0x4,%esp
pop %ebx
pop %ebp
ret
xchg %ax,%ax
cmp %edx,%eax
setg %dl
jmp 8048444 <__addvsi3+0x24>
call 80482fc <abort@plt>

Without ftrapv:
080483c0 <main>:
mov 0x804a01c,%eax
add 0x804a018,%eax
push %ebp
mov %esp,%ebp
mov %eax,0x804a020
pop %ebp
ret


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds