Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22011

Gcc objcopy get reasonable size binary

$
0
0

I am trying to create a binary from elf file with PPC GCC, I understand the the objcopy will create the whole area for the memory sections. here is my sample ld file:

MEMORY { RESETWORD: ORIGIN = 0x00f8c000, LENGTH = 0x00000020 ROM1        : ORIGIN = 0x09000040, LENGTH = 0x00000FC0}SECTIONS{    .resetword : {        *(.resetword.*)         } > RESETWORD   .startup :  {        *(.startup)    } > ROM1}

if I use objcopy -O binary demo.elf demo.bin, I will get a 131573KB bin file, basically the size is 0x09000040 + 0x00000FC0 - 0x00f8c000. so the binary is filled from 0x00f8c000 to 0x09001000. A huge area will be filled with zero from 0xF8 C020 to 0x09000040. I tried to change the Load address of .resetword section as below:

MEMORY { RESETWORD: ORIGIN = 0x00f8c000, LENGTH = 0x00000020 ROM1        : ORIGIN = 0x09000040, LENGTH = 0x00000FC0}SECTIONS{    .startup :  {        *(.startup)    } > ROM1    .resetword : AT(LOADADDR(.startup) + SIZEOF(.startup)){        *(.resetword.*)         } > RESETWORD}

the objcopy gets a 1k binary. I can see the load address of .resetword is 0x9000xxx and address is still 0x00f8c000 from map file. I think this time the objcopy starts from 0x09000040 and ends at 0x09000040 + length(.startup) + length(.resetword). I understand the logic here, but I am wondering my changes are reasonable? is there any side affect to do this change? What is the correct way to get a flashable binary in my scenario?

BTW: I tried Greenhills compiler , even with the original ld file without any loading address changes, it can generate a 1k binary, looks like Greenhills compiler doesn't put zeros between .resetword and .startup or Greenhills compiler does something similar change the load address of .resetword automatically .

Thanks!

UPDATE:

I found why GHS can make a smaller size of binary file but not sure how GCC LD file can do the same thing:the readelf gives me below information for greenhills binary:

Section Headers:  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al  [ 1] .resetword        PROGBITS        00f8c000 000960 00001c 00 AXV  0   0  2  [ 2] .startup          PROGBITS        09000040 00097c 0001b8 00 AXV  0   0  4Program Headers:  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align  LOAD           0x000960 0x00f8c000 0x00000000 0x0001c 0x0001c R E 0x2  LOAD           0x00097c 0x09000040 0x00000000 0x001b8 0x001b8 R E 0x4

but the GCC is :

Section Headers: [ 1] .startup          PROGBITS        09000040 010040 0001b8 00 AXV  0   0  1 [ 2] .resetword        PROGBITS        00f8c000 01c000 00001c 00 AXV  0   0  1Program Headers:  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align  LOAD           0x010040 0x09000040 0x09000040 0x001b8 0x001b8 R E 0x10000  LOAD           0x01c000 0x00f8c000 0x090001f8 0x0001c 0x0001c R E 0x10000

The Greenhills compiled virtual address is the addr for sections and physical address is zero , We can do that in GCC LD file ?


Viewing all articles
Browse latest Browse all 22011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>