Migrate from 4.8.4 to 5.2.1

Asked by Morten Rick

Hey All

I am trying to migrate from 4.8.4 to 5.2.1 on my project.

First it coms up with
/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'

After som google, I found this article.
http://embdev.net/topic/linker-error-undefined-reference-to-_sbrk

After implementering this. It compiles, but now uses much more RAM
Old compiler .data 2884 536871232
New compiler .data 3980 536871232

I seams to me that it hase som thing to do with malloc
If I dont use the module that uses malloc I dont have this error.

Thils is my liker setup.
arm-none-eabi-gcc-5.2.1 -Os -I..***** -DUSE_STDPERIPH_DRIVER -ffreestanding -mthumb -mcpu=cortex-m3 -Wall -Wextra -Wno-unused-parameter -Werror -mno-unaligned-access -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions ********.o -nostartfiles ../../../ICP/Common/_Build/startup_stm32f10x_hd_cpp.s -Xlinker -o../Build/CM-RC-01.elf -Xlinker -M -Xlinker -Map=../Build/CM-RC-01.map -Wl,--gc-sections -lm -T../../../ICP/Common/_Build/stm32f10x_flash_cpp.ld

Watt to do now ???

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Andre Vieira (andre-simoesdiasvieira) said :
#1

Hi Morten,

I am not sure what you are asking here. As the link points out, your original error was due to a missing implementation of _sbrk. Something you seem to have fixed. The size increase could be due to a lot of things, you mention this "module that uses malloc". Is this a new module? Could that be the reason for the increase?

Either way if size is a big concern, then I suggest you try using newlib-nano. This is a version of newlib (libc), configured in a way that is "optimized" for size instead of speed and stripped of some functionality (like C99 IO support). If that is acceptable for your use case, then you can add --specs=nano.specs to your compile (and link) command line to use newlib-nano.

Hope that helps.

Cheers,
Andre

Revision history for this message
Morten Rick (mri-b) said :
#2

The thing is that I ty to compile the same code just with a with the new compiler 5.2.1, the old one is 4.8.4

The new one first complains about missing '_sbrk_r' and this is related to malloc.

So with the same options/arguments why dose the new compiler need this more things(functions / RAM) for malloc.

Revision history for this message
Andre Vieira (andre-simoesdiasvieira) said :
#3

Looking at the malloc used in 4.8, it shows it also required sbrk. So that means that with the old compiler you weren't using malloc.

So it could be due to:
- the compiler could now be using library code (that directly or indirectly calls malloc) where it didn't used to;
- functions you use from libc could now be using malloc where they didn't use to.

Try adding '-Wl,Map=map.output' to your command line and search map.output for malloc or _malloc_r, that way you might be able to find out where malloc is being used.

Can you help with this problem?

Provide an answer of your own, or ask Morten Rick for more information if necessary.

To post a message you must log in.