On Tue, 2010-10-19, Yakov Gerlovin wrote:
>> how the access to data, BSS segments containing global/static data
>> will be, through
>> using a pointer like stack frame pointer indicating starting point of
>> those segments or instructions address pieces of those segments
>> directly so that each time application starts the system will have to
>> write address parts of instructions in text segment ?
>
> The addresses of global/static variables are resolved during linkage.
During /linkage/ or during /loading/. E.g. on the Amiga, you had no
idea which addresses your BSS would end up in until you actually
loaded (tried to run) the program. Then you had at least two ways of
loading:
- keep a base address and do indirect addressing with offset to
access the various variables, or
- "write address parts of instructions" according to above.
The latter was generally considered less efficient, and prevented you
from sharing the same text segment between two running copies of the
same program.
> The calculated addresses are relative to the begging of BSS segment
> and each time the application starts may reside at different physical
> memory locations.
Not on modern Unixes though, and I'm guessing not on Windows either.
You have virtual memory, so an executable can (and will) contain the
exact addresses which are later used during runtime.
In this scenario the code /can/ contain hardcoded addresses ... but if
that's the most efficient on a certain architecture is a different
question.
The simplest way to check is to compile an example and look at the
generated code.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
|