区域ram溢出,section .text不适合区域ram [英] Region ram overflowed and section .text will not fit region ram

查看:254
本文介绍了区域ram溢出,section .text不适合区域ram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 GCC编译器(标准C)来编译裸机应用.我将 Cyclone V SoC Cortex-A9 处理器一起使用. Eclipse DS-5 .我收到一个错误-区域ram溢出295376字节" "section .text将不适合区域ram" .

我认为问题不在于链接脚本,而在于其他.我看到消息,提示编译器试图将项目中的所有 .c 文件添加到一个 .axf 文件中,即使我的主 .c <中都不包含这些文件./code>文件(在其中编写程序),当我从项目中删除一些未使用的 .c 文件时,它说区域ram溢出275433字节" (不同的溢出大小).我应该怎么做才能摆脱这个错误?

I'm trying to compile a bare-metal app with GCC compilator (Standart C). I use Cyclone V SoC with Cortex-A9 processor. Eclipse DS-5. I get an errors - "Region ram overflowed by 295376 bytes" and "section .text will not fit region ram".

I think that the problem isn't in linker script but in something else. I see messages that compiler tries to add all my .c files in project into one .axf file even if I include none of them in my main .c file (where I write the program) When I delete some unused .c files from project it says "Region ram overflowed by 275433 bytes" (different overflow size). What should I do to get rid of this mistake?

推荐答案

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

notmain.c

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

Makefile

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不适合,但这是您遇到的相同问题.在链接描述文件中更改大小.

I could have made it say .text wont fit, but it is the same problem you are having. Change the size in the linker script.

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而没有删除任何实际功能,您需要让它做更少的事情.

The .text section, which is your program itself basically, was too big for the "memory" allocated for it. If the linker script you are using reflects the true size of what you are allocated, your program is too big you need to make it smaller, can start by optimizing if you are not (-O2 on the gcc command line) or putting static in front of functions that are not global, or just overall reducing the amount of code by cleaning up. that doesnt mean make a few lines of C into one long line of C with no real functionality removed, you need to have it do fewer things.

或者像我这样,在链接器脚本中定义的同一部分中可能还有一些.data或.bss或其他项目,并且所有这些项目的组合占用了太多空间.在上面的示例中,将长度更改为0x10时,它首先抱怨.text而没有其他抱怨,如上所示,如果我将其设置为0x100,则它抱怨.bss然后停止抱怨,因此ld抱怨的是主动越线而不是那个还没拉进来.

Or as in my case here perhaps you have some .data or .bss or other items that are also in the same section defined in the linker script and the combination of all of them are taking up too much space. Changing the length to 0x10 in my example above it complains about .text first without the others, as above if I make it 0x100 it complains about .bss then stops complaining, so ld is complaining about the one that actively crosses the line not the ones that didnt get pulled in yet.

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

You can make the length larger to get it to build, then examine the elf file (objdump or readelf or whatever) and from there perhaps get an idea of what part is really too big, what functions are huge or what data, etc. Functions that are global that dont need to be that are being inlined by the optimizer, etc.

这篇关于区域ram溢出,section .text不适合区域ram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