Why isn't all code compiled position independent?

前端 未结 9 2521
感情败类
感情败类 2020-12-04 10:46

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

9条回答
  •  不知归路
    2020-12-04 11:10

    Yes there are performance reasons. Some accesses are effectively under another layer of indirection to get the absolute position in memory.

    There is also the GOT (Global offset table) which stores offsets of global variables. To me, this just looks like an IAT fixup table, which is classified as position dependent by wikipedia and a few other sources.

    http://en.wikipedia.org/wiki/Position_independent_code

提交回复
热议问题