Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9a3c04

Browse files
committed
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 extensionssuch as Citus and pglogical where it's becoming a problem. A bit ofresearch suggests that the penalty for -fPIC is small, in thesingle-digit-percentage range --- and there's none at all on popularplatforms such as x86_64. So let's just default to -fPIC everywhereand 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 andunixware in the back branches, though. We'd have no way to test thatit doesn't break anything on those platforms.)Discussion:https://postgr.es/m/20170529155850.qojdfrwkkqnjb3ap@msg.df7cb.de
1 parent2712da8 commite9a3c04

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

‎doc/src/sgml/dfunc.sgml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
<listitem>
6464
<para>
6565
The compiler flag to create <acronym>PIC</acronym> is
66-
<option>-fpic</option>. To create shared libraries the compiler
66+
<option>-fPIC</option>. To create shared libraries the compiler
6767
flag is <option>-shared</option>.
6868
<programlisting>
69-
gcc -fpic -c foo.c
69+
gcc -fPIC -c foo.c
7070
gcc -shared -o foo.so foo.o
7171
</programlisting>
7272
This is applicable as of version 3.0 of
@@ -84,14 +84,14 @@ gcc -shared -o foo.so foo.o
8484
<para>
8585
The compiler flag of the system compiler to create
8686
<acronym>PIC</acronym> is <option>+z</option>. When using
87-
<application>GCC</application> it's <option>-fpic</option>. The
87+
<application>GCC</application> it's <option>-fPIC</option>. The
8888
linker flag for shared libraries is <option>-b</option>. So:
8989
<programlisting>
9090
cc +z -c foo.c
9191
</programlisting>
9292
or:
9393
<programlisting>
94-
gcc -fpic -c foo.c
94+
gcc -fPIC -c foo.c
9595
</programlisting>
9696
and then:
9797
<programlisting>
@@ -112,13 +112,11 @@ ld -b -o foo.sl foo.o
112112
<listitem>
113113
<para>
114114
The compiler flag to create <acronym>PIC</acronym> is
115-
<option>-fpic</option>. On some platforms in some situations
116-
<option>-fPIC</option> must be used if <option>-fpic</option>
117-
does not work. Refer to the GCC manual for more information.
115+
<option>-fPIC</option>.
118116
The compiler flag to create a shared library is
119117
<option>-shared</option>. A complete example looks like this:
120118
<programlisting>
121-
cc -fpic -c foo.c
119+
cc -fPIC -c foo.c
122120
cc -shared -o foo.so foo.o
123121
</programlisting>
124122
</para>
@@ -149,12 +147,12 @@ cc -bundle -flat_namespace -undefined suppress -o foo.so foo.o
149147
<listitem>
150148
<para>
151149
The compiler flag to create <acronym>PIC</acronym> is
152-
<option>-fpic</option>. For <acronym>ELF</acronym> systems, the
150+
<option>-fPIC</option>. For <acronym>ELF</acronym> systems, the
153151
compiler with the flag <option>-shared</option> is used to link
154152
shared libraries. On the older non-ELF systems, <literal>ld
155153
-Bshareable</literal> is used.
156154
<programlisting>
157-
gcc -fpic -c foo.c
155+
gcc -fPIC -c foo.c
158156
gcc -shared -o foo.so foo.o
159157
</programlisting>
160158
</para>
@@ -169,10 +167,10 @@ gcc -shared -o foo.so foo.o
169167
<listitem>
170168
<para>
171169
The compiler flag to create <acronym>PIC</acronym> is
172-
<option>-fpic</option>. <literal>ld -Bshareable</literal> is
170+
<option>-fPIC</option>. <literal>ld -Bshareable</literal> is
173171
used to link shared libraries.
174172
<programlisting>
175-
gcc -fpic -c foo.c
173+
gcc -fPIC -c foo.c
176174
ld -Bshareable -o foo.so foo.o
177175
</programlisting>
178176
</para>
@@ -188,7 +186,7 @@ ld -Bshareable -o foo.so foo.o
188186
<para>
189187
The compiler flag to create <acronym>PIC</acronym> is
190188
<option>-KPIC</option> with the Sun compiler and
191-
<option>-fpic</option> with <application>GCC</>. To
189+
<option>-fPIC</option> with <application>GCC</>. To
192190
link shared libraries, the compiler option is
193191
<option>-G</option> with either compiler or alternatively
194192
<option>-shared</option> with <application>GCC</>.
@@ -198,7 +196,7 @@ cc -G -o foo.so foo.o
198196
</programlisting>
199197
or
200198
<programlisting>
201-
gcc -fpic -c foo.c
199+
gcc -fPIC -c foo.c
202200
gcc -G -o foo.so foo.o
203201
</programlisting>
204202
</para>

‎src/makefiles/Makefile.linux

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
AROPT = crs
2+
23
export_dynamic = -Wl,-E
34
# Use --enable-new-dtags to generate DT_RUNPATH instead of DT_RPATH.
45
# This allows LD_LIBRARY_PATH to still work when needed.
56
rpath = -Wl,-rpath,'$(rpathdir)',--enable-new-dtags
7+
68
DLSUFFIX = .so
79

8-
ifeq "$(findstring sparc,$(host_cpu))" "sparc"
910
CFLAGS_SL = -fPIC
10-
else
11-
CFLAGS_SL = -fpic
12-
endif
11+
1312

1413
# Rule for building a shared library from a single .o file
1514
%.so: %.o

‎src/makefiles/Makefile.netbsd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ endif
99

1010
DLSUFFIX = .so
1111

12-
ifeq ($(findstring sparc,$(host_cpu)), sparc)
1312
CFLAGS_SL = -fPIC -DPIC
14-
else
15-
CFLAGS_SL = -fpic -DPIC
16-
endif
1713

1814

1915
# Rule for building a shared library from a single .o file

‎src/makefiles/Makefile.openbsd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ endif
77

88
DLSUFFIX = .so
99

10-
ifeq ($(findstring sparc,$(host_cpu)), sparc)
1110
CFLAGS_SL = -fPIC -DPIC
12-
else
13-
CFLAGS_SL = -fpic -DPIC
14-
endif
1511

1612

1713
# Rule for building a shared library from a single .o file

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp