can we add personal information in elf file?
Brian Dessent
brian@dessent.net
Tue Jun 24 18:27:00 GMT 2008
vichy wrote:
> I have a script which can build my source code as ELF daily, but I want to
> add my personal information in elf file, such that I can not only identify
> the file by date but also by the information I added.
> I have seen the format of elf, but there seems have no space to put
> user-defined information in ELF header.
> If someone has the same experience or knows where we can put user-defined
> information in elf, please let me know.
There's no need to invent any special header fields, just use a named
section marked noload. The compiler already does something like this
with .comment to identify the version and options used etc.
$ echo 'int main() { puts ("Hello world"); }' | gcc -x c - -c -o hello.o
$ echo "this is my special data" >mydata
$ objcopy --add-section .mydata=mydata \
--set-section-flags .mydata=noload,readonly hello.o hello2.o
$ gcc hello2.o -o hello
$ ./hello
Hello world
$ objdump -sj .mydata hello
hello: file format elf32-i386
Contents of section .mydata:
0000 74686973 20697320 6d792073 70656369 this is my speci
0010 616c2064 6174610a al data.
Brian
More information about the Binutils
mailing list