This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: simplest way to get the size of an output section
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Cc: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- Date: Mon, 4 Oct 2004 15:59:55 +0100
- Subject: Re: simplest way to get the size of an output section
- Organization: CodeSourcery
- References: <20041004140653.67109.qmail@web11801.mail.yahoo.com>
On Monday 04 October 2004 15:06, Etienne Lorrain wrote:
> --- Daniel Jacobowitz <drow@false.org> a écrit?:
> > On Mon, Oct 04, 2004 at 11:51:01AM +0200, Etienne Lorrain wrote:
> > > On a Linux ia32 system, I am trying to get the size of an output
> > > section of an ELF file to use it automatically in a Makefile.
> > >
> > > Ideally I would like to compile a small GCC program like:
> > > gcc -Wl,--defsym,linker_tells_size=SIZEOF(.text16) print_command_line.c
> > > but that will not work because --defsym cannot get the SIZEOF().
> > >
> > > So I have gone the objcopy way:
> > > objcopy --output-target binary --only-section .text16 vmlinux param.bin
> > > ./print_command_line ` cat param.bin | wc -c `
> > > That does the job, but is there a way to not create the temporary file
> > > "param.bin" (i.e. objcopy uses standard output) (because it is always
> > > a problem in Makefiles: it may already exist and be write protected,
> > > it needs to be cleaned by make clean, an interrupted make command
> > > may leave the temporary file...) or another way, without using too
> > > complex awk or sed scripts?
> >
> > Why not use objdump -h or readelf -S?
>
> Basically because of the complexity of the sed or awk to get back the
> hexadecimal number (in a Makefile):
> readelf gives all the sections, so (not tested - not a real awk master)
> ./print_command_line ` readelf -S vmlinux | awk "/.text16/ {printf $...}" `
> objdump - when I tried yesterday - wanted the number of the input
> section and need quite a complex filtering of the standard output too.
How about "size -A"
Paul