Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7143b3e

Browse files
committed
Build src/common files as a library with -fPIC.
Build a third version of libpgcommon.a, with -fPIC and -DFRONTEND, as commit ea53100 did for src/port. Use that in libpq to avoid symlinking+rebuilding source files retail. Also adjust ecpg to use the new src/port and src/common libraries. Arrange to install these libraries, too, to simplify out-of-tree builds of shared libraries that need any of these modules. Discussion: https://postgr.es/m/13022.1538003440@sss.pgh.pa.us Discussion: https://postgr.es/m/E1g5Y8r-0006vs-QA@gemulon.postgresql.org
1 parent f7ab802 commit 7143b3e

File tree

11 files changed

+68
-111
lines changed

11 files changed

+68
-111
lines changed

src/Makefile.global.in

+10-5
Original file line numberDiff line numberDiff line change
@@ -534,21 +534,26 @@ libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
534534
libpq_builddir = $(top_builddir)/src/interfaces/libpq
535535
endif
536536

537-
# This macro is for use by libraries linking to libpq. (Because libpgport
538-
# isn't created with the same link flags as libpq, it can't be used.)
537+
# How to link to libpq. (This macro may be used as-is by backend extensions.
538+
# Client-side code should go through libpq_pgport or libpq_pgport_shlib,
539+
# instead.)
539540
libpq = -L$(libpq_builddir) -lpq
540541

541-
# This macro is for use by client executables (not libraries) that use libpq.
542+
# libpq_pgport is for use by client executables (not libraries) that use libpq.
542543
# We force clients to pull symbols from the non-shared libraries libpgport
543544
# and libpgcommon rather than pulling some libpgport symbols from libpq just
544545
# because libpq uses those functions too. This makes applications less
545-
# dependent on changes in libpq's usage of pgport. To do this we link to
546+
# dependent on changes in libpq's usage of pgport (on platforms where we
547+
# don't have symbol export control for libpq). To do this we link to
546548
# pgport before libpq. This does cause duplicate -lpgport's to appear
547-
# on client link lines.
549+
# on client link lines, since that also appears in $(LIBS).
550+
# libpq_pgport_shlib is the same idea, but for use in client shared libraries.
548551
ifdef PGXS
549552
libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
553+
libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
550554
else
551555
libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
556+
libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)
552557
endif
553558

554559
# Cygwin seems to need ldap libraries to be mentioned here, too

src/common/Makefile

+38-10
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
# Makefile
44
# Makefile for src/common
55
#
6-
# This makefile generates two outputs:
6+
# These files are used by the Postgres backend, and also by frontend
7+
# programs. These files provide common functionality that isn't directly
8+
# concerned with portability and thus doesn't belong in src/port.
9+
#
10+
# This makefile generates three outputs:
711
#
812
# libpgcommon.a - contains object files with FRONTEND defined,
913
# for use by client applications
1014
#
11-
# libpgcommon_srv.a - contains object files without FRONTEND defined,
12-
# for use only by the backend binaries
15+
# libpgcommon_shlib.a - contains object files with FRONTEND defined,
16+
# built suitably for use in shared libraries; for use
17+
# by frontend libraries
1318
#
14-
# You can also symlink/copy individual source files from this directory,
15-
# to compile with different options. (libpq does that, because it needs
16-
# to use -fPIC on some platforms.)
19+
# libpgcommon_srv.a - contains object files without FRONTEND defined,
20+
# for use only by the backend
1721
#
1822
# IDENTIFICATION
1923
# src/common/Makefile
@@ -52,26 +56,48 @@ else
5256
OBJS_COMMON += sha2.o
5357
endif
5458

59+
# A few files are currently only built for frontend, not server
5560
OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o file_utils.o restricted_token.o
5661

62+
# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
63+
OBJS_SHLIB = $(OBJS_FRONTEND:%.o=%_shlib.o)
5764
OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
5865

59-
all: libpgcommon.a libpgcommon_srv.a
66+
all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
6067

