搬迁的概念是什么意思? [英] What does the concept of relocation mean?

查看:26
本文介绍了搬迁的概念是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是组装新手,因此想更多地了解搬迁的概念.

I'm new to assembly and hence want to understand more about the concept of relocation.

  1. 为什么我们需要重新定位程序、数据?
  2. 具体是怎么做的?

如果有人能用初学者级别的例子来解释,那就太好了.

It would be great if someone could explain with a beginner level example.

推荐答案

汇编器有一个源文件可以查看.它必须基于该源文件构建内存映像.所以它以 0 开头的代码,也以 0 开头的数据.结果进入目标文件.

The assembler has one source file to look at. It has to build a memory image based on that one source file. So it starts with 0 for the code, and also for 0 with the data. The results go into an object file.

现在,链接器出现了,它需要将许多目标文件组合成一个可执行文件(或内核映像,或其他).它不能让每个人都处于 0,它们会重叠.因此它必须重新定位地址以将每个目标文件的数据价值分配到一个唯一的范围.

Now, the linker comes along and needs to combine many object files into an executable (or kernel image, or whatever). It can't leave everyone at 0, they would overlap. So it must relocate the addresses to assign each object file's worth of data to a unique range.

然后,图像被加载到虚拟内存中,操作系统可能有充分的理由想要使用0"以外的地址作为基本虚拟地址.因此,在运行时,它想再次重新定位所有内容.

Then, then the image is loaded into virtual memory, the operating system may have good reasons to want to use an address other than '0' as the base virtual address. So, at runtime, it wants to relocate everything again.

最后,如果涉及共享库,汇编器和链接器都不知道它们在运行环境中的位置,因此必须重新定位对它们的引用.

Finally, if there are shared libraries involved, neither the assembler nor the linker knows where they will be in the running environment, and so the references to them must be relocated.

这篇关于搬迁的概念是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