This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: can we add personal information in elf file?
- From: Brian Dessent <brian at dessent dot net>
- To: vichy dot kuo at gmail dot com
- Cc: binutils at sourceware dot org
- Date: Tue, 24 Jun 2008 01:43:06 -0700
- Subject: Re: can we add personal information in elf file?
- References: <000001c8d5cc$9798d740$57273b74@sofia>
- Reply-to: binutils at sourceware dot org
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