Finding the start and end of memory areas

Nick Clifton nickc@redhat.com
Thu Dec 23 11:15:00 GMT 2004


Hi Shaun,

> First off, this posting is somewhat off-topic. My apologies in
> advance. If anyone knows of a better forum for this topic, I'd
> appreciate being pointed in the right direction. 

Actually this is the right forum for this kind of question.

> I'd like to find the start and end of the following memory areas
> during run-time...
> 
> text
> data
> bss - &__bss_start to &__bss_end
> heap - &__bss_end to sbrk(0)
> (gap)
> stack - stack pointer to ?

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



More information about the Binutils mailing list