I have a situation where I'm hitting some limitation in the GCC tool chain.
I'm using the Uno, so I should have about 30 kB of code flash, and about 2 kB of SRAM (for globals + stack), if I read all the documentation correctly.
Yet, I'm running into problems at code sizes that are way smaller than that. Let me explain the symptoms. I have two global instances of some classes. The classes each have a small vtable, and a handful of bytes of member variables. Those instances, in turn, reference a hundred bytes or so of PROGMEM data and a dozen bytes of other global data.
In the smallest case, these instances are commented out:
//Menu menu(lcd, &menuExit);
//Page main(&menu, &mainText, &mainAction);
The binary sketch size of this is 8482 bytes (of a 32256 byte maximum). This runs as expected.
Now, I can add one of the variables:
Menu menu(lcd, &menuExit);
//Page main(&menu, &mainText, &mainAction);
The binary size is 8586 bytes, and it still runs as expected.
Moving on, I can add the second variable, with the first variable still there, and the linker goes bonkers:
Menu menu(lcd, &menuExit);
Page main(&menu, &mainText, &mainAction);
Compiling this results in a binary size of only 4722 bytes, but no compiler or linker errors. The program does not run as expected. However, I don't think this is "running out of SRAM," by looking at the memory consumed. I think this is a bug in the compiler or linker, where it generates an invalid image, without generating an error to the user, and this concerns me a lot, because I don't know how to diagnose this problem.
But, the plot thickens! If I remove the first variable, only keeping the second, I get an unexplained internal linker error:
//Menu menu(lcd, &menuExit);
Page main(0, &mainText, &mainAction);
c:/code/arduino/arduino-0022/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5/crtm328p.o:(.init9+0x0): warning: internal error: out of range error
Binary sketch size: 4610 bytes (of a 32256 byte maximum)
This gives me very little to go on. I'd like to start varying the different inputs to this compilation, and examine the object files (say, with objdump or something similar), but I can't find where the Arduino software stores the intermediate build artifacts. It seems to create temporary directories, compile into there, and then wipe them all out before I can get to them.
Is there some way to avoid that deletion? Is there some way to build my sketch from the command line? Perhaps one step at a time -- gather, compile, link, as separate steps? Is there some way to know how the environment is invoking the compiler/linker so I can reproduce the exact same build under conditions I can examine? And is this documented somewhere? The documentation Wiki just seems to talk about the high-level API of the built-in libraries; perhaps there's some reference documentation that I've simply missed?
Any help on this would be appreciated.