From 68938ab8ea0edf877e6e2821cec9e70ef2befa92 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 1 Jun 2017 13:32:56 -0400 Subject: Always use -fPIC, not -fpic, when building shared libraries with gcc. On some platforms, -fpic fails for sufficiently large shared libraries. We've mostly not hit that boundary yet, but there are some extensions such as Citus and pglogical where it's becoming a problem. A bit of research suggests that the penalty for -fPIC is small, in the single-digit-percentage range --- and there's none at all on popular platforms such as x86_64. So let's just default to -fPIC everywhere and provide one less thing for extension developers to worry about. Per complaint from Christoph Berg. Back-patch to all supported branches. (I did not bother to touch the recently-removed Makefiles for sco and unixware in the back branches, though. We'd have no way to test that it doesn't break anything on those platforms.) Discussion: https://postgr.es/m/20170529155850.qojdfrwkkqnjb3ap@msg.df7cb.de --- doc/src/sgml/dfunc.sgml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/dfunc.sgml b/doc/src/sgml/dfunc.sgml index 5a368f6df04..ebc85bf54b4 100644 --- a/doc/src/sgml/dfunc.sgml +++ b/doc/src/sgml/dfunc.sgml @@ -63,10 +63,10 @@ The compiler flag to create PIC is - . To create shared libraries the compiler + . To create shared libraries the compiler flag is . -gcc -fpic -c foo.c +gcc -fPIC -c foo.c gcc -shared -o foo.so foo.o This is applicable as of version 3.0 of @@ -84,14 +84,14 @@ gcc -shared -o foo.so foo.o The compiler flag of the system compiler to create PIC is . When using - GCC it's . The + GCC it's . The linker flag for shared libraries is . So: cc +z -c foo.c or: -gcc -fpic -c foo.c +gcc -fPIC -c foo.c and then: @@ -112,13 +112,11 @@ ld -b -o foo.sl foo.o The compiler flag to create PIC is - . On some platforms in some situations - must be used if - does not work. Refer to the GCC manual for more information. + . The compiler flag to create a shared library is . A complete example looks like this: -cc -fpic -c foo.c +cc -fPIC -c foo.c cc -shared -o foo.so foo.o @@ -149,12 +147,12 @@ cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o The compiler flag to create PIC is - . For ELF systems, the + . For ELF systems, the compiler with the flag is used to link shared libraries. On the older non-ELF systems, ld -Bshareable is used. -gcc -fpic -c foo.c +gcc -fPIC -c foo.c gcc -shared -o foo.so foo.o @@ -169,10 +167,10 @@ gcc -shared -o foo.so foo.o The compiler flag to create PIC is - . ld -Bshareable is + . ld -Bshareable is used to link shared libraries. -gcc -fpic -c foo.c +gcc -fPIC -c foo.c ld -Bshareable -o foo.so foo.o @@ -188,7 +186,7 @@ ld -Bshareable -o foo.so foo.o The compiler flag to create PIC is with the Sun compiler and - with GCC. To + with GCC. To link shared libraries, the compiler option is with either compiler or alternatively with GCC. @@ -198,7 +196,7 @@ cc -G -o foo.so foo.o or -gcc -fpic -c foo.c +gcc -fPIC -c foo.c gcc -G -o foo.so foo.o -- cgit v1.2.3