2

Already read this but cannot solve my problem.

huge binary files with objcopy

For some testing need. I have to add following link script when link.

.section_test 0x11323000: {  *(.section_test) }

This self-defined section must start at a big address 0x11323000.

Then use objcopymips to generate the raw binary file

objcopymips -O binary vxWorks.st E0122.bin    

This step makes the final raw binary file,the bin file, too big. from 27MB to more than 270MB.

In this way it cannot be loaded in our machine which only have around 64MB physical memory.

Can I reduce the size of it without remove any sections and still let it be executable?

Community
  • 1
  • 1
oyss
  • 662
  • 1
  • 8
  • 20

1 Answers1

4

objcopy -O binary produces the memory image of the program, based on the load address of sections. In your case, the load and the runtime address of .section_test are the same, i.e. the load address is 0x11323000 which explains the big file size.

The usual solution is to create an executable with compact load image and have the program itself copy the necessary parts from their load address to their runtime address before they are used.

Example:

.section_test 0x11323000 : AT(some-small-address) {  *(.section_test) }

or

.section_test 0x11323000 : {  *(.section_test) } AT> some-region-name

Check this page as well: https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html#Output-Section-LMA

chill
  • 16,470
  • 2
  • 40
  • 44
  • perfect answer, thanks a lot! I've check this manual before but missed this part.... – oyss Sep 27 '13 at 04:05
  • I understand the answer, but why bss section is not included in the big file ? (in the example in the above link) - bss section has no "AT" – ransh Jun 06 '17 at 20:04