GCC kernel miscompile with O2
William Stearns
wstearns@pobox.com
Wed Feb 14 21:46:00 GMT 2001
Good day, all,
gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
In the following code, the &&error is calculated incorrectly under -O2,
but correctly under normal optimization. This is the assembly under -O2:
Dump of assembler code for function __copy_from_user:
0x80484a0 <__copy_from_user>: push %ebp
0x80484a1 <__copy_from_user+1>: mov %esp,%ebp
0x80484a3 <__copy_from_user+3>: push %edi
0x80484a4 <__copy_from_user+4>: push %esi
0x80484a5 <__copy_from_user+5>: push %ebx
0x80484a6 <__copy_from_user+6>: sub $0x18,%esp
0x80484a9 <__copy_from_user+9>: push $0x80484a0
0x80484ae <__copy_from_user+14>: mov 0x8(%ebp),%edi
0x80484b1 <__copy_from_user+17>: mov 0xc(%ebp),%esi
0x80484b4 <__copy_from_user+20>: mov 0x10(%ebp),%ebx
0x80484b7 <__copy_from_user+23>: call 0x804848c <set_fault_addr>
The instruction at 0x80484a9 is calculating &&error as 0x80484a0, which is
the start of the procedure.
#include <stdlib.h>
void set_fault_addr(void *ptr)
{
printf("HI\n");
}
int __copy_from_user(void *to, const void *from, int n) {
int ret = 0;
set_fault_addr(&&error);
memcpy(to, from, n);
goto out;
error:
ret = n - ((unsigned long) get_fault_addr() - (unsigned long) from);
out:
set_fault_addr(NULL);
return(ret);
}
main()
{
printf("HI\n");
__copy_from_user("a", "b", 100);
}
Cheers,
- Bill
---------------------------------------------------------------------------
"Microsoft has done more for the fault tolerance industry than any
other company. They have made end-users very tolerant of faults".
(Courtesy of "Deliduka, Bennet" <bennet.deliduka@state.vt.us>)
--------------------------------------------------------------------------
William Stearns (wstearns@pobox.com). Mason, Buildkernel, named2hosts,
and ipfwadm2ipchains are at: http://www.pobox.com/~wstearns
LinuxMonth; articles for Linux Enthusiasts! http://www.linuxmonth.com
--------------------------------------------------------------------------
More information about the Gcc-bugs
mailing list