Reputation: 3497
I have this subtle question about virtual memory. In one book I read this quote
When the ELF file is executed, the text and the two data segments are loaded into separate areas of virtual memory
But if we for example compile a C program consisting of two source file without linking it will produce two object files. And in both object files addressing starts from zero. Then if we link both object files into one executable and inspect it we will observe that addressing no longer starts from zero, rather some address is already assigned to each of the segments. And as I understand this assigned address is a virtual memory address. So I have two questions:
Upvotes: 3
Views: 221
Reputation:
The linker will assign a virtual address that can be used as a 'base' for the loaded segments. So yes the linker does assign the virtual address base. The OS simply maps this memory to a physical address. The assignment is the OS assigning the physical address to the virtual one.
Upvotes: 3