Global variables, shared libraries and -fPIC effect

前端 未结 2 1336
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 17:16

I made a piece of code which consists in a dynamic library (lib.c), and a main executable (main.c). In both files I define a global variable named:

2条回答
  •  独厮守ぢ
    2020-12-17 17:25

    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.

提交回复
热议问题