Include binary file with GNU ld linker script

Solution 1:

You could try using objcopy to convert it to a normal object you can link in, and then reference its symbols in the linker script like you would do to a normal object. From the objcopy manual page:

-B bfdarch --binary-architecture=bfdarch Useful when transforming a raw binary input file into an object file. In this case the output architecture can be set to bfdarch. This option will be ignored if the input file has a known bfdarch. You can access this binary data inside a program by referencing the special symbols that are created by the conversion process. These symbols are called _binary_objfile_start, _binary_objfile_end and _binary_objfile_size. e.g. you can transform a picture file into an object file and then access it in your code using these symbols.

...where objfile will be expanded to the name of the input object file.

See also the --rename-section option.

Solution 2:

You can put raw file to separate section in assembly, and then include this section in linker script.

First you need to create template .S file, eg.

.section .rawdata
.incbin "blob1.raw"

... and modify linker script to include this section as you like it:

.data : {

    *(.rawdata*)

}

You can also take a look here here for a bit more detailed information about .S template.