LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   hitting size limit (or whatever), gcc (http://www.linuxquestions.org/questions/programming-9/hitting-size-limit-or-whatever-gcc-847328/)

kaz2100 11-29-2010 06:57 PM

hitting size limit (or whatever), gcc
 
Hya,

I am inventing wheel here. If anybody else is hitting similar problem, hopefully this post helps.

I am sure that this is some sort of size limit related. The code below compiles, but runs into SegFault.

Code:

int main(int argc, char** argv, char** envv){

struct  rStr {
        long    i1l;
        long    i2l;
        long    j1l;
        long    j2l;
        int    k1;
        char    s1[400];
        char    s2[400];
        char    s3[50];
        }      qu[10000];

return;
}

When array size of "qu" is small (100 ish), it runs. If memory is allocated dynamically using pointer and malloc, it runs also. I guess the problem is not physical memory related.

My system is Debian squeeze, gcc version 4.4.5 (Debian 4.4.5-8). It took quite a while for me to figure out, so I am posting here.

Happy Penguins!

kaz2100 11-29-2010 06:59 PM

Self reply,

If anybody knows how to detect this problem, please post here.

paulsm4 11-29-2010 07:53 PM

Hi -

Try compiling with "-fstack-check" and see what happens:

http://gcc.gnu.org/onlinedocs/gcc/Co...de-Gen-Options

And/or "-fstack-protector-all":

http://gcc.gnu.org/onlinedocs/gcc/Op...timize-Options

'Hope that helps

johnsfine 11-30-2010 07:48 AM

The problem is stack overflow.

Quote:

Originally Posted by kaz2100 (Post 4175234)
If anybody knows how to detect this problem, please post here.

Are you really asking how to detect the stack overflow (I expect paulsm4's post covers that)?

Or do you want to correct the stack overflow? You can use the ulimit command to change the initial stack size.

kaz2100 11-30-2010 10:42 PM

Hya,

Thanks for replies, however...
Code:

>cat error.c
int main(int argc, char** argv, char** envv){

struct  rStr {
        long    i1l;
        long    i2l;
        long    j1l;
        long    j2l;
        int    k1;
        char    s1[400];
        char    s2[400];
        char    s3[50];
        }      qu[10000];

return;
}
>gcc -fstack-check error.c
>./a.out
Segmentation fault
>gcc -fstack-protector-all error.c
0 /common/ref18>./a.out
Segmentation fault
>gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)

I think ulimit is a bash built-in command and I use tcsh.

I would prefer using pointer to using getrlimit(), setrlimit() and sysconf(). At least, I know where to check next time.

Thanks again.

Happy Penguins!


All times are GMT -5. The time now is 12:48 PM.