GCC -fPIC option(GCC -fPIC 选项)
问题描述
我已阅读GCC 的代码选项生成约定,但无法理解生成位置无关代码(PIC)"的作用.请举例说明这是什么意思.
I have read about GCC's Options for Code Generation Conventions, but could not understand what "Generate position-independent code (PIC)" does. Please give an example to explain me what does it mean.
推荐答案
Position Independent Code 意味着生成的机器代码不依赖于位于特定地址才能工作.
Position Independent Code means that the generated machine code is not dependent on being located at a specific address in order to work.
例如跳转将作为相对而不是绝对生成.
E.g. jumps would be generated as relative rather than absolute.
伪组装:
PIC:无论代码在地址 100 还是 1000 处,这都有效
PIC: This would work whether the code was at address 100 or 1000
100: COMPARE REG1, REG2
101: JUMP_IF_EQUAL CURRENT+10
...
111: NOP
Non-PIC:仅当代码位于地址 100 时才有效
Non-PIC: This will only work if the code is at address 100
100: COMPARE REG1, REG2
101: JUMP_IF_EQUAL 111
...
111: NOP
回应评论.
如果您的代码是使用 -fPIC 编译的,则它适合包含在库中 - 该库必须能够从其在内存中的首选位置重定位到另一个地址,在您的库地址处可能有另一个已加载的库喜欢.
If your code is compiled with -fPIC, it's suitable for inclusion in a library - the library must be able to be relocated from its preferred location in memory to another address, there could be another already loaded library at the address your library prefers.
这篇关于GCC -fPIC 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC -fPIC 选项
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01