This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Finding the start and end of memory areas


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]