From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gery Subject: Re: reading elf section data Date: Tue, 13 Nov 2007 10:22:52 -0500 Message-ID: <4739C14C.3090608@gmail.com> References: <473856E2.5050707@gmail.com> <18232.12586.211596.82841@cerise.gclements.plus.com> <47389A8B.8030108@gmail.com> <18232.30663.274365.914938@cerise.gclements.plus.com> Reply-To: zaphod001@gmail.com Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=qP4r0RfQFiv/WDyn3sI7n/5bAAklUe7Bdm+DiIwtyX8=; b=kbkOQcTEOmGsUtrEc98cYWRTRrJUJUMJX/GSqdcFyvnAVxXKpVPZnlmnJBF7m2K2JEHY3xK6jfYtm2XtDoqKN+BtbSD4ppG0tr2ugTximldnGSnDnMAq0eFVzy5Hl8/UKGcVfD6TigAYT2I/mBH4jKsRbEhsuICL6RxAdl9mDs8= In-Reply-To: <18232.30663.274365.914938@cerise.gclements.plus.com> Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: Glynn Clements Cc: linux-c-programming@vger.kernel.org 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 : > 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 : > 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 : > 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 : > 28: 00 00 00 00 13 00 00 00 ........ > > Thank you very much :))