Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22063

Does one still need to use -fPIC when compiling with GCC?

$
0
0

On gcc target machines, when one wanted to compile a shared library, one would need to specify -fpic or -fPIC to get things to work correcly. This is because by default absolute addressing was used, which is suitable for executable that have full control of their own address space, but not shared libraries, which could be loaded anywhere in an executable's address space.

However modern kernels are now implementing address space randomization and many modern architectures support PC relative addressing. This all seems to make the absolute addressing either unusable (address space randomization) or unneeded (PC relative addressing).

I have also noticed that clang does not have an -fPIC option which makes me think that it is no longer necessary.

So is -fPIC now redundant or does one need to generate separate .o files, one for static library use, and one for shared library use?


Viewing all articles
Browse latest Browse all 22063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>