Global variables, shared libraries and -fPIC effect

六眼飞鱼酱① 提交于 2019-11-29 05:58:45

When you compile with -fPIC the object in question will determine the address of global symbols using the Global Offset Table. What happens though when part of the code is -fPIC and part isn't is that one of your int globals will be using this table to determine the address whilst the other part isn't.

If you had two shared object linked with -fPIC, but your main program not then you would still have two addresses for int global, one using the global offset table and one which was just local to the non-PIC code.

There's a really great discussion on PIC vs pic vs non PIC if you want to read further.

By default, when building an executable references to variables are done internally, with a fixed offset and no relocation.

However, you're passing -fPIC and access to global data are converted to access via GOT and GOT relocations are added.

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