简体   繁体   English

为什么ELF的虚拟地址在映射到虚拟空间之前可以确定?

[英]Why the virtual address of ELF can be determined before it is mapped to virtual space?

An object file is linked to generate an ELF file and its virtual address is determined. 链接目标文件以生成ELF文件并确定其虚拟地址。 For example, the virtual address of .text is 0x8048000. 例如,.text的虚拟地址是0x8048000。 When the ELF file is going to be mapped to virtual space, another ELF has already been mapped to this address. 当ELF文件将映射到虚拟空间时,另一个ELF已映射到此地址。 What the operating system should do? 操作系统应该做什么? Why the virtual address of ELF can be determined before it is mapped to virtual space. 为什么ELF的虚拟地址在映射到虚拟空间之前可以确定。

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. 它不必与程序实际位于物理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. 它们可以映射到该地址,每个地址都在自己的私有地址空间中。

  1. ELF tells the Linux kernel where it wants to be placed, and if the Linux kernel accepts that address, it loads it there. ELF告诉Linux内核它要放在哪里,如果Linux内核接受该地址,它会在那里加载它。

    Eg 0 does not work because too low: Why is the ELF execution entry point virtual address of the form 0x80xxxxx and not zero 0x0? 例如,0不起作用,因为太低: 为什么ELF执行入口点为0x80xxxxx形式的虚拟地址而不是零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? ld使用配置使用的链接描述文件确定地址: 在ELF文件中,如何确定_start的地址?

  2. As mentioned by Wyzard, each process has it's own virtual address space. 正如Wyzard所提到的,每个进程都有自己的虚拟地址空间。

    More precisely, virtual address spaces have hardware support through paging: How does x86 paging work? 更确切地说,虚拟地址空间通过分页提供硬件支持: x86分页如何工作? which the kernel sets up and uses. 内核设置和使用的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM