gpt4 book ai didi

c - 区域 ram 溢出,section .text 不适合区域 ram

转载 作者:太空宇宙 更新时间:2023-11-04 03:24:50 28 4
gpt4 key购买 nike

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

我认为问题不在链接描述文件中,而在其他方面。我看到编译器试图将项目中的所有 .c 文件添加到一个 .axf 文件中的消息,即使我在主 .c< 中不包含任何文件也是如此 文件(我写程序的地方)当我从项目中删除一些未使用的 .c 文件时,它说 “Region ram overflowed by 275433 bytes”(不同的溢出大小) .我应该怎么做才能摆脱这个错误?

最佳答案

flash.ld

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

闪光.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 部分基本上就是您的程序本身,对于分配给它的“内存”来说太大了。如果您使用的链接描述文件反射(reflect)了您分配的真实大小,则您的程序太大,您需要将其变小,如果您不是(gcc 命令行上的 -O2)或将 static 放入,则可以从优化开始非全局函数的前面,或者只是通过清理整体减少代码量。这并不意味着将几行 C 变成一长行 C 而不删除任何实际功能,您需要让它做更少的事情。

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

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

关于c - 区域 ram 溢出,section .text 不适合区域 ram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041390/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com