tags:

views:

38

answers:

1

The static variables in an exe go into data segment of the process and initized at the start up of the process.

So, if my process dynamically load a library, which has static variables using dlopen or something, to which segment these static variables will be mapped to. Also when these static variables will be initialized?

My understanding is that data segment in a process is fixed and cannot grow unlike stack or heap. Am i correct?

+2  A: 

The dll has its own segments which are mapped into address space using a more complex model than text+data+bss. No attempt is made to split up the dynamically linked library and join it with your original text, data, or bss segments.

The static variables are never initialized with code. If it's a writable segment, it will be demand-paged off the disk into your address space, where it will become a private mapping. If it's not writable, you may just link up to an already loaded shared page, but ultimately static variables are initialized in an image somewhere, and paged into RAM.

Any given data segment in a linked program typically can't grow like a stack or heap, no.

DigitalRoss