带有 objcopy 的巨大二进制文件 [英] huge binary files with objcopy
问题描述
我在 ARM9 处理器的基本 C 程序中定义全局变量时遇到问题.我正在使用 EABI GNU 编译器,从 12KB 精灵生成的二进制文件是 4GB!我认为问题出在我的分散文件上,但我无法理解它.
我有 256KB 的 ROM(基址 0xFFFF0000)和 32KB 的 RAM(基址 0x01000000)
SECTIONS {.= 0xFFFF0000;.文本 : {*(向量);* (.文本);}.rodata : { *(.rodata) }.= 0x01000000;sbss = .;.data : { *(.data) }.bss : { *(.bss) }ebss = .;bssSize = ebss - sbss;}
我的程序如下:
int a=10;int main() {int b=5;b = (a>b)?一:乙;返回 b;};
如果我将 a 声明为局部变量,即没有 .data 部分,那么一切正常.美好的.非常感谢任何帮助.
--2011 年 3 月 16 日--
任何人都可以帮助解决这个问题,我无处可去,并且已经阅读了手册、论坛等...
我的boot、compile命令和objcopy命令贴在下面
.section "vectors"重置:b 开始undef: b undefswi: b swipabt: b pabtdabt: b dabt没有irq: b irqfiq: b fiq
.text开始:ldr sp, =0x01006000主线停止: b 停止
<块引用>
arm-none-eabi-gcc -mcpu=arm926ej-s -Wall -nostartfiles -Wall main.c boot.s -o main.elf -T \ scatter_file
arm-none-eabi-objcopy ./main.elf --output-target=binary ./main.bin
arm-none-eabi-objdump ./main.elf --disassemble-all > ./main.dis
我发现了问题.objcopy 命令将尝试创建链接描述文件中描述的整个地址空间,从最低地址到最高地址,包括其间的所有内容.您可以告诉它只生成 ROM 代码,如下所示:
<块引用>objcopy ./main.elf -j ROM --output-target=binary ./main.bin
我也稍微改变了链接脚本
MEMORY {ram(WXAIL):原点= 0x01000000,长度= 32Krom(RX):原点 = 0xFFFF0000,长度 = 32K}部分{只读存储器 : {*(向量);*(.文本);*(.rodata);} >只读存储器内存 : {*(.数据);*(.bss);} >内存}
Im having problems when I define global variables in a basic C program for an ARM9 processor. I'm using EABI GNU compiler and the binary generated from a 12KB elf is 4GB! I assume the issue is with my scatter file but Im having trouble getting my head around it.
I have 256KB of ROM (base address 0xFFFF0000) and 32KBs of RAM (base 0x01000000)
SECTIONS {
. = 0xFFFF0000;
.text : {
* (vectors);
* (.text);
}
.rodata : { *(.rodata) }
. = 0x01000000;
sbss = .;
.data : { *(.data) }
.bss : { *(.bss) }
ebss = .;
bssSize = ebss - sbss;
}
And my program is as follows:
int a=10;
int main() {
int b=5;
b = (a>b)? a : b;
return b;
};
If I declare a as a local variable, i.e. there is no .data section then everything works. fine. Any help greatly appreciated.
--16th March 2011--
Can anyone help with this, Im getting nowhere and have read the manuals, forums etc...
My boot, compile command and objcopy commands are pasted below
.section "vectors" reset: b start undef: b undef swi: b swi pabt: b pabt dabt: b dabt nop irq: b irq fiq: b fiq
.text
start:
ldr sp, =0x01006000
bl main
stop: b stop
arm-none-eabi-gcc -mcpu=arm926ej-s -Wall -nostartfiles -Wall main.c boot.s -o main.elf -T \ scatter_file
arm-none-eabi-objcopy ./main.elf --output-target=binary ./main.bin
arm-none-eabi-objdump ./main.elf --disassemble-all > ./main.dis
I found the problem. The objcopy command will try to create the entire address space described in the linker script, from the lowest address to the highest including everything in between. You can tell it to just generate the ROM code as follows:
objcopy ./main.elf -j ROM --output-target=binary ./main.bin
I also changed the linker script slightly
MEMORY {
ram(WXAIL) : ORIGIN = 0x01000000, LENGTH = 32K
rom(RX) : ORIGIN = 0xFFFF0000, LENGTH = 32K
}
SECTIONS {
ROM : {
*(vectors);
*(.text);
*(.rodata);
} > rom
RAM : {
*(.data);
*(.bss);
} > ram
}
这篇关于带有 objcopy 的巨大二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!