6168
# libpgcommon is needed by some contrib
6269
install: all installdirs
6370
$(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
71+
$(INSTALL_STLIB) libpgcommon_shlib.a '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
6472

6573
installdirs:
6674
$(MKDIR_P) '$(DESTDIR)$(libdir)'
6775

6876
uninstall:
6977
rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
78+
rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
7079

7180
libpgcommon.a: $(OBJS_FRONTEND)
7281
rm -f $@
7382
$(AR) $(AROPT) $@ $^
7483

84+
#
85+
# Shared library versions of object files
86+
#
87+
88+
libpgcommon_shlib.a: $(OBJS_SHLIB)
89+
rm -f $@
90+
$(AR) $(AROPT) $@ $^
91+
92+
# Because this uses its own compilation rule, it doesn't use the
93+
# dependency tracking logic from Makefile.global. To make sure that
94+
# dependency tracking works anyway for the *_shlib.o files, depend on
95+
# their *.o siblings as well, which do have proper dependencies. It's
96+
# a hack that might fail someday if there is a *_shlib.o without a
97+
# corresponding *.o, but there seems little reason for that.
98+
%_shlib.o: %.c %.o
99+
$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
100+
75101
#
76102
# Server versions of object files
77103
#
@@ -87,16 +113,18 @@ libpgcommon_srv.a: $(OBJS_SRV)
87113
# a hack that might fail someday if there is a *_srv.o without a
88114
# corresponding *.o, but it works for now.
89115
%_srv.o: %.c %.o
90-
$(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@
116+
$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
91117

92118
# Dependencies of keywords.o need to be managed explicitly to make sure
93119
# that you don't get broken parsing code, even in a non-enable-depend build.
94-
# Note that gram.h isn't required for the frontend version of keywords.o.
120+
# Note that gram.h isn't required for the frontend versions of keywords.o.
95121
$(top_builddir)/src/include/parser/gram.h: $(top_srcdir)/src/backend/parser/gram.y
96122
$(MAKE) -C $(top_builddir)/src/backend $(top_builddir)/src/include/parser/gram.h
97123

98124
keywords.o: $(top_srcdir)/src/include/parser/kwlist.h
125+
keywords_shlib.o: $(top_srcdir)/src/include/parser/kwlist.h
99126
keywords_srv.o: $(top_builddir)/src/include/parser/gram.h $(top_srcdir)/src/include/parser/kwlist.h
100127

101128
clean distclean maintainer-clean:
102-
rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND) $(OBJS_SRV)
129+
rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
130+
rm -f $(OBJS_FRONTEND) $(OBJS_SHLIB) $(OBJS_SRV)
-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
/compatlib.def
22
/blibecpg_compatdll.def
33
/exports.list
4-
/snprintf.c
5-
/strerror.c
6-
/strlcpy.c
7-
/strnlen.c

src/interfaces/ecpg/compatlib/Makefile

+3-10
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2222
-I$(libpq_srcdir) -DFRONTEND $(CPPFLAGS)
2323
override CFLAGS += $(PTHREAD_CFLAGS)
2424

25-
SHLIB_LINK_INTERNAL = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq)
25+
SHLIB_LINK_INTERNAL = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq_pgport_shlib)
2626
SHLIB_LINK = $(filter -lintl -lm, $(LIBS)) $(PTHREAD_LIBS)
2727
SHLIB_PREREQS = submake-ecpglib submake-pgtypeslib
2828

2929
SHLIB_EXPORTS = exports.txt
3030

