I'm trying to move a section from a proprietary binary into my own object file so that I can link against it. However the ARM architecture data is not being properly added to the generated object file, so it does not link into the final executable.
I do this with the following command:
arm-none-eabi-objcopy --rename-section .data=.rodata,contents,alloc,load,readonly,data
-I binary -O elf32-littlearm -B arm prop_fw.bin fw_data.o
When I try to link this object file into my executable, I get:
arm-none-eabi-ld: error: ../fw_lib.a(fw_data.o): Conflicting CPU architectures 13/0
This seems to be because there is no ARM architecture data in the generated object. I've compared my generated fw_data.o to an object file generated by the compiler (main.o for example) using objdump and readelf. Object files that successfully link all seem to have the .ARM.attributes
section which my generated object does not.
Just as a test, I manually dumped that section from main.o and added it to my objcopy command:
arm-none-eabi-objcopy --rename-section .data=.rodata,contents,alloc,load,readonly,data
-I binary -O elf32-littlearm -B arm prop_fw.bin fw_data.o
--add-section .ARM.attributes=attributes_dump.bin
This successfully adds the section to the object, but the compiler does not seem to pick it up and it still fails to link. Comparing main.o and fw_data.o I see that the sections differ in their TYPE:
main.o
[31] .ARM.attributes ARM_ATTRIBUTES 00000000 001abc 000033 00 0 0 1
fw_data.o
[ 3] .ARM.attributes PROGBITS 00000000 0078b9 000033 00 0 0 1
I have also tried dumping the .data section to a file and using ld to create fw_data.o as this question suggests: What's the "correct" way to determine target and architecture for GNU binutils?
arm-none-eabi-objcopy --dump-section .data=fw_data.bin -I binary -O elf32-littlearm -B arm prop_fw.bin
arm-none-eabi-ld -r -b binary -A elf32-littlearm -o fw_data.o fw_data.bin
This leads to the same problem with the generated fw_data.o
and it still fails to link.
How can I properly set the ARM_ATTRIBUTES section in an object file that I am generating with objcopy?