[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: _Very_ strange problem with compiling



Peter Kovacs [peter@kovax.org] wrote:
> The problem is: you're simply asking for too much stack space.  On my
> machine, ulimit -s reports 8129 (that's in Kilobytes).  When I write a
> seperate program such as:
> 
> #include <stdio.h>
> 
> void main(int argc, char **argv)
> {
> 	double a[209677];
> 	printf("%d\n", sizeof(a)*5/1024);
> }
> 
> it reports a total usage of 8190K in stack space.  This is obviously
> over the limit.  So just increase the stack space and the program runs
> fine:  (ulimit -s <size>)

Thanks for this!  I increased the stack size via "ulimit -s <size>"
and the thick4 executable no longer crashes.

However the curious thing is that with test.c, I thought "surely by
increasing N I could make it seg fault too" but I can't, even

#define N 200000000

runs fine.  (c.f. #define N 209677 for thick4.c) (Remember that test.c
and thick4.c are identical apart from name --- and now size of N.)

Perhaps my understanding of what the stack is and how it works is
wrong.  (Basically it is where local variables are stored --- or is
there more to it than that?)

Perhaps the compiler does things differently depending on how big
the name space is?

Anyway, thanks again for your help.

Mark.






> 
> As for the slight difference between the two executables, that's because
> you were storing symbols in the executable.  If you run them through
> strip there is no difference between the two files.
> 
> Peter
> 
> 
> On Wed, Mar 07, 2001 at 03:18:56AM +1030, Mark Phillips wrote:
> > Hi,
> > 
> > I thought I'd found a gcc compiler error (and still may have).  The
> > following program crashes with a segmentation fault.
> > 
> > #define N 209677
> > 
> > int main(int argv, char **argc) {
> >   int
> >     i;
> >   double
> >     a[N],
> >     b[N],
> >     c[N],
> >     d[N], 
> >     e[N];
> > 
> >   c[0]=0.0;
> >   i=1;
> >   c[i]=c[i-1];
> > }
> > 
> > If I make N slightly less, or reduce the number of arrays defined, it
> > runs fine.  If I write instead "c[1]=c[0]" it runs fine.  Basically, I
> > simplified the original program as much as I could in ways which still
> > caused the Seg Fault to happen.
> > 
> > So I thought this must be a compiler error.  The program was called
> > "thick4.c".  I used emacs to paste the file into a new buffer called
> > "test.c".  But this one worked fine when I compiled!!!!  The two files
> > "thick4.c" and "test.c" are identical, as both diff and cmp prove.
> > 
> > The executables "thick4" and "test" differ very slightly however.
> > 
> > -rwxrwxr-x    1 mark     mark         4731 Mar  7 02:53 test*
> > -rw-rw-r--    1 mark     mark          162 Mar  7 02:53 test.c
> > -rwxrwxr-x    1 mark     mark         4733 Mar  7 02:53 thick4*
> > -rw-r--r--    1 mark     mark          162 Mar  7 02:51 thick4.c
> > 
> > and 
> > 
> > $ cmp thick4 test  
> > thick4 test differ: char 3061, line 2
> > 
> > Why would identical files compile to slightly different executables?
> > I have included gzipped versions of these executables with this email.
> > 
> > Has anyone got any idea what might be going on?  Or suggestions about
> > what I could investigate next!
> > 
> > Also, can anyone else replicate the error I got (using thick4.c as
> > your file name).
> > 
> > Thanks,
> > 
> > Mark.
> > 
> > -- 
> > _/~~~~~~~~\___/~~~~~~\____________________________________________________
> > ____/~~\_____/~~\__/~~\__________________________Mark_Phillips____________
> > ____/~~\_____/~~\________________________________mark@ist.flinders.edu.au_
> > ____/~~\HE___/~~\__/~~\APTAIN_____________________________________________
> > ____/~~\______/~~~~~~\____________________________________________________
> > __________________________________________________________________________
> >         "They told me I was gullible ... and I believed them!" 
> > 
> 
> 
> > ???:> 
> > ????F%?Dm??Z?^???\?+?@<lwO?kv?lv???%?H??C?SL?h?l??>TJD?%?h0*	&????D?!???3g???$???4?3????????K??i????c~F????
?[?E{?y???e?PFyu?5?:??:e?(/C}??i2??P&}V/??m2?e????b
> > ?)?(?>)????????^K9> ?o?
> > ?????1?~lOl????}???????-?8:????1??R??????)??/??EQ??_A?QV<?[
> > ?Y???????????Z?za?\
)?#?????YQ~pJ(4????Ob?\??r???w?y???;:??=>?sG????M?{4x???1?[j?$?????ck??
c?pQ_tqm??????9J_|??9l???S7?/?/??,<T?]???U???6???s??U,????DD?????o(??[N)??????#?M?k??>k?q????X?FIqB?%??ERo????2;4???y\1v;???z%?^&K??nC;?j?X~C?t?/???z0???b}??x?~?5??????h????T> ???a????V?\?"?~?????>Wt(o???V?a"?????W?? m??+??????s???uZ??&??????????*???h?`\_?h?XXn*aa!T??;?%,????~q???*??L???J?_?8vJx!?S%???K%,V0????9?[?K8>0???'JXD[??8??p#??%,v??^.?O?xE????~~Q??
> > ?????k?^Wp?&u|.?*?w+?:?V???"?7Ht???-e??k?7??"?????A???Z8H?R?#?+??6??c????S
> > ~?????=?}
???|?G??|?`??JG?'{m#??w?y?X???????D?W?2?i???4o?4`?,???????+?x????F??-Z??????z???y????????????V?????x`?'5o>???7+?{W????,pH????a/(??????'@?C?H??;O:?????	????,~??d???4",m??gkwh?n?????w0i'??m?????=N???e?sy?5????4;?=?;?Dw53?K&2{?)+?--L??E+??du??D,??M~?3?.??j0?????nN?V??@??u0'????{?????n???`??=?L~??????/?h??[??|?W?+@U?i???NkZb?=};;;??????Cf???/?Y???????Q?o???>^?{
> 
> -- 
> Peter D. Kovacs <peter@kovax.org>
> Software Developer
> Webmachines, Inc. http://webmachines.com

-- 
_/~~~~~~~~\___/~~~~~~\____________________________________________________
____/~~\_____/~~\__/~~\__________________________Mark_Phillips____________
____/~~\_____/~~\________________________________mark@ist.flinders.edu.au_
____/~~\HE___/~~\__/~~\APTAIN_____________________________________________
____/~~\______/~~~~~~\____________________________________________________
__________________________________________________________________________
        "They told me I was gullible ... and I believed them!" 



Reply to: