Re: How a program could generate the memory addresses for its variables, when it is about to run?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi...

On Fri, May 27, 2011 at 13:44, sandeep kumar <coolsandyforyou@xxxxxxxxx> wrote:
>
> I want to start with the following question,
> How a program could generate the memory addresses for its variables, when it
> is about to run?

first, linker will determine in which section and which offset (from
the start of the program) the variables will be positioned. If it is a
dynamic variable (one that ends up in stack), it will determined
dynamically later according to stack position.

later, loader will reposition those variables based on real memory
address positioning. This is based on the information placed inside
the binary (ELF header). Usually, it is followed strictly, but if it
is PIE (Position Independent Executable), further flexible reposition
is allowed based on certain policy.

those address (for static variables) are then substituted into GOT
(Global Offset Table), some kind of lookup table to determined address
of variables (and function address too actually).

for dynamic variable, usually simply using compiler generated code, it
is sufficient to reference them. This is because they are referenced
using relative offset against base address of frame (which is usually
saved in esp or ebp in x86 arch)

I hope I correctly describe it....

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux