* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
@ 2001-06-29 16:51 ` Robert M. Riches Jr.
2001-06-29 17:21 ` Berkley Shands
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Robert M. Riches Jr. @ 2001-06-29 16:51 UTC (permalink / raw)
On Fri, 29 Jun 2001 16:10:38 GMT, Patrick Paul
<patrick@no_microway_spam.com> wrote:
>a little help from those programmer types out there. i compared
>/proc/sys/kernel entries between intel and alpha machines, and that wasn't
>the problem.
>
>what happens is that i compile this proggy
>
>#include <stdio.h>
>#define SIZE 1047977
>
>main ()
>{
> double vector_x [SIZE];
> int x;
>
> for ( x = 0; x < SIZE; x++ )
> vector_x [x] = (double) x;
>
> printf ("\n x [%d] = %.4f\n\n", SIZE - 1, vector_x [SIZE - 1] );
>}
>
>
>which compiles fine
>
>but when i run it on alpha, it coredumps and segfaults.
>
>on intel, it works fine.
It's not too hard to stump me, as I'm far from an expert, but
this dumps core on my RH7.0 Alpha Linux box, too. My first
thought was that there should probably be an 'l' in front of the
'f' in the format string. I tried all four combinations of 'l'
vs. no 'l' in front of the 'd' and 'f'. All four core dump. A
check with gdb says the problem happens in the printf call, at
line 270 of vfprintf.c, and at line 203 of dl-runtime.c, at their
respective levels on the stack. I don't find either of these
files on my system, so I would guess they are in the GLIBC
sources.
Good luck.
Robert Riches
richesr1@inetarena.com
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
2001-06-29 16:51 ` Robert M. Riches Jr.
@ 2001-06-29 17:21 ` Berkley Shands
2001-06-29 20:59 ` Art Haas
2001-06-29 17:36 ` Serguei Patchkovskii
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Berkley Shands @ 2001-06-29 17:21 UTC (permalink / raw)
In article <2M1%6.147007$Bz6.91285@sjc-read.news.verio.net>,
Patrick Paul <patrick@no_microway_spam.com> wrote:
>a little help from those programmer types out there. i compared
>/proc/sys/kernel entries between intel and alpha machines, and that wasn't
>the problem.
>
>what happens is that i compile this proggy
>
>#include <stdio.h>
>#define SIZE 1047977
>
>main ()
>{
> double vector_x [SIZE];
> int x;
>
> for ( x = 0; x < SIZE; x++ )
> vector_x [x] = (double) x;
>
> printf ("\n x [%d] = %.4f\n\n", SIZE - 1, vector_x [SIZE - 1] );
>}
>
>
>which compiles fine
>
>but when i run it on alpha, it coredumps and segfaults.
>
>on intel, it works fine.
>
>any ideas?
>
>tia
>
>--
>Patrick Paul
>Microway.com
>patrick@no_microway_spam.com
>
>
you have overrun the static storage limit for arrays...
#include <stdio.h>
#define SIZE 1047977
main ()
{
/* double vector_x [SIZE]; */
double *vector_x = NULL;
int x = 0;
vector_x = (double *) malloc(sizeof(double) * (SIZE + 1));
if (! vector_x)
{
perror("malloc failed");
exit(-1);
}
for ( x = 0; x < SIZE; x++ )
vector_x [x] = (double) x;
printf ("\n x [%d] = %.4lf\n\n", SIZE - 1, vector_x [SIZE - 1] );
}
(Xp1000 512mb 500mhz ev6 redhat 7.0 running 2.4.5)
Xp1000@alleycat /tmp> cc test.c
test.c: In function `main':
test.c:10: warning: cast to pointer from integer of different size
Xp1000@alleycat /tmp> a.out
x [1047976] = 1047976.0000
you fight many battles with gcc, some you win, some you don't.
large static arrays will crash many systems, not just alphas.
Try that one under Micro$oft :-)
Your code on Tru64 V5.1a generates
Stack overflow: pid 12853, proc a.out, addr 0x11f7fd2b0, pc 0x120001190
Segmentation fault
Xp1000@alleycat2 /tmp> limit stack un
Xp1000@alleycat2 /tmp> a.out
x [1047976] = 1047976.0000
My general rule is any array over 128Kb should be malloc() or new().
Long Live Alpha!
berkley
--
berkley@cs.wustl.edu "Software Enforcer"
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 17:21 ` Berkley Shands
@ 2001-06-29 20:59 ` Art Haas
0 siblings, 0 replies; 7+ messages in thread
From: Art Haas @ 2001-06-29 20:59 UTC (permalink / raw)
berkley@taumsauk.cs.wustl.edu (Berkley Shands) writes:
> you have overrun the static storage limit for arrays...
>
> #include <stdio.h>
#include <stdlib.h>
> #define SIZE 1047977
>
> main ()
> {
> /* double vector_x [SIZE]; */
> double *vector_x = NULL;
> int x = 0;
>
> vector_x = (double *) malloc(sizeof(double) * (SIZE + 1));
vector_x = malloc(sizeof(double) * (SIZE + 1));
> if (! vector_x)
> {
> perror("malloc failed");
> exit(-1);
> }
> for ( x = 0; x < SIZE; x++ )
> vector_x [x] = (double) x;
>
> printf ("\n x [%d] = %.4lf\n\n", SIZE - 1, vector_x [SIZE - 1] );
> }
>
> (Xp1000 512mb 500mhz ev6 redhat 7.0 running 2.4.5)
>
> Xp1000@alleycat /tmp> cc test.c
> test.c: In function `main':
> test.c:10: warning: cast to pointer from integer of different size
> Xp1000@alleycat /tmp> a.out
> [ ... snip ... ]
You need to `#include <stdlib.h>' for the prototype for malloc(), and
you don't need the cast. I think the changes above should rid you of
the warnings generated by the compiler, too.
--
###############################
# Art Haas
# (713) 689-2417
###############################
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
2001-06-29 16:51 ` Robert M. Riches Jr.
2001-06-29 17:21 ` Berkley Shands
@ 2001-06-29 17:36 ` Serguei Patchkovskii
2001-06-29 17:59 ` Terrance Richard Boyes
2001-06-29 19:25 ` Patrick Paul
4 siblings, 0 replies; 7+ messages in thread
From: Serguei Patchkovskii @ 2001-06-29 17:36 UTC (permalink / raw)
Patrick Paul (patrick@no_microway_spam.com) wrote:
: #define SIZE 1047977
[...]
: double vector_x [SIZE];
[...]
# expr 1047977 \* 8 / 1024
8187
# ulimit -sH
8192
# uname -a
Linux xXxXxXx 2.2.14-6.0 #1 Tue Mar 28 16:56:56 EST 2000 alpha unknown
man ulimit setrlimit getrlimit
/Serge.P
---
Home page: http://www.cobalt.chem.ucalgary.ca/ps/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
` (2 preceding siblings ...)
2001-06-29 17:36 ` Serguei Patchkovskii
@ 2001-06-29 17:59 ` Terrance Richard Boyes
2001-06-29 19:25 ` Patrick Paul
4 siblings, 0 replies; 7+ messages in thread
From: Terrance Richard Boyes @ 2001-06-29 17:59 UTC (permalink / raw)
Patrick Paul <patrick@no_microway_spam.com> wrote:
> a little help from those programmer types out there. i compared
> /proc/sys/kernel entries between intel and alpha machines, and that wasn't
> the problem.
> what happens is that i compile this proggy
> #include <stdio.h>
> #define SIZE 1047977
I had a play with the SIZE and the limiting value (on my normal
setup) seems to be 1047863. Which suggests it's running out of
stack (8MB). Either up the stack, or allocate memory for vector_x
separately.
[snip]
*Tez* who would like to point out that the sig was completely random :)
--
<URL:http://www.pierrot.co.uk/faq/dtm.faq> Team AMIGA
There's a bug somewhere in your code.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: 13 line c program segfaults on alpha/linux, but not intel. why?
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
` (3 preceding siblings ...)
2001-06-29 17:59 ` Terrance Richard Boyes
@ 2001-06-29 19:25 ` Patrick Paul
4 siblings, 0 replies; 7+ messages in thread
From: Patrick Paul @ 2001-06-29 19:25 UTC (permalink / raw)
thanks for the help. malloc will be used, but setting the stack to 16384
allowed it to run. coulda sworn i checked the ulimit -s setting though.....
^ permalink raw reply [flat|nested] 7+ messages in thread