afr0ck
afr0ck

Reputation: 63

Layout of ELF binary in virtual memory

All modern *nix operating systems use virtual memory concept (with paging). And as far as i know, this concept of virtual memory is used to set a layer of abstraction between the programmer and the real physical memory: the programmer doesn't have to be limited to ram size and he can see the program as a large contiguous space of data, instructions, heap and stack (manipulate pointers according to that concept). When we compile & link a source code we get an executable file stored on HDD known as ELF, that file contains all data and instructions of the program beside some additional information like stack and heap sizes (only created at runtime).

Now my questions:

   1. How does this binary file (elf) is mapped to virtual memory ?
   2. Does every process has its own virtual memory (a page file !!!) ?
   3. What is the program's layout after being mapped to virtual memory ?
   4. What is exactly the preferred base address and how does it look in virtual memory ?
   5. What is the difference between a RVA and an Offset ?

You don't have to answers all the questions or give detailed answers instead you can provide me with good full readings about the subject, thanks.

Upvotes: 1

Views: 1398

Answers (1)

user3344003
user3344003

Reputation: 21607

  1. How does this binary file (elf) is mapped to virtual memory ??

The executable file contains instructions to the loader on how to lay out the address space. On some systems, parts of the executable can be mapped to memory and serve as a page file.

  1. Does every process has its own virtual memory (a page file !!!) ?

Every process has its own logical address space. Some areas within that address space may be shared with other processes.

  1. What is the program's layout after being mapped to virtual memory ?

The depends upon the system and what the executable told the loader to do.

  1. What is exactly the preferred base address and how does it look in virtual memory ?

That is just the desirable start location for loading something in memory. Most compilers generate relocatable code that is not tied to any specific logical address.

  1. What is the difference between a RVA and an Offset ?

RVA is a screwed up unixism for an offset. What is not clear, in your question is what type of offset you are talking about. There are byte offsets from pages. RVA is usually an offset from a loading location that can span pages.

Upvotes: 1

Related Questions