You can use the GNU linker (ld) to create a new executable that's identical as the old one, but additionally contains the section from a new file. Well, in theory. So far I haven't gotten it to work as hoped. Attached are the files you can use for playing around.
First, you take a C source file that contains only static strings:
static char* __version = "sample 1.0";
static char* __author = "otheus@gmail.com";
Second, you compile it as usual with a C compiler to an object file.
gcc -o version_tmp.o -c version.c
Third, create a ld script file that will be used by ldto create an object file containing the static strings in your source, but in a ".comment" section.
SECTIONS
{
.comment 0 : { *(.rodata) }
/DISCARD/ : { *(.text .bss .data .comment .note.GNU-stack) }
}
Fourth, use the linker with this special ld script file ("commentsonly.lds") on your object file (created above with the gcc command). Now, instead of the strings being in the ".rodata" section, they are stored in the ".comment" section. Use the -r option so an object file is created.
ld -r -T commentsonly.lds -o version.o version_tmp.o
Finally, relink the original program with the new object file:
ld -o new_executable original_executable version.o
Now you can confirm the data is stored in this file using readelf or objdump:
objdump -s -j .comment new_executable
Here you should see the data you stored in your .c program.
So what happens. When I tried it, I got a segmentation fault. I suspect you have to do some address juggling to get this to work right. Let me know if you get anywhere?