为什么不是所有的代码编译位置都独立? [英] Why isn't all code compiled position independent?

查看:13
本文介绍了为什么不是所有的代码编译位置都独立?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 gcc 中编译共享库时,-fPIC 选项将代码编译为与位置无关的代码.是否有任何原因(性能或其他原因)为什么不编译所有代码位置无关?

When compiling shared libraries in gcc the -fPIC option compiles the code as position independent. Is there any reason (performance or otherwise) why you would not compile all code position independent?

推荐答案

它增加了一个间接性.使用位置无关代码,您必须加载函数的地址,然后跳转到它.通常函数的地址已经存在于指令流中.

It adds an indirection. With position independent code you have to load the address of your function and then jump to it. Normally the address of the function is already present in the instruction stream.

这篇关于为什么不是所有的代码编译位置都独立?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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