Is there any harm in always compiling with -fPIC
even if I might not intend to link the resulting relocatable object files into a shared library?
Asked
Active
Viewed 297 times
2

Petr Skocik
- 58,047
- 6
- 95
- 142
-
2Relocation costs extra indirection and increases code size, and you may wish to take that into account. But best to measure and compare! – Kerrek SB Oct 14 '15 at 20:42
-
1Related: [Why does arm-linux-androideabi-gcc enforce -fpic?](http://stackoverflow.com/questions/14990461/why-does-arm-linux-androideabi-gcc-enforce-fpic) – Ivan Aksamentov - Drop Oct 14 '15 at 21:33
1 Answers
2
Well, always compiling with -fPIC will produce a bit more bloated and a bit slower code.
Difference would be less visible on x64 target, I believe
You shall measure and decide if those differences are relevant for you app, you might be ok with it

Severin Pappadeux
- 18,636
- 3
- 38
- 64
-
It worth mention that there are not only x86 and x86_64 out there (their current share maybe even less than everything else) – Ivan Aksamentov - Drop Oct 14 '15 at 21:36