I'm developing an embedded application using GCC/G++ compiled for arm-eabi. Due to resource constraints, I'm trying to disable the standard C++ exception handling. I'm compiling the code with "-fno-exceptions -nostartfiles -ffreestanding".
When a global instance of a class exists, and that class contains an instance of another class as a member, then a lot of exception handling code is being linked in. This wouldn't be so bad, except that it's also bringing in lots of stdio stuff, like printf, fopen, fclose and other FILE functions. This application has no filesystem, and even if it did, these functions waste too much code space.
I understand that even with -fno-exceptions, G++ links in an operator new that uses exceptions, because the library doesn't have a non-exception-using operator new (except new(nothrow)). I created replacements for operator new and delete, and these are linked into the output as well as the unwanted standard-library functions.
What puzzles me is that I'm not calling new anywhere. It's only when a global object contains another object that all this code is linked in.
For example:
class UartA {
...
private:
Ringbuffer* rxbuf;
};
class UartB {
...
private:
Ringbuffer rxbuf;
};
If a global instance of UartA is created, the exception handling, operator new, and stdio stuff are not linked in. This is what I want.
If a global instance of UartB is created (where rxbuf is an instance instead of a pointer), the unwanted code is linked in.
Neither UartA nor UartB use operator new, exceptions or stdio. They differ only by the type of rxbuf.
Can you suggest how to prevent linking the extra code? Also, why is this being linked in for UartB, but not UartA?