全局偏移表的意义是什么? [英] What is the point of the Global Offset Table?

查看:127
本文介绍了全局偏移表的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GOT工作的全部原因是代码段和数据段之间的偏移量是恒定的.因此,代码与数据部分中某些给定基准之间的偏移量是恒定的.

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.

此SO问题解决了该问题,并确认了该数据在库中定义的GOT是多余的.

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.

因此,这是共享库中GOT的唯一要点,它可以通过将所有重定位到其他共享库中定义的符号上来保持该库的代码节位置独立.知道了吗?

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?

推荐答案

因此,这是共享库中GOT的唯一要点,它可以通过将所有重定位本地化到GOT中其他共享库中定义的符号来保持该库的代码节位置无关?

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?

您是正确的,因为GOT是允许代码可重定位的机制.

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

但是,它同时适用于传统共享对象和程序.它适用于由于位置无关代码(PIE)(又称地址空间布局随机化)而产生的程序.

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).

通常来说,PIE是PIC的子集.也就是说,您可以使用-fPIC编译所有代码(程序和共享库).但是,相反是 不是 .您不能使用-fPIE编译所有代码(程序和共享库).共享库需要-fPIC.

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.

这篇关于全局偏移表的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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