There were several posts in stackoverflow and other places that described in detail how to embed binary drops in elf binaries.
Insert binary blocks using gcc mingw
and
C / C ++ with GCC: statically add resource files to an executable / library
- the most complete answers.
But there is a possible problem that no one mentions. Here quicky foo.txt is hidden for foo.o:
$ objdump -x foo.o foo.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .data 0000000d 00000000 00000000 00000034 2**0 CONTENTS, ALLOC, LOAD, DATA SYMBOL TABLE: 00000000 ld .data 00000000 .data 0000000d g .data 00000000 _binary_foo_txt_end 0000000d g *ABS* 00000000 _binary_foo_txt_size 00000000 g .data 00000000 _binary_foo_txt_start
Now, I really don't understand this release - is there any documentation for this stuff ??? I guess most of this is pretty obvious, "g" is global, and "l" is local, etc. Etc....
What is allocated to align the .data segment set to 0. Does this mean that I think it means? i.e.: when it comes to links, the linker will be "oh yes, wherever ..."
If you insert char data or work on x86, then you will never notice. But if you insert int data or, as I do, 16 and 32 bit data in ARM, then you can get the alignment trap at any point.
I get the feeling that this means that either objcopy needs another option to indicate the alignment of the binary blob, or it is broken, and you should not use this method at all.