When I compile my library I have switched on -fPIC
because I want to be able to compile it as a shared and as a static library.
Using gcc 3.4.4 on cygwin I get this warning on all source files:
-fPIC ignored for target (all code is position independent)
And I really wonder what's the point of it. It tells me that I use a switch which has no effect because what the switch should achieve is already accomplished. Well, it means it's redundant, fine. But what's the point of it and how can I suppress it?
I'm not talking about why using PIC or not, just why it generates that IMO useless warning.
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).