Reputation: 937
An object file is linked to generate an ELF file and its virtual address is determined. For example, the virtual address of .text is 0x8048000. When the ELF file is going to be mapped to virtual space, another ELF has already been mapped to this address. What the operating system should do? Why the virtual address of ELF can be determined before it is mapped to virtual space.
Upvotes: 5
Views: 894
Reputation: 382512
ELF tells the Linux kernel where it wants to be placed, and if the Linux kernel accepts that address, it loads it there.
E.g. 0 does not work because too low: Why is the ELF execution entry point virtual address of the form 0x80xxxxx and not zero 0x0?
ld
determines the address with the linker script it is configured to use: In an ELF file, how does the address for _start get detemined?
As mentioned by Wyzard, each process has it's own virtual address space.
More precisely, virtual address spaces have hardware support through paging: How does x86 paging work? which the kernel sets up and uses.
Upvotes: 0
Reputation: 34563
Each process gets its own private virtual address space — that's the point of it being virtual; it doesn't have to correspond to where the program is actually located in physical RAM. So there's no conflict of addresses between programs running in different processes. They can all be mapped to that address, each in its own private address space.
Upvotes: 3