Removing heap allocation using linkscripts

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Removing heap allocation using linkscripts

ソリューションへジャンプ
2,088件の閲覧回数
eaad
Contributor II

Hello,

In the project im involved in, we're using nxp product that runs FreeRTOS as os. As our application does not allocate dynamic memory using the ordinary mallocs, I want to remove the heap allocation that the linker puts in the binary.

The method for this is to put the relevant ldt file in the linkscripts folder, which I did- specifically by overriding the heap size to be zero. this works.

How ever, it will be better for me if I could just discard the symbol of the heap from the binary (heap_symbol which is set to _pvHeapStart) because otherwise this symbol gets its address, and it is possible to override memory using its address. My problem is that when im just discarding it I get references errors of gcc files (_cr_sbrk.c) expecting this reference.

I would like to ask for a help reaching my goal which is safely remove the heap allocation from the linker.

 

Thanks

0 件の賞賛
返信
1 解決策
2,066件の閲覧回数
eaad
Contributor II

I just want to update that I found a good enough solution, based on this post: https://stackoverflow.com/questions/40130374/gcc-how-to-disable-heap-usage-entirely-on-an-mcu

(idea is to redirect dynamic memory allocation methods to unimplemented method, which leads to linker errors if one uses them)

元の投稿で解決策を見る

5 返答(返信)
2,067件の閲覧回数
eaad
Contributor II

I just want to update that I found a good enough solution, based on this post: https://stackoverflow.com/questions/40130374/gcc-how-to-disable-heap-usage-entirely-on-an-mcu

(idea is to redirect dynamic memory allocation methods to unimplemented method, which leads to linker errors if one uses them)

2,047件の閲覧回数
ErichStyger
Specialist I

Hi @eaad ,

In case you want use FreeMarker Scripts or in general check if malloc() is still used, maybe this helps: https://mcuoneclipse.com/2022/11/06/how-to-make-sure-no-dynamic-memory-is-used/

Erich

2,032件の閲覧回数
eaad
Contributor II


Hi @ErichStyger, thank you. Actually i was trying the approach of removing the definition of the heap using the FreeMarker Scripts, but I was not able to overcome the __sbrk function error that comes on the linking stage, And even though the map gives me the list, what is a way to overcome that issue?

i get a libc reference:

/usr/local/mcuxpressoide-11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.linux_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libcr_c.a(alloc.o)
max_utilize_stack.lto_priv.0

what do you think? i couldn't figure that from the article. btw, as you said there, i prefer removing the definition in addition to redirecting the malloc/free ops.



ty,

Efraim
0 件の賞賛
返信
2,020件の閲覧回数
ErichStyger
Specialist I

If __sbrk is still referenced, it means that your application is still possibly calling malloc() or any other dynamic memory allocator.

I suggest you link with the heap in the linker script enabled and then use the Image Info to find out who is calling/using malloc and sbrk. Most likely it is a printf() somewhere in your code?

0 件の賞賛
返信
2,012件の閲覧回数
eaad
Contributor II

Yea, I will re do that, and update about my findings

0 件の賞賛
返信