This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcc for AMD x86 does not allow to use large static array of 4GB or more.
- From: "Murakami Hiroshi" <dm at tmca dot ac dot jp>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 11 Jan 2004 21:39:08 +0900 (JST)
- Subject: gcc for AMD x86 does not allow to use large static array of 4GB or more.
Dear, GCC bugs,
This is a sample C source code for the gcc 3.3.1 on AMD x64
to show that the static array allocation fails for the large
array as large as 4GB or more. (This may be a loader bug, though.)
The gcc compiler compiles without any warning or error messages fine,
however the size information with a.out is bad.
If the size of a static array is more than 4GB, the size is
computed as if the size were modulo 4GB. On the other hand the
C language function sizeof(array) gives the correct size in bytes
which is larger than 2^32 instead.
Since the AMD x64 is 64bit system, it is quite desirable to allow
any single array may be of its size 4GB or more. But, current
implementation is not and we have no way other than to use
malloc or calloc to obtain the large array of 4GB or more.
Hiroshi Murakami
<dm@tmca.ac.jp>
Script started on Sun 11 Jan 2004 08:19:15 PM EST
$
$ cc -v
Reading specs from /usr/lib64/gcc-lib/amd64-mandrake-linux-gnu/3.3.1/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib64
--with-slibdir=/lib64 --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checking --enable-long-long
--enable-__cxa_atexit --enable-languages=c,c++,ada,f77,objc,java,pascal
--host=amd64-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.3.1 (Mandrake Linux 9.2 3.3.1-4mdk)
$
$
$
$ cc a.c
$ size a.out
text data bss dec hex filename
1116 504 32 1652 674 a.out
$
$
$
$ cat a.c
//============================================================
//
// This short sample program demonstrates a problem of
// the gcc for AMD x64.
// If the size of the static array is defined with a size
// not smaller than 4GB(=2^32), its size is chopped with
// modulo 4GB. (The array may be char or float of double or
// long double or any type of array.)
//
//#define N ((1UL<<32)-1) // This works. $ size a.out gives about 4GB.
#define N ((1UL<<32)) // This does not. $ size a.out gives very small size.
static char a[N]; // A large static array.
int main()
{
long int i,s;
for(i=0;i<N;i++) {a[i]=i;}
for(s=0,i=0;i<N;i++) s+=a[i];
return 0;
}
//============================================================
$ exit
exit
Script done on Sun 11 Jan 2004 08:19:54 PM EST