【问题标题】:Region ram overflowed and section .text will not fit region ram区域内存溢出,部分 .text 不适合区域内存
【发布时间】:2017-06-21 20:04:57
【问题描述】:

我正在尝试使用 GCC compilator(标准 C)编译一个裸机应用程序。我使用Cyclone V SoCCortex-A9 处理器。 Eclipse DS-5。我收到一个错误 - "Region ram overflowed by 295376 bytes""section .text will not fit region ram"

我认为问题不在于链接描述文件,而在于其他问题。我看到编译器尝试将项目中的所有.c 文件添加到一个.axf 文件中的消息,即使我在我的主.c 文件(我编写程序的地方)中没有包含它们当我删除一些未使用的@987654330 @ 来自项目的文件,它说"Region ram overflowed by 275433 bytes"(不同的溢出大小)。我应该怎么做才能摆脱这个错误?

【问题讨论】:

  • 你只是在你的程序中为链接描述文件消耗了很多堆。
  • 你能解释得更准确一点吗?
  • 您的代码中某处有一个或多个全局数组,它太大而无法放入您的 RAM 区域。尝试声明一个额外的全局数组,您会看到数量增加。你必须减少全局消耗,也许减少堆栈大小。确保链接描述文件不是太“贪婪”。你这台裸机有多少内存?
  • 它有 64 kb 的 RAM,程序只执行一个简单的循环,而 (1) {led = key} 我不包括任何这些 .c 文件,它们只是在项目文件夹中
  • 好的,那么问题必须存在于您的构建环境中,该环境会自动获取项目文件夹中的所有 .c 文件。你不能把那些(无用的)文件移到其他地方吗?或者创建一个只有你的文件的项目?这可能会解决它。

标签: c gcc compilation bare-metal ds-5


【解决方案1】:

flash.ld

MEMORY
{
    ram : ORIGIN = 0x00000000, LENGTH = 0x100
}
SECTIONS
{
    .text : { *(.text*) } > ram
    .rodata : { *(.rodata*) } > ram
    .bss : { *(.bss*) } > ram
}

flash.s

.globl _start
_start:
    b reset
    b hang
    b hang
    b hang
    b hang
    b hang
    b hang
    b hang
reset:
    mov sp,#0x8000
    bl notmain
    b hang
hang:
    b hang

notmain.c

unsigned int data[1000];
int notmain ( void )
{
    unsigned int ra;
    for(ra=0;ra<1000;ra++) data[ra]=ra;
    return(0);
}

生成文件

ARMGNU = arm-none-eabi

COPS = -O2 -nostdlib -nostartfiles -ffreestanding

all : notmain.bin

clean:
    rm -f *.bin
    rm -f *.o
    rm -f *.elf
    rm -f *.list

flash.o : flash.s
    $(ARMGNU)-as $(AOPS) flash.s -o flash.o

notmain.o : notmain.c
    $(ARMGNU)-gcc $(COPS) -c notmain.c -o notmain.o

notmain.bin : flash.ld flash.o notmain.o
    $(ARMGNU)-ld -o notmain.elf -T flash.ld flash.o notmain.o
    $(ARMGNU)-objdump -D notmain.elf > notmain.list
    $(ARMGNU)-objcopy notmain.elf notmain.bin -O binary

输出:

arm-none-eabi-ld -o notmain.elf -T flash.ld flash.o notmain.o
arm-none-eabi-ld:flash.ld:10: warning: memory region `rom' not declared
arm-none-eabi-ld: notmain.elf section `.bss' will not fit in region `ram'
arm-none-eabi-ld: region `ram' overflowed by 3828 bytes
Makefile:21: recipe for target 'notmain.bin' failed
make: *** [notmain.bin] Error 1

我本可以让它说 .text 不适合,但这与您遇到的问题相同。在链接描述文件中更改大小。

ram : ORIGIN = 0x00000000, LENGTH = 0x1000

现在很开心

arm-none-eabi-ld -o notmain.elf -T flash.ld flash.o notmain.o
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy notmain.elf notmain.bin -O binary

.text 部分,基本上是您的程序本身,对于为其分配的“内存”来说太大了。如果您使用的链接描述文件反映了您分配的真实大小,您的程序太大,您需要将其缩小,如果不是,可以从优化开始(gcc命令行上的-O2)或放入静态非全局函数的前面,或者只是通过清理来整体减少代码量。这并不意味着将几行 C 变成一长行 C 而没有删除真正的功能,你需要让它做更少的事情。

或者在我的情况下,也许您有一些 .data 或 .bss 或其他项目也在链接描述文件中定义的同一部分中,并且所有这些项目的组合占用了太多空间。在我上面的示例中将长度更改为 0x10 它首先抱怨 .text 而没有其他人,如上所述,如果我将其设为 0x100 它抱怨 .bss 然后停止抱怨,所以 ld 抱怨的是积极越线的人而不是那些人那还没有被拉进去。

您可以增大长度以构建它,然后检查 elf 文件(objdump 或 readelf 或其他),然后可能会了解哪些部分确实太大,哪些功能很大或哪些数据,等等。不需要被优化器内联的全局函数等。

【讨论】:

    猜你喜欢
    • 2013-08-24
    • 2012-01-28
    • 1970-01-01
    • 2016-12-24
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多