public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32520] New: C/C++ programs segfault at runtime if arrays larger than 8MB are declared.
@ 2007-06-27 5:09 is+gcc at cs dot hmc dot edu
2007-06-27 7:28 ` [Bug c/32520] " pluto at agmk dot net
2007-06-27 8:59 ` rguenth at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: is+gcc at cs dot hmc dot edu @ 2007-06-27 5:09 UTC (permalink / raw)
To: gcc-bugs
Consider a snippet like the following
-----------Begin Snippet--------------
#define N 2048
int main(int argc; char *argv[])
{
int mat[N][N];
,,,
-----------End Snippet--------------
or the slightly snazified C99 style
-----------Begin Snippet--------------
int main(int argc; char *argv[])
{
...
N = strtol(argv[1], arg_end, 0);
int mat[N][N];
,,,
-----------End Snippet--------------
One would expect both of these to compile and run just fine. In fact both
compile without any problems, and for small values of N work as expected.
However, when the size of the array becomes about 8MB, the programs segfault at
run time. I get identical behaviour use both styles of declaring mat. This is
not a problem with the rest of the code. If I declare mat as an (**int) or as
an *int[N] and use malloc, then the program runs just fine for any value of N
(well, at least values of N which run in some reasonable period of time). There
is nothing sacred about it being a mutli-dimensional array. I've now reproduced
with 1d arrays, it's just that my actual code uses 2d arrays. Also, the size
limitation seems to be 8MB. If I use char instead of int, I can make the # of
elements larger until I hit 8MB.
I've had identical results both on my x86 (coppermine) Debian box using Debian
builds of gcc 3.3, 4.1 and 4.2, and also on my ppc32 Mac OS X machine with
Apple builds of gcc 3.3 and 4.0.x. Thus I think this is an issue in gcc core.
--
Summary: C/C++ programs segfault at runtime if arrays larger than
8MB are declared.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: is+gcc at cs dot hmc dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32520
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/32520] C/C++ programs segfault at runtime if arrays larger than 8MB are declared.
2007-06-27 5:09 [Bug c/32520] New: C/C++ programs segfault at runtime if arrays larger than 8MB are declared is+gcc at cs dot hmc dot edu
@ 2007-06-27 7:28 ` pluto at agmk dot net
2007-06-27 8:59 ` rguenth at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: pluto at agmk dot net @ 2007-06-27 7:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pluto at agmk dot net 2007-06-27 07:28 -------
the 8MB array overflows stack and gcc has nothing to do here
because stack size is controlled by operating system.
use ulimit -s [stack size in kB] to workaround this problem.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32520
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/32520] C/C++ programs segfault at runtime if arrays larger than 8MB are declared.
2007-06-27 5:09 [Bug c/32520] New: C/C++ programs segfault at runtime if arrays larger than 8MB are declared is+gcc at cs dot hmc dot edu
2007-06-27 7:28 ` [Bug c/32520] " pluto at agmk dot net
@ 2007-06-27 8:59 ` rguenth at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-06-27 8:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2007-06-27 08:59 -------
Adjust your available stack size.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32520
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-06-27 8:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-27 5:09 [Bug c/32520] New: C/C++ programs segfault at runtime if arrays larger than 8MB are declared is+gcc at cs dot hmc dot edu
2007-06-27 7:28 ` [Bug c/32520] " pluto at agmk dot net
2007-06-27 8:59 ` rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).