From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29345 invoked by alias); 23 Dec 2004 19:39:24 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 29284 invoked from network); 23 Dec 2004 19:39:12 -0000 Received: from unknown (HELO mproxy.gmail.com) (216.239.56.245) by sourceware.org with SMTP; 23 Dec 2004 19:39:12 -0000 Received: by mproxy.gmail.com with SMTP id w41so125350cwb for ; Thu, 23 Dec 2004 11:39:12 -0800 (PST) Received: by 10.11.94.29 with SMTP id r29mr336834cwb; Thu, 23 Dec 2004 11:39:12 -0800 (PST) Received: by 10.11.99.52 with HTTP; Thu, 23 Dec 2004 11:39:12 -0800 (PST) Message-ID: <7f45d93904122311394f9e1fc4@mail.gmail.com> Date: Thu, 23 Dec 2004 19:39:00 -0000 From: Shaun Jackman Reply-To: Shaun Jackman To: binutils@sources.redhat.com Subject: Re: Finding the start and end of memory areas In-Reply-To: <41CAAA76.8060400@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <7f45d93904122216217855ef5f@mail.gmail.com> <41CAAA76.8060400@redhat.com> X-SW-Source: 2004-12/txt/msg00298.txt.bz2 Thanks for pointing me towards the linker script. From 'ld --verbose' I found ld was using /usr/lib/ldscripts/elf_i386.xc. From this I found the following information... text ? to &_etext data &_etext to &_edata bss - &__bss_start to &_end heap - &_end to sbrk(0) (gap) stack - stack_ptr to ? >From a snippet of code in newlib (sys/arm/syscalls.c), I found that stack_ptr can be defined as such: register void *stack_ptr asm ("sp"); On a Linux system, the beginning of the text and the top of the stack are constants, 0x08048000 and 0xbffff7a0 respectively. I haven't yet found a way to find these values at run-time in a cross-platform manner. I found the above values give somewhat different results than 'size'. For exampled, on my sample program... _etext = 0x8057baf _edata = 0x805ce18 _end = 0x80b1cd8 _etext - 0x08048000 = 64431 // size of text _edata - _etext = 21097 // size of data _end - _edata = 347840 // size of bss _end - 0x08048000 = 433368 // total $ size a.out text data bss dec hex filename 74477 7704 347832 430013 68fbd a.out The results are similar, but not identical. Cheers, Shaun > The simplest way is to have the cooperation of the linker script used to > create your executable. If the script places symbols at the start and > end of each of these sections then you can easily access them at run-time. > > If you cannot modify the linker script then you are going to have to > locate the executable on disk (presumably via argv[0]) and then load and > process the ELF headers and section tables themselves. > > Cheers > Nick