On AVR-GCC, how can I find out what statically initialized variable is using up my RAM?
If you have a statically initialized variable like...

const int numbers[] = { 12 , 13 , 4 , 17 , 12 , 9 };

...then it will not only use up flash, but also RAM even though it is const. To keep it from using up RAM, you must make it PROGMEM - but first you have to find which variable is using up the RAM which can be very hard if it is declared with static scope like this...

static const int numbers[] = { 12 , 13 , 4 , 17 , 12 , 9 };

...since then it will not show up individually in the MAP file.

To track these down, you use use the debug info in the ELF file. Here is a Linux command line that will use the BINUTILS to list all of the variables in a file including the statically scoped ones...

avr-readelf -a example.elf | sort -k 2


The stuff between the __data_start and __data_end are the variables that will be copied from flash into RAM...

99: 00800100     0 NOTYPE  GLOBAL DEFAULT    1 __data_start
 1: 00800100     0 SECTION LOCAL  DEFAULT    1
38: 00800100    12 OBJECT  LOCAL  DEFAULT    1 _ZL7numbers
77: 0080010c     0 NOTYPE  GLOBAL DEFAULT    1 __data_end
91: 0080010c     0 NOTYPE  GLOBAL DEFAULT    1 _edata


You can ignore the 1st number. The 2nd number is the address in the FLASH that the static data landed at, and the 3rd number is the number of bytes used (in this case 12 bytes). Now you can track those down and make them into PROGMEM and save some RAM.