Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc compile time and memory usage changing as array size in source code changes

Tags:

gcc

This is gcc 4.4.6 on Linux.

Here's the behavior

bizarre.c

double a[500000000];

main() {
}

If I compile this using:

gcc bizarre.c

Then the compiler uses 4G of memory, and takes a long time.

If I make the array size 50000000, the the compilation takes considerably less memory and time.

It's like the compiler is executing the code that it's compiling.

I realize that creating a humongous array this way might not be best practice, but any explanations?

like image 673
Alan Avatar asked Jun 15 '12 01:06

Alan


1 Answers

It's a known linker bug related to --build-id, now fixed on mainline. See http://sourceware.org/bugzilla/show_bug.cgi?id=12451 Some distros took an earlier patch of Nick's that needlessly calculated a checksum over .bss, requiring the .bss section to be allocated and zeroed. Complain to your distro.

like image 104
Alan Modra Avatar answered Oct 22 '22 00:10

Alan Modra