This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

segmentation fault for small C program


I am running Debian 2.0.  I've been playing with EGCS-2.90.29.  It
appears to use EBX as a pointer without initializing it first.  

Here is the shell screen:

$ egcc  -Wall -O -o foo foo.c
$ foo
Segmentation fault
$

Here is the C program:
---------------foo.c--------
#include <time.h>
#include <math.h>

int main(int argc, char *argv[])
{
  time_t time_and_date;   /* Self-explanatory */
  time(&time_and_date); 
  pow((double) 1.0,(double).142857);
  return 0;
}



Here is the assembly output
-----------foo.s ---------
	.file	"foo.c"
	.version	"01.01"
/ GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release) (i486-linux) compiled by GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release).
/ options passed:  -O -Wall
/ options enabled:  -fdefer-pop -fthread-jumps -fpeephole -ffunction-cse
/ -finline -fkeep-static-consts -fpcc-struct-return -fcommon -fverbose-asm
/ -fgnu-linker -falias-check -fargument-alias -m80387 -mhard-float
/ -mno-soft-float -mieee-fp -mfp-ret-in-387 -mschedule-prologue -mcpu=i486
/ -march=pentium

gcc2_compiled.:
.section	.rodata
	.align 4
.LC14:
	.long 0x5f809918,0x3fc24923
	.align 4
.LC15:
	.long 0x0,0x3ff00000
.text
	.align 16
.globl main
	.type	 main,@function
main:
	pushl %ebp
	movl %esp,%ebp
	subl $16,%esp
	pushl %ebx
	leal -4(%ebp),%ebx
	pushl %ebx
	call time
	fldl .LC14
	fld %st(0)
	fnstcw -4(%ebx)
	movl -4(%ebx),%eax
	movb $12,%ah
	movl %eax,-12(%ebx)
	fldcw -12(%ebx)
	fistpll -12(%ebx)
	movl -12(%ebx),%ecx
	movl -8(%ebx),%ebx
	fldcw -4(%ebx)
	pushl %ebx
	pushl %ecx
	fildll (%esp)
	addl $8,%esp
	fucompp
	fnstsw %ax
	andb $68,%ah
	xorb $64,%ah
	jne .L100
	testl %ecx,%ecx
	jne .L101
	testl %ebx,%ebx
	je .L99
.L101:
	testl %ebx,%ebx
	jge .L106
	negl %ecx
	adcl $0,%ebx
	negl %ebx
	.align 4
.L106:
	shrdl $1,%ebx,%ecx
	sarl $1,%ebx
	testl %ecx,%ecx
	jne .L106
	testl %ebx,%ebx
	je .L99
	jmp .L106
	.align 16
.L100:
	fldl .LC15
#APP
	fld1
	fxch
	fyl2x
#NO_APP
	fldl .LC14
	fxch %st(1)
#APP
	fmul	%st(1)		# y * log2(x)
	fstl	%st(1)
	frndint			# int(y * log2(x))
	fxch
	fsub	%st(1)		# fract(y * log2(x))
	f2xm1			# 2^(fract(y * log2(x))) - 1
	
#NO_APP
	fld %st(1)
	fstp %st(0)
	faddl .LC15
#APP
	fscale
#NO_APP
	fstp %st(0)
	fstp %st(0)
.L99:
	xorl %eax,%eax
	movl -20(%ebp),%ebx
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 main,.Lfe1-main
	.ident	"GCC: (GNU) egcs-2.90.29 980515 (egcs-1.0.3 release)"



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]