Notifications
Clear all

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

 

(@rkravitz)
New Member
Joined: 4 years ago
Posts: 1
Topic starter  

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?


   
Quote
RCWO
 RCWO
(@rcwo)
Member Admin Registered
Joined: 5 years ago
Posts: 59
 

@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 Registered
Joined: 5 years ago
Posts: 59
 

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 4 years ago by RCWO

   
ReplyQuote
(@guanyang-he)
Estimable Member
Joined: 4 years ago
Posts: 44
 

Dear all,

Please find the attachment as example code.


   
ReplyQuote