venus.w
venus.w

Reputation: 2251

Should the static or global data which is stored in .data or .bss section be loaded before the program executing?

Usually, the static and global variables are both stored in the .data or .bss section according to their initialization condition. It is said their life time is from the beginning to the ending of the program, and it is also known that program is loaded into the memory as a page when demanded in paging management. Does this mean .data and .bss section should both be loaded into the memory before their access, or before the first instruction goes?

Upvotes: 1

Views: 170

Answers (1)

Francis Upton IV
Francis Upton IV

Reputation: 19443

You are dealing with two levels of abstraction here. Everything accessed within the program is in the virtual address space, and the .data/.bss sections are available at the beginning of program execution. A deeper abstraction is that the virtual address space is backed by physical memory using paging, managed by the memory manager. This is totally unknown to the executing code and code that loads the process. So it's possible at this level that parts of .data/.bss (or even your code) are not present in main memory because the physical pages have not been loaded, in general these will be loaded on demand as their corresponding virtual addresses are referenced.

Google things like "memory management", "virtual memory", "paging" for more information.

Upvotes: 2

Related Questions