Huge binaries with objcopy

I am having problems when I define global variables in the base program on an ARM9 processor. I am using the EABI GNU compiler, and the binary code generated from 12KB elves is 4 GB! I assume that the problem is with my scatter file, but I am having problems with its head.

I have 256 KB of ROM (base address 0xFFFF0000) and 32 KB 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 as a local variable, that is, a .data section, then everything works. well. Any help was greatly appreciated.

- March 16, 2011

Can anyone help with this, I don't get anywhere and read manuals, forums, etc.

Download, compile, and objcopy commands are inserted 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

+4
source share
2 answers

I found a problem. The objcopy command will attempt to create the full address space specified in the script builder, from the lowest address to the highest, including all intermediate addresses. You can say that it just generates ROM code like this:

objcopy./main.elf -j ROM --output-target = binary./main.bin

I also changed the linker script a bit

 MEMORY { ram(WXAIL) : ORIGIN = 0x01000000, LENGTH = 32K rom(RX) : ORIGIN = 0xFFFF0000, LENGTH = 32K } SECTIONS { ROM : { *(vectors); *(.text); *(.rodata); } > rom RAM : { *(.data); *(.bss); } > ram } 
+2
source

A file is created that starts at address 0x01000000 and will contain at least up to address 0xFFFF0000. Unsurprisingly, this is almost 4 GB. What do you like? Try deleting data segments with the -R options if you do not want them (as is possible if you are preparing a ROM initialization file).

+2
source

Source: https://habr.com/ru/post/1342849/


All Articles