c - 如何在链接器文件中添加堆内存
问题描述
嗨,我最近正在研究 RiscV Ibex 内核,由于我的 FPGA 内存不足,我必须在我的 C 代码中使用动态内存分配(malloc() 和 free())。但是我应该首先在链接器文件中定义堆内存,以便我可以使用这个函数。有谁知道我该怎么做?或者无论如何使用这个函数来定义 Ibex 核心的堆栈内存?这是 Ibex 的链接器文件:
OUTPUT_ARCH(riscv)
/* required to correctly link newlib */
GROUP( -lc -lgloss -lgcc -lsupc++ )
SEARCH_DIR(.)
__DYNAMIC = 0;
MEMORY
{
rom : ORIGIN = 0x00000000, LENGTH = 0x36800 /* 218 kB */
stack : ORIGIN = 0x00036800, LENGTH = 0x4F000 /* 316 kB */
}
/* Stack information variables */
_min_stack = 0x2000; /* 8K - minimum stack space to reserve */
_stack_len = LENGTH(stack);
_stack_start = ORIGIN(stack) + LENGTH(stack);
/* We have to align each sector to word boundaries as our current s19->slm
* conversion scripts are not able to handle non-word aligned sections. */
SECTIONS
{
.vectors :
{
. = ALIGN(4);
KEEP(*(.vectors))
} > rom
.text : {
. = ALIGN(4);
_stext = .;
*(.text)
*(.text.*)
_etext = .;
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(.ctors)
LONG(0)
__CTOR_END__ = .;
__DTOR_LIST__ = .;
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
*(.dtors)
LONG(0)
__DTOR_END__ = .;
*(.lit)
*(.shdata)
. = ALIGN(4);
_endtext = .;
} > rom
.rodata : {
. = ALIGN(4);
*(.rodata);
*(.rodata.*)
} > rom
.shbss :
{
. = ALIGN(4);
*(.shbss)
} > rom
.data : {
. = ALIGN(4);
sdata = .;
_sdata = .;
*(.data);
*(.data.*)
edata = .;
_edata = .;
} > rom
.bss :
{
. = ALIGN(4);
_bss_start = .;
*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)
*(COMMON)
_bss_end = .;
} > rom
/* ensure there is enough room for stack */
.stack (NOLOAD): {
. = ALIGN(4);
. = . + _min_stack ;
. = ALIGN(4);
stack = . ;
_stack = . ;
} > stack
.stab 0 (NOLOAD) :
{
[ .stab ]
}
.stabstr 0 (NOLOAD) :
{
[ .stabstr ]
}
}
解决方案
推荐阅读
- c# - 名称与集合匹配的 Lucene 查询文档
- python - 如何在中心重复值时填充numpy数组
- java - 尝试调用虚拟方法 'void android.view.View.setAlpha(float)
- c# - 将数据从控制器传递给 GetVaryByCustomString
- mysql - 外键是否必要?
- python - 使用“大于或等于”(>=) 时无法理解包含的内容
- javascript - 同步内容加载
- node.js - 启用了 NodeJS 压缩,但使用 Angular 前端的灯塔审计仍然性能不佳
- python - 相邻列与新列的 Pandas 比较(布尔值)
- c# - 如何路由到子控制器覆盖 API 而不是基本控制器 API