Include binary file?

Andrew Haley aph@redhat.com
Thu May 20 21:07:00 GMT 2010


On 05/20/2010 05:44 PM, Mark Ainsworth wrote:
> Hello, at link time I would like to include the contents of a binary
> file into the output executable, in a separate segment.  In my code I
> would then read this as an array.  I've done this before with other
> compilers / linkers, but not with gcc.  Can you show me the directives
> to do this?

I'm not aware of any gcc directive to do it.  I think objcopy can
read a binary and then make a section of it.  See the  --rename-section
section in the objcopy manual.

Like this:

objcopy -I binary -O elf64-x86-64 --rename-section .data=.mydata,alloc,load,readonly,data,contents file.txt  foo.o

Andrew.



More information about the Gcc-help mailing list