Rustam Issabekov
Rustam Issabekov

Reputation: 3497

about virtual memory

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:

  1. So am I correct that it is the linker that requests some virtual memory range from OS and assigns it to program segments?
  2. What does the author of the quote mean when he said that virtual address is assigned when the process is executed?

Upvotes: 3

Views: 221

Answers (1)

user400055
user400055

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

Related Questions