0

I have created an object file from a binary file using objcopy as below:

objcopy -I binary -O elf32-little --rename-section .data=.text file.bin file.o

In one of the linker script sections I have included the following to place that file into that section:

file.o (.text)

But I get the following error:

skipping incompatible file.o when searching for file.o

error: ld returned 1 exit status

I am developing for a arm microcontroller so I believe the file format "elf32-little" is correct.

Any help is much appreciated.

##################################################################### UPDATE FOLLOWING THE INCBIN path:

I have tried a new approach and although I have made some progress still not quite yet there.

This is my assembly file:

            .section .text.audio_binary
            .global audio_start
    audio_start:
            .incbin "AudioData.bin"

            .global audio_start
    audio_end:
            .byte 0

        .global audio_size
audio_size:
        .int audio_start - audio_start

This is the object file I get:

raw_audio_binary.o:     file format elf32-little

SYMBOL TABLE:
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .text.audio_binary 00000000 .text.audio_binary
00069a78 l       .text.audio_binary 00000000 audio_end
00000000 l       .text.audio_binary 00000000 $d
00000000 l    d  .ARM.attributes    00000000 .ARM.attributes
00000000 g       .text.audio_binary 00000000 audio_start
00069a79 g       .text.audio_binary 00000000 audio_size

And this is the section I have in my linker script:

    .text_Flash3 : ALIGN(4)
    {
       FILL(0xff)
        *(.text.$Flash3*)
        *(.text.$AUDIO*)        *(.rodata.$Flash3*)
        *(.text.audio_binary*) /* audio binary */      
        *(.rodata.$AUDIO*)    } > AUDIO

For some reason the linker does NOT place the data in this section (or in any).

Any ideas what is wrong?

I apologise in advance if something is very wrong here, I am new to linker scripts so still understanding them...

maverick
  • 31
  • 4
  • if you build a test object, a few lines of asm, with that toolchain what does objdump or readelf show for the elf32 type? – old_timer Jul 18 '18 at 23:00
  • It shows elf32-little, I had already checked the objects produced for different c source files. – maverick Jul 18 '18 at 23:03
  • keep working on the linker approach rather than trying to backdoor it like that. – old_timer Jul 18 '18 at 23:06
  • Sorry I don't quite understand your last comment... – maverick Jul 18 '18 at 23:10
  • I am not trying a backdoor, I have a binary file with audio data that I need to place in flash at build time, if you have a better approach please let me know. – maverick Jul 19 '18 at 07:20
  • backdoor meaning change the section after the fact rather than just put it in the desired place from the start. If it is data why is it being marked as .text? – old_timer Jul 19 '18 at 14:38
  • It is marked as. text because it is constant, it will not change. – maverick Jul 19 '18 at 15:07
  • then why are you trying to change it to a .data? why not make it a .rodata? or just a .data? what is the problem you are trying to solve here? to get the objcopy command to work or to create an object with a .data section? are you simply trying to make a .bin from file.o? you can arm-whatever-ld -Ttext=0 file.o -o file.elf and ignore the _start warning arm-whatever-objcopy -O binary file.elf file.bin you might not need to even stop at the linked elf you can perhaps arm-x-objcopy file.o -O binary file.bin perhaps the only issue here is you have your files backward on the command line? – old_timer Jul 19 '18 at 15:15
  • what is your input and what is your output? the .bin is the file you want to create? you need file.o then file.bin...if you are trying to create an object from a raw binary then I also can see what you are trying, the answer below or what I simply do is create a program to create a file C or asm with that data in it unsigned char data[] = { fprintf of data from file } or .word data from file then compile or assemble. the .incbin shown in the answer is easier, no adhoc program required...Im going to have to remember that one and save myself some time. – old_timer Jul 19 '18 at 15:17

1 Answers1

1

If you have a sufficiently recent version of GAS, you can use this to create an object file from a binary input file using the .incbin directive:

        .section .rodata
        .globl input_wav
input_wav:
        .incbin "input.wav"
        .globl input_wav_size
input_wav_size:
        .long . - input_wav
Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Thanks for your answer Florian, I have tried the INCBIN path but still have issues, please see the original question which I have edited with how far I have got. – maverick Jul 19 '18 at 17:41
  • Can you try a section name which starts with `.rodata.`? `.text` may have some very special treatment because it's Arm. How do you verify the section is gone? Is there a link error? – Florian Weimer Jul 19 '18 at 20:21
  • Hi Florian, I am placing this audio data object in a spifi external flash and in that flash I don't have a section called ". rodata." I have managed to move some of the code to the section text_Flash3, after I finish building I can see in the memory summary that few Kbs are placed there but not the 400Kb of the audio. – maverick Jul 19 '18 at 21:17
  • Or do you mean that I should try to place the audio binary at ".rodata.$AUDIO"? – maverick Jul 19 '18 at 21:22
  • Yes, use `.rodata.$AUDIO` or adjust the linker script. You may also need an actual symbol reference to the data before the linker preserves it. – Florian Weimer Jul 20 '18 at 06:11
  • Hi Florian, I already tried using {.rodata.$AUDIO} with no luck. What do you mean with an "actual symbol"? – maverick Jul 20 '18 at 06:37
  • Depending on the linker command line, the section is only preserved if there are actual references to it. – Florian Weimer Jul 20 '18 at 07:25
  • I have a variable in C code pointing to this section but still no luck. I don't really understand why the linker doesn't include this into the section, I am running out of ideas... – maverick Jul 20 '18 at 12:02
  • I have tried few things in the script files: when section tagged as text *(.text.audio_binary*) , when section tagged as rodata *(.rodata.audio_binary*), try including the whole file raw_audio.o. – maverick Jul 20 '18 at 12:02
  • I wonder why it is s still saying `raw_audio_binary.o: file format elf32-little`. Does the compiler produce `.o` with identical architecture markup? – Florian Weimer Jul 20 '18 at 12:17
  • Yes, all the .o produced by the compiler are elf32-little. I have checked few and its structure is quite similar to raw_audio_binary.o. – maverick Jul 20 '18 at 12:36