0

I'm trying to objcopy some elf file to ihex with following command:

arm-none-eabi-objcopy  -j .flash_vectors -j .isr_vector \
    -j .text -j .rodata ./app.elf -O ihex ./app.hex

and I'm trying to copy four sections to ihex. The problem is that objcopy copies only first three of them, without .rodata.

My question is why objcopy copies only the first three sections and not fourth (.rodata)?


Allocated sections from readelf

There are 25 section headers, starting at offset 0x97350:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .flash_vectors    PROGBITS        08010000 010000 000010 00   A  0   0  1
  [ 2] .isr_vector       PROGBITS        08010200 010200 0001ac 00   A  0   0 512
  [ 3] .text             PROGBITS        080103b0 0103b0 006cf0 00  AX  0   0 16
  [ 4] .rodata           PROGBITS        080170a0 0170a0 0007b4 00   A  0   0  4
  [ 5] .ARM              ARM_EXIDX       08017854 017854 000008 00  AL  3   0  4
  [ 6] .init_array       INIT_ARRAY      0801785c 01785c 000004 04  WA  0   0  4
  [ 7] .fini_array       FINI_ARRAY      08017860 017860 000004 04  WA  0   0  4
  [ 8] .data             PROGBITS        20000000 020000 000124 00  WA  0   0  4
  [ 9] .ccmram           PROGBITS        10000000 020124 000000 00   W  0   0  1
  [10] .bss              NOBITS          20000124 020124 004d3c 00  WA  0   0  4
  [11] ._user_heap_stack NOBITS          20004e60 020124 000600 00  WA  0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),

Elf Info

artless noise
  • 21,212
  • 6
  • 68
  • 105
user2699113
  • 4,262
  • 3
  • 25
  • 43
  • I noticed that .rodata is after `_etext`. This is a little strange. I don't see why the `objcopy` would not work. If you just do only the `.rodata` does it copy; Ie, something wrong with the amount of sections as opposed to `.rodata`? You can use `.rodata*` wild cards as well. Generally if you don't specify `-j`sections, anything with **LOAD** in objdump file will be copied to ihex at the LMA values. This is normally what you want; if you don't copy the `.data` to flash and then initialize it in startup, you will have issues. So even if this command works you have issues. – artless noise Sep 06 '19 at 13:31
  • This looks similar to, but different from https://sourceware.org/bugzilla/show_bug.cgi?id=23947 – Employed Russian Sep 08 '19 at 10:57
  • @EmployedRussian: it is similar? Ie, to confirm the four sections are all **LOAD** and **ALLOCATE**. The referenced bug has a section with neither **LOAD** nor **ALLOCATE**. It could be a bug in `objcopy`, but I don't think it is this one. `objcopy -S -R remove.sections ./app.elf -O ihex ./app.hex` might be useful to try. – artless noise Sep 08 '19 at 14:31

0 Answers0