I am tying to use objcopy to include a binary form of a text file into an executable. (At runtime I need the file as a string). This works fine until the linker
Generic method of including raw data into ELF is supported by .incbin assembler directive.
The trick is to create template .S file that could look like this:
.global foo_start
foo_start:
.incbin "foo.raw"
.global foo_end
foo_end:
This file is preprocessed via cpp so we don't have to hardcode file name there, eg. we can write:
.incbin __raw_file_path__
... and then pass it while compiling:
gcc -D__raw_file_path__='"data/foo.png"' foo.S -c -o data/foo.o
Lastly, as we prepare .S file ourself we can add some extra data and/or information. If you include raw "text files" and want these to be available as C strings you can add '0' byte just after raw data:
.global foo_start
foo_start:
.incbin "foo.raw"
.global foo_end
foo_end:
.byte 0
.global foo_size
foo_size:
.int foo_end - foo_start
If you want full-blown flexibility, you can of course pre-process file manually to alter any part of it, eg.
.global @sym@_start
@sym@_start:
.incbin "@file@"
.global @sym@_end
@sym@_end:
... and then compile it:
sed -e "s,@sym@,passwd,g" -e "s,@file@,/etc/passwd,"