Reputation: 2055
I know when it's a matter of accessing memory of a stack frame it'll be through using stack frame pointer but I wonder about 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?
Upvotes: 1
Views: 1260
Reputation: 19
You could declare a global variable with __attribute__ ((section ("BSS")))
and get the address of the variable.
Take a look at the Gcc documentation
You can also declare a non-initialized static variable and get its address.
Upvotes: 1
Reputation: 272687
Virtual memory means that these segments always appear in the same location in virtual-address space, so their addresses can be hardcoded into the executable code.
(Note, this is not true for ASLR).
Upvotes: 1