31-
# Need to recompile any libpgport object files
32-
LIBS := $(filter-out -lpgport, $(LIBS))
33-
34-
OBJS= informix.o snprintf.o strerror.o \
35-
$(filter strlcpy.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
31+
OBJS= informix.o $(WIN32RES)
3632

3733
PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
3834

@@ -49,16 +45,13 @@ submake-pgtypeslib:
4945
# Shared library stuff
5046
include $(top_srcdir)/src/Makefile.shlib
5147

52-
snprintf.c strerror.c strlcpy.c strnlen.c: % : $(top_srcdir)/src/port/%
53-
rm -f $@ && $(LN_S) $< .
54-
5548
install: all installdirs install-lib
5649

5750
installdirs: installdirs-lib
5851

5952
uninstall: uninstall-lib
6053

6154
clean distclean: clean-lib
62-
rm -f $(OBJS) snprintf.c strerror.c strlcpy.c strnlen.c
55+
rm -f $(OBJS)
6356

6457
maintainer-clean: distclean maintainer-clean-lib
-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
/ecpglib.def
22
/blibecpgdll.def
33
/exports.list
4-
/path.c
5-
/pgstrcasecmp.c
6-
/snprintf.c
7-
/strerror.c
8-
/strlcpy.c
9-
/strnlen.c
10-
/thread.c
11-
/win32setlocale.c
12-
/isinf.c

src/interfaces/ecpg/ecpglib/Makefile

+4-23
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,10 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2222
-I$(libpq_srcdir) -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
2323
override CFLAGS += $(PTHREAD_CFLAGS)
2424

25-
# Need to recompile any libpgport object files
26-
LIBS := $(filter-out -lpgport, $(LIBS))
25+
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o \
26+
memory.o connect.o misc.o $(WIN32RES)
2727

28-
OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
29-
connect.o misc.o path.o pgstrcasecmp.o snprintf.o strerror.o \
30-
$(filter strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
31-
$(WIN32RES)
32-
33-
# thread.c is needed only for non-WIN32 implementation of path.c
34-
ifneq ($(PORTNAME), win32)
35-
OBJS += thread.o
36-
endif
37-
38-
SHLIB_LINK_INTERNAL = -L../pgtypeslib -lpgtypes $(libpq)
28+
SHLIB_LINK_INTERNAL = -L../pgtypeslib -lpgtypes $(libpq_pgport_shlib)
3929
SHLIB_LINK = $(filter -lintl -lm, $(LIBS)) $(PTHREAD_LIBS)
4030
SHLIB_PREREQS = submake-libpq submake-pgtypeslib
4131

@@ -52,16 +42,8 @@ submake-pgtypeslib:
5242
# Shared library stuff
5343
include $(top_srcdir)/src/Makefile.shlib
5444

55-
# We use some port modules verbatim, but since we need to
56-
# compile with appropriate options to build a shared lib, we can't
57-
# necessarily use the same object files as the backend uses. Instead,
58-
# symlink the source files in here and build our own object file.
59-
60-
path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
61-
rm -f $@ && $(LN_S) $< .
62-
45+
# Make dependency on pg_config_paths.h visible.
6346
misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
64-
path.o: path.c $(top_builddir)/src/port/pg_config_paths.h
6547

6648
$(top_builddir)/src/port/pg_config_paths.h:
6749
$(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
@@ -74,6 +56,5 @@ uninstall: uninstall-lib
7456

7557
clean distclean: clean-lib
7658
rm -f $(OBJS)
77-
rm -f path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c
7859

7960
maintainer-clean: distclean maintainer-clean-lib
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
/pgtypeslib.def
22
/blibpgtypesdll.def
33
/exports.list
4-
/pgstrcasecmp.c
5-
/rint.c
6-
/snprintf.c
7-
/strerror.c
8-
/strlcpy.c
9-
/string.c
10-
/strnlen.c

src/interfaces/ecpg/pgtypeslib/Makefile

+2-18
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,26 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2222
-DFRONTEND $(CPPFLAGS)
2323
override CFLAGS += $(PTHREAD_CFLAGS)
2424

25-
# Need to recompile any libpgport object files
26-
LIBS := $(filter-out -lpgport, $(LIBS))
27-
25+
SHLIB_LINK_INTERNAL = -lpgcommon_shlib -lpgport_shlib
2826
SHLIB_LINK += $(filter -lintl -lm, $(LIBS))
2927

3028
SHLIB_EXPORTS = exports.txt
3129

3230
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
33-
pgstrcasecmp.o snprintf.o strerror.o \
34-
$(filter rint.o strlcpy.o strnlen.o, $(LIBOBJS)) \
35-
string.o \
3631
$(WIN32RES)
3732

3833
all: all-lib
3934

4035
# Shared library stuff
4136
include $(top_srcdir)/src/Makefile.shlib
4237

43-
# We use some port modules verbatim, but since we need to
44-
# compile with appropriate options to build a shared lib, we can't
45-
# necessarily use the same object files as the backend uses. Instead,
46-
# symlink the source files in here and build our own object file.
47-
48-
pgstrcasecmp.c rint.c snprintf.c strerror.c strlcpy.c strnlen.c: % : $(top_srcdir)/src/port/%
49-
rm -f $@ && $(LN_S) $< .
50-
51-
string.c: % : $(top_srcdir)/src/common/%
52-
rm -f $@ && $(LN_S) $< .
53-
5438
install: all installdirs install-lib
5539

5640
installdirs: installdirs-lib
5741

5842
uninstall: uninstall-lib
5943

6044
clean distclean: clean-lib
61-
rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strerror.c strlcpy.c strnlen.c string.c
45+
rm -f $(OBJS)
6246

6347
maintainer-clean: distclean maintainer-clean-lib

src/interfaces/libpq/.gitignore

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
/exports.list
22
/libpq.rc
33
# .c files that are symlinked in from elsewhere
4-
/ip.c
5-
/md5.c
6-
/base64.c
7-
/link-canary.c
8-
/scram-common.c
9-
/sha2.c
10-
/sha2_openssl.c
11-
/saslprep.c
12-
/unicode_norm.c
134
/encnames.c
145
/wchar.c

src/interfaces/libpq/Makefile

+8-14
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ OBJS= fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-l
3232

3333
# src/backend/utils/mb
3434
OBJS += encnames.o wchar.o
35-
# src/common
36-
OBJS += base64.o ip.o link-canary.o md5.o scram-common.o saslprep.o unicode_norm.o
3735

3836
ifeq ($(with_openssl),yes)
39-
OBJS += fe-secure-openssl.o fe-secure-common.o sha2_openssl.o
40-
else
41-
OBJS += sha2.o
37+
OBJS += fe-secure-openssl.o fe-secure-common.o
4238
endif
4339

4440
ifeq ($(PORTNAME), cygwin)
@@ -59,12 +55,14 @@ endif
5955

6056
# Add libraries that libpq depends (or might depend) on into the
6157
# shared library link. (The order in which you list them here doesn't
62-
# matter.) Note that we filter out -lpgport from LIBS and instead
63-
# insert -lpgport_shlib, to get port files that are built correctly.
58+
# matter.) Note that we filter out -lpgcommon and -lpgport from LIBS and
59+
# instead link with -lpgcommon_shlib and -lpgport_shlib, to get object files
60+
# that are built correctly for use in a shlib.
61+
SHLIB_LINK_INTERNAL = -lpgcommon_shlib -lpgport_shlib
6462
ifneq ($(PORTNAME), win32)
65-
SHLIB_LINK += -lpgport_shlib $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv -lintl -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
63+
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv -lintl -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
6664
else
67-
SHLIB_LINK += -lpgport_shlib $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl -lm $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
65+
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl -lm $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
6866
endif
6967
ifeq ($(PORTNAME), win32)
7068
SHLIB_LINK += -lshell32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
@@ -87,9 +85,6 @@ backend_src = $(top_srcdir)/src/backend
8785
# Instead, symlink the source files in here and build our own object files.
8886
# When you add a file here, remember to add it in the "clean" target below.
8987

90-
ip.c md5.c base64.c link-canary.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c: % : $(top_srcdir)/src/common/%
91-
rm -f $@ && $(LN_S) $< .
92-
9388
encnames.c wchar.c: % : $(backend_src)/utils/mb/%
9489
rm -f $@ && $(LN_S) $< .
9590

@@ -136,8 +131,7 @@ clean distclean: clean-lib
136131
rm -f $(OBJS) pthread.h libpq.rc
137132
# Might be left over from a Win32 client-only build
138133
rm -f pg_config_paths.h
139-
# Remove files we (may have) symlinked in from src/common and other places
140-
rm -f ip.c md5.c base64.c link-canary.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c
134+
# Remove files we (may have) symlinked in from other places
141135
rm -f encnames.c wchar.c
142136

143137
maintainer-clean: distclean maintainer-clean-lib

src/port/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# libpgport_shlib.a - contains object files with FRONTEND defined,
1616
# built suitably for use in shared libraries; for use
17-
# by libpq and other frontend libraries
17+
# by frontend libraries
1818
#
1919
# libpgport_srv.a - contains object files without FRONTEND defined,
2020
# for use only by the backend
@@ -53,15 +53,16 @@ OBJS_SRV = $(OBJS:%.o=%_srv.o)
5353
all: libpgport.a libpgport_shlib.a libpgport_srv.a
5454

5555
# libpgport is needed by some contrib
56-
# currently we don't install libpgport_shlib.a, maybe we should?
5756
install: all installdirs
5857
$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
58+
$(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
5959

6060
installdirs:
6161
$(MKDIR_P) '$(DESTDIR)$(libdir)'
6262

6363
uninstall:
6464
rm -f '$(DESTDIR)$(libdir)/libpgport.a'
65+
rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
6566

6667
libpgport.a: $(OBJS)
6768
rm -f $@

0 commit comments

Comments
 (0)