Skip to content

Commit 1e7bb2d

Browse files
committed
Arrange to strip libpq.so of symbols that aren't officially supposed to
be exported on Linux and Darwin. We already did this on Windows but that's not enough, as evidenced by the fact that libecpg had an unexpected dependency on one such symbol. We should try to do it on more platforms. Fix ecpg's oversight, and bump libpq's major .so version number to reflect the unwanted but nonetheless real ABI break.
1 parent 35a0601 commit 1e7bb2d

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/Makefile.shlib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Copyright (c) 1998, Regents of the University of California
77
#
88
# IDENTIFICATION
9-
# $PostgreSQL: pgsql/src/Makefile.shlib,v 1.103 2006/04/19 16:32:08 tgl Exp $
9+
# $PostgreSQL: pgsql/src/Makefile.shlib,v 1.104 2006/04/28 02:53:20 tgl Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

@@ -107,11 +107,11 @@ ifeq ($(PORTNAME), darwin)
107107
ifeq ($(DLTYPE), library)
108108
# linkable library
109109
DLSUFFIX := .dylib
110-
LINK.shared = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) -multiply_defined suppress
110+
LINK.shared = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
111111
else
112112
# loadable module (default case)
113113
DLSUFFIX := .so
114-
LINK.shared = $(COMPILER) -bundle
114+
LINK.shared = $(COMPILER) -bundle -multiply_defined suppress
115115
endif
116116
shlib = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
117117
shlib_major = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
@@ -186,7 +186,7 @@ ifeq ($(PORTNAME), irix)
186186
endif
187187

188188
ifeq ($(PORTNAME), linux)
189-
LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
189+
LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname) $(exported_symbols_list)
190190
endif
191191

192192
ifeq ($(PORTNAME), solaris)

src/interfaces/ecpg/ecpglib/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.38 2006/01/17 19:49:23 meskes Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.39 2006/04/28 02:53:20 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -25,7 +25,7 @@ override CFLAGS += $(PTHREAD_CFLAGS)
2525
LIBS := $(filter-out -lpgport, $(LIBS))
2626

2727
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
28-
connect.o misc.o path.o exec.o \
28+
connect.o misc.o path.o exec.o thread.o \
2929
$(filter snprintf.o, $(LIBOBJS))
3030

3131
SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq) \
@@ -46,7 +46,7 @@ include $(top_srcdir)/src/Makefile.shlib
4646
# necessarily use the same object files as the backend uses. Instead,
4747
# symlink the source files in here and build our own object file.
4848

49-
path.c exec.c snprintf.c: % : $(top_srcdir)/src/port/%
49+
path.c exec.c snprintf.c thread.c: % : $(top_srcdir)/src/port/%
5050
rm -f $@ && $(LN_S) $< .
5151

5252
path.o: path.c $(top_builddir)/src/port/pg_config_paths.h
@@ -62,7 +62,7 @@ installdirs:
6262
uninstall: uninstall-lib
6363

6464
clean distclean maintainer-clean: clean-lib
65-
rm -f $(OBJS) path.c exec.c snprintf.c
65+
rm -f $(OBJS) path.c exec.c snprintf.c thread.c
6666

6767
depend dep:
6868
$(CC) -MM $(CFLAGS) *.c >depend

src/interfaces/libpq/Makefile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.143 2006/04/11 20:26:40 neilc Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.144 2006/04/28 02:53:20 tgl Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -16,8 +16,8 @@ include $(top_builddir)/src/Makefile.global
1616

1717
# shared library parameters
1818
NAME= pq
19-
SO_MAJOR_VERSION= 4
20-
SO_MINOR_VERSION= 2
19+
SO_MAJOR_VERSION= 5
20+
SO_MINOR_VERSION= 0
2121
DLTYPE= library
2222

2323
override CPPFLAGS := -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
@@ -125,6 +125,31 @@ $(srcdir)/blibpqdll.def: exports.txt
125125
echo '; Aliases for MS compatible names' >> $@
126126
sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1= _\1/' < $< | sed 's/ *$$//' >> $@
127127

128+
# Where possible, restrict the symbols exported by the library to just the
129+
# official list, so as to avoid unintentional ABI changes. On recent Darwin
130+
# this also quiets multiply-defined-symbol warnings in programs that use
131+
# libpgport along with libpq.
132+
133+
ifeq ($(PORTNAME), darwin)
134+
$(shlib): exports.list
135+
136+
exports.list: exports.txt
137+
$(AWK) '/^[^#]/ {printf "_%s\n",$$1}' $< >$@
138+
139+
exported_symbols_list = -exported_symbols_list exports.list
140+
endif
141+
142+
ifeq ($(PORTNAME), linux)
143+
$(shlib): exports.list
144+
145+
exports.list: exports.txt
146+
echo '{ global:' >$@
147+
$(AWK) '/^[^#]/ {printf "%s;\n",$$1}' $< >>$@
148+
echo ' local: *; };' >>$@
149+
150+
exported_symbols_list = -Wl,--version-script=exports.list
151+
endif
152+
128153
# depend on Makefile.global to force rebuild on re-run of configure
129154
$(srcdir)/libpq.rc: libpq.rc.in $(top_builddir)/src/Makefile.global
130155
sed -e 's/\(VERSION.*\),0 *$$/\1,'`date '+%y%j' | sed 's/^0*//'`'/' < $< > $@
@@ -147,7 +172,7 @@ uninstall: uninstall-lib
147172
rm -f '$(DESTDIR)$(includedir)/libpq-fe.h' '$(DESTDIR)$(includedir_internal)/libpq-int.h' '$(DESTDIR)$(includedir_internal)/pqexpbuffer.h' '$(DESTDIR)$(datadir)/pg_service.conf.sample'
148173

149174
clean distclean: clean-lib
150-
rm -f $(OBJS) pg_config_paths.h crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c thread.c md5.c ip.c encnames.c wchar.c pthread.h
175+
rm -f $(OBJS) pg_config_paths.h crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c thread.c md5.c ip.c encnames.c wchar.c pthread.h exports.list
151176
rm -f pg_config_paths.h # Might be left over from a Win32 client-only build
152177

153178
maintainer-clean: distclean

0 commit comments

Comments
 (0)