delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/08/05/14:04:34

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>,
<http://sourceware.cygnus.com/ml/#faqs>
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Date: Fri, 6 Aug 1999 04:00:14 +1000
From: Fergus Henderson <fjh AT cs DOT mu DOT OZ DOT AU>
To: "Read, Gordon" <GRead AT Broner DOT co DOT uk>
Cc: "'cygwin AT sourceware DOT cygnus DOT com'" <cygwin AT sourceware DOT cygnus DOT com>
Subject: Re: text/data segments in cygnus executables
Message-ID: <19990806040011.A6030@murlibobo.cs.mu.OZ.AU>
References: <BAB9541AAA7FD211844A00E0290C074C056BE5 AT BGPC66>
Mime-Version: 1.0
X-Mailer: Mutt 0.95.1i
In-Reply-To: <BAB9541AAA7FD211844A00E0290C074C056BE5@BGPC66>; from Read, Gordon on Thu, Aug 05, 1999 at 10:44:37AM +0100

On 05-Aug-1999, Read, Gordon <GRead AT Broner DOT co DOT uk> wrote:
> I need to find out the addresses of the the various segments in the
> currently running process (i.e. the start address of the text segment, data
> segment and so on), these are the values reported by "size -A program.exe".
> 
> How do I do this from within a C program compiled using gcc under cygnus?

The start and end of the data and bss segments are contained in the
symbols __data_start__, __data_end__, __bss_start__, and __bss_end__.
I think there are other symbols like these; check the linker script for
details.  (I think there's an option to `ld' to get it to dump the linker
script, but if not, you could try using strace to see what files `ld' reads,
or looking at the `ld' source code.)

You can access these symbols from C program using declarations
like the following:

	extern char _data_start__[];
	extern char _data_end__[];
	extern char _bss_start__[];
	extern char _bss_end__[];

	int main() {
		printf("data start = %p\n", (void *) _data_start__);
	}

For an example of their use, check the definitions of DATASTART and DATAEND
for CYGWIN in the file config.h from gc.tar.gz available at
http://reality.sgi.com/boehm/gc.html.


-
Fergus Henderson <fjh AT cs DOT mu DOT oz DOT au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh AT 128 DOT 250 DOT 37 DOT 3        |     -- the last words of T. S. Garp.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019