What does the concept of relocation mean? [closed]

人盡茶涼 提交于 2019-11-27 17:41:11

问题


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

  1. Why exactly do we need to relocate programs, data?
  2. How exactly is it done?

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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/16385826/what-does-the-concept-of-relocation-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!