egcs 1.1.1 miscompiles linux 2.1.127

H.J. Lu (hjl@lucon.org)
Sun, 8 Nov 1998 20:57:35 -0800 (PST)


egcs 1.1.1 prerelease miscompiles linux 2.1.127 when -O3 is used. Here
is a simple testcase.

# gcc -O2 bug.c
# a.out
# gcc -O3 bug.c
# a.out
zsh: 657 abort ./a.out

The problem is when egcs inlines calibrate_tsc, it puts RET in eax
for
__asm__(
"movl $100, %%eax\n\t"
"movl %1, %%edx\n\t"
"movl %%edx, %%eax\n\t"
"movl %%eax, %0\n\t"
: "=r" (retval)
: "r" (RET)
: "ax", "bx", "cx", "dx", "cc", "memory");

although it clearly says eax will be clobbered. If the asm statement
is correct, I hope it won't be hard to fix in egcs 1.1.1.

Thanks.

-- 
H.J. Lu (hjl@gnu.org)
---
#define RET	1000

static unsigned long calibrate_tsc(void) { unsigned long retval; __asm__( "movl $100, %%eax\n\t" "movl %1, %%edx\n\t" "movl %%edx, %%eax\n\t" "movl %%eax, %0\n\t" : "=r" (retval) : "r" (RET) : "ax", "bx", "cx", "dx", "cc", "memory"); return retval; } static unsigned long fast_gettimeoffset_quotient=0; unsigned long cpu_hz; void time_init(void) { fast_gettimeoffset_quotient = calibrate_tsc(); { unsigned long eax=0, edx=1000000; __asm__("nop" :"=a" (cpu_hz), "=d" (edx) :"r" (fast_gettimeoffset_quotient), "0" (eax), "1" (edx)); } }

main () { time_init (); if (fast_gettimeoffset_quotient != RET) abort ();

return 0; }

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/