C stack frame > 64K (on a Sun)

Mark Plotnick mp at allegra.UUCP
Wed Dec 12 02:18:05 AEST 1984


> From gnu at sun.uucp (John Gilmore)
> The Sun C compiler used to have this restriction.  We fixed it.  It was easy
> (on the 68000).  Hey, all you people who "severely limited their target
> machine choices" -- your code will run fine on Suns!

Note that if you care about getting correct code out of the SMI C
compiler, you shouldn't use stack frames larger than 32Kbytes.  This is
because of a bug in their compiler (at least as of release 1.1, which
is what we have) with the handling of floating point operations that
require scratch areas on the stack.  The compiler doesn't seem to know
that displacements, as in reg@(disp), are limited to 16-bit signed
integers.  Example:

calliope% cat bug.c
#ifndef SIZE
#define SIZE 30000
#endif

#include <stdio.h>

main()
{

	char HIGHBOUND;
	double tx,temp;
	char c[SIZE];
	int lcv, i;
	char LOWBOUND;

	printf("&LOWBOUND=%d &HIGHBOUND=%d\n", &LOWBOUND, &HIGHBOUND);
	printf("stack size = approx %d\n", &HIGHBOUND - &LOWBOUND);
	fflush(stdout);
	for(i=0;i<SIZE;i++)
		c[i]=0;
	tx = 1.0; lcv = 1;
	temp = tx/lcv;
	for(i=0;i<SIZE;i++)
		if(c[i]) printf("oops, c[%d]=%d\n",i,0377&c[i]);
    
}
calliope% cc bug.c -O -o bug -DSIZE=30000
calliope% bug
&LOWBOUND=16746693 &HIGHBOUND=16776719
stack size = approx 30026
calliope% cc bug.c -O -o bug -DSIZE=50000
calliope% bug
&LOWBOUND=16726693 &HIGHBOUND=16776719
stack size = approx 50026
Segmentation fault (core dumped)
calliope% cc bug.c -O -o bug -DSIZE=70000
calliope% bug
&LOWBOUND=16706693 &HIGHBOUND=16776719
stack size = approx 70026
oops, c[65518]=63
oops, c[65519]=240

In the last program, the offending instructions in bug.s are (just after
the jbsr fvflti):
	movl	d0,a6@(-70036)
	movl	d1,a6@(-70032)

	Mark Plotnick
	Department of Sun burns
	allegra!mp



More information about the Comp.lang.c mailing list