And I really wonder what's the point of it...
I'm not talking about why using PIC or not, just why it generates that IMO useless warning.
That's a good question, and I have not seen a definitive answer. At least one of the GCC devs considers it a pointless warning. Paolo Bonzini called it that in his recent patch Remove pointless -fPIC warning on Windows platforms.
According to Jonathan Wakely on the GCC mailing list at How to suppress "warning: -fPIC ignored for target..." under Cygwin (August 2015):
That warning has been there since well before 2003 (I couldn't be bothered tracing the history back past a file rename in 2003).
And from Alexander Monakov on the same thread (referencing Bonzini's patch):
A patch was proposed just recently to just remove the warning: https://gcc.gnu.org/ml/gcc-patches/2015-08/msg00836.html
Related, Windows has /ASLR
, which is address space layout randomization. Its optional, but often required as a security gate, meaning all program code on must be compiled with it. If you have an SDLC, then you are probably using /ASLR
because Microsoft calls it out as a best practice in Writing Secure Code.
The Linux/Unix equivalent of /ASLR
is -fPIE
for executables.
Under Windows, all DLL code is relocatable. Under Linux/Unix, shared object code can be made relocatable with -fPIC
.
-fPIC
is a "superset" of -fPIE
(some hand waiving). That means -fPIC
can be used anywhere you would use -fPIE
(but not vice-versa).