Hello !
I am using Code Sourcery's GNU toolchain to code for the LXPXpresso
LPC1769 board.
Just a word before you think I understand more than I do : this is my
first step outside of the arduino world ( after a few days in the mBed
world ).
So I'm trying to code for it in C++. A simple "blinking" example works
ok.
But when I try to do oop, and use the "new" keyword, the program's size
explodes :
Without the "new" keyword :
1 | arm-none-eabi-size main.elf
|
2 | text data bss dec hex filename
|
3 | 768 8 8 784 310 main.elf
|
With the "new" keyword :
1 | arm-none-eabi-size main.elf
|
2 | text data bss dec hex filename
|
3 | 82264 1424 2136 85824 14f40 main.elf
|
That's a lot of flash usage for just a small keyword. A similar test in
the mBed online compiler gives no visible difference ( it rounds code
size to kilobytes ) between using new or not using it.
So I have googled quite a lot about this. The most usefull command I
have found is this :
1 | arm-none-eabi-nm --demangle --print-size --size-sort --reverse-sort -S main.elf
|
2 | 00003400 00005202 t d_print_comp
|
3 | 0000d190 00001640 T _svfprintf_r
|
4 | 00008604 00000ede t d_print_mod
|
5 | 0000eb2c 00000eba T _dtoa_r
|
6 | 00010db4 00000ae0 T _svfiprintf_r
|
7 | 100005a8 00000800 b emergency_buffer
|
8 | 00001ad8 0000071c t d_type
|
9 | 000094e4 00000696 t d_print_mod_list
|
10 | 0000bd18 0000057a T _malloc_r
|
11 | 0000298c 00000544 t d_encoding
|
12 | 0000c790 0000041c T _realloc_r
|
13 | 10000100 00000408 D __malloc_av_
|
14 | etc ...
|
So it looks like using the new keyword also gets printf and other space
consuming things into the program. I don't want it to do that, that's
stupid.
It seems like there are two reasons why it would do that ( from what I
have googled, I understand like 3% of it ) :
1. Maybe it puts all of libstdc++ into the program, and does not delete
what is not needed.
But the makefile does -ffunction-sections at compilation and
--gc-sections at linking, and from what I have understood if you do that
useless stuff gets discarded. So either --gc-sections does not work, or
that's not the problem.
2. Maybe it includes code for "exceptions", which from what I understand
( probably wrong ) is like runtime errors or something. So it would make
sense it needs printf to report errors ... The problem is that in my
makefile I have -fno-exceptions. So either -fno-exceptions does not work
correctly, or it is not the problem ...
This is as far as I was able to go with my knowledge and google ...
I am attaching a zip of the project ( it's like a frankeinstein
creature, with bits of everything I was able to find on the internet,
please don't mock it ).
I would be extremely gratefull for any help in getting the code size to
a reasonable size.
Thank you very much in advance for your help !
Arthur.