linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gery <zaphod001@gmail.com>
To: Glynn Clements <glynn@gclements.plus.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: reading elf section data
Date: Tue, 13 Nov 2007 10:22:52 -0500	[thread overview]
Message-ID: <4739C14C.3090608@gmail.com> (raw)
In-Reply-To: <18232.30663.274365.914938@cerise.gclements.plus.com>

Glynn Clements wrote:
> Gery wrote:
>
>   
>> i put some structure with gcc attribute to special section named ".my_sec"
>> The structure is like
>> struct abc {
>> char *a;
>> char *b;
>> };
>> and global variable is
>> struct abc klm = { "this is 1st string", "this is 2nd string" };
>>     
>
> Like this:
>
> struct abc klm __attribute__ ((section (".my_sec"))) = { "this is 1st string", "this is 2nd string" };
>
> ?
>
>   
>> Which utility can show me just the data of that section?
>>     
>
> 	$ objdump -j .my_sec -d foo.o
>
> 	foo.o:     file format elf32-i386
> 	
> 	Disassembly of section .my_sec:
> 	
> 	00000000 <klm>:
> 	   0:	00 00 00 00 13 00 00 00                             ........
>
> Bear in mind that the structure only contains the pointers, not the
> strings themselves. String literals used as values are stored in the
> .rodata section. If you want them elsewhere, you'll have to store them
> in named variables, e.g.:
>
> 	static char s1[] __attribute__ ((section (".my_sec"))) = "this is 1st string";
> 	static char s2[] __attribute__ ((section (".my_sec"))) = "this is 2nd string";
> 	struct abc klm __attribute__ ((section (".my_sec"))) = { s1, s2 };
>
> 	$ objdump -j .my_sec -d foo.o
>
> 	foo.o:     file format elf32-i386
> 	
> 	Disassembly of section .my_sec:
> 	
> 	00000000 <s1>:
> 	   0:	74 68 69 73 20 69 73 20 31 73 74 20 73 74 72 69     this is 1st stri
> 	  10:	6e 67 00                                            ng.
> 	
> 	00000013 <s2>:
> 	  13:	74 68 69 73 20 69 73 20 32 6e 64 20 73 74 72 69     this is 2nd stri
> 	  23:	6e 67 00 00 00                                      ng...
> 	
> 	00000028 <klm>:
> 	  28:	00 00 00 00 13 00 00 00                             ........
>
>   
Thank you very much :))

  reply	other threads:[~2007-11-13 15:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-12 13:36 reading elf section data Gery
2007-11-12 10:55 ` Glynn Clements
2007-11-12 11:29   ` Steve Graegert
2007-11-12 18:37     ` Gery
2007-11-12 12:07       ` Steve Graegert
2007-11-12 19:11         ` Gery
2007-11-12 18:25   ` Gery
2007-11-12 15:56     ` Glynn Clements
2007-11-13 15:22       ` Gery [this message]
2007-11-13  9:13 ` Kristof Provost
2007-11-13 16:22   ` Gery

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4739C14C.3090608@gmail.com \
    --to=zaphod001@gmail.com \
    --cc=glynn@gclements.plus.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).