FoRUmS

Does stdlib for RVfpga support heap-based functions like malloc()?  

 

rkravitz
(@rkravitz)
New Member
Joined: 5 months ago
Posts: 1
08/03/2021 11:41 pm  

One of my students has reported that the C compiler for RVfpga is throwing errors whenever he tries to use memory allocation functions like malloc.   Is the heap, and malloc() and free() supported by the RVfpga tool chain?


ReplyQuote
Topic Tags
RCWO
 RCWO
(@rcwo)
Member Admin
Joined: 2 years ago
Posts: 21
11/03/2021 3:54 pm  

@rkravitz

We have this from Valerii at PlatformIO:
"The toolchain itself does support the heap memory management (it's the same GCC toolchain used across all of our RISC-V integrations). 
To better understand the problem we need a more detailed description of that error. In a nutshell, the CHIPSAlliance development platform can compile 3 different types of project:
- Bare ASM projects (simplistic linker script, no runtime, no heap memory) 
- Bare C projects (simplistic linker script, no runtime, no heap memory)
- SDK-based projects (appropriate linker script, C runtime, available heap)

Also, we need to know where the firmware is uploaded to (an FPGA board or simulator).
Without this information it'd be hard to help.
Regards, Valerii, the PlatformIO team"

 


ReplyQuote
RCWO
 RCWO
(@rcwo)
Member Admin
Joined: 2 years ago
Posts: 21
12/03/2021 11:20 am  

Luis at UCM gave us these useful comments:

Very short answer: 

  1. Although malloc is provided by the newlib library it requires an appropriate sbrk() function
  2. By default malloc wrapped is the linking process, hence it must be call using the __real_ prefix

Please find attached a very simple example that I have just tested on the fpga_board as well as on SweRV-ISS (whisper).
- File needs to be unzipped first

Thanks Luis!

This post was modified 2 months ago by RCWO

ReplyQuote
guanyang.he
(@guanyang-he)
Member Admin
Joined: 11 months ago
Posts: 26
12/03/2021 11:25 am  

Dear all,

Please find the attachment as example code.


ReplyQuote