What is the point of the Global Offset Table?

烂漫一生 提交于 2019-12-12 08:57:43

问题


The whole reason the GOT works is that the offset between the code and data sections is constant; ergo, the offset between the code and some given datum in the data section is constant.

This SO question addresses this, and confirms that for data defined in the library, the GOT is redundant.

The only possibility left is data used in the library, but defined elsewhere.

Thus, is the only point of the GOT in a shared lib, to be able to keep that lib's code section position-independent by localizing all relocations to symbols defined in other shared libraries, in the GOT?


回答1:


Thus, is the only point of the GOT in a shared lib, to be able to keep that lib's code section position-independent by localizing all relocations to symbols defined in other shared libraries, in the GOT?

You are correct that the GOT is the mechanism which allows code to be relocatable.

However, it applies to both traditional shared objects and programs. It applies to programs due to Position Independent Code (PIE) (a.k.a Address Space Layout Randomization).

Generally speaking, PIE is a subset of PIC. That is, you can compile all code (programs and shared libraries) with -fPIC. However, the converse is not true. You cannot compile all code (programs and shared libraries) with -fPIE. Shared libraries require -fPIC.



来源:https://stackoverflow.com/questions/27449376/what-is-the-point-of-the-global-offset-table

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