summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-09-09 15:16:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-09-09 15:17:01 -0400
commite3d77ea6b4e425093db23be492f236896dd7b501 (patch)
tree28b47369c072734046951043ddbb3f86505b13bc
parentcf984672427ebc4446213fe8f71d8899452802b6 (diff)
downloadpostgresql-e3d77ea6b4e425093db23be492f236896dd7b501.tar.gz
Prevent mis-linking of src/port and src/common functions on *BSD.
On ELF-based platforms (and maybe others?) it's possible for a shared library, when dynamically loaded into the backend, to call the backend versions of src/port and src/common functions rather than the frontend versions that are actually linked into the shlib. This is the cause of bug #15367 from Jeremy Evans, and is likely to lead to more problems in future; it's accidental that we've failed to notice any bad effects up to now. The recommended way to fix this on ELF-based platforms is to use a linker "version script" that makes the shlib's versions of the functions local. (Apparently, -Bsymbolic would fix it as well, but with other side effects that we don't want.) Doing so has the additional benefit that we can make sure the shlib only exposes the symbols that are meant to be part of its API, and not ones that are just for cross-file references within the shlib. So we'd already been using a version script for libpq on popular platforms, but it's now apparent that it's necessary for correctness on every ELF-based platform. Hence, add appropriate logic to the openbsd, freebsd, and netbsd stanzas of Makefile.shlib; this is just a copy-and-paste from the linux stanza. There may be additional work to do if commit ed0cdf0e0 reveals that the problem exists elsewhere, but this is all that is known to be needed right now. Back-patch to v10 where SCRAM support came in. The problem is ancient, but analysis suggests that there were no really severe consequences in older branches. Hence, I won't take the risk of such a large change in the build process for older branches. In passing, remove a rather opaque comment about -Bsymbolic; I don't think it's very on-point about why we don't use that, if indeed that's what it's talking about at all. Patch by me; thanks to Andrew Gierth for helping to diagnose the problem, and for additional testing. Discussion: https://postgr.es/m/153626613985.23143.4743626885618266803@wrigleys.postgresql.org
-rw-r--r--src/Makefile.shlib20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 95b82a6dea..9cfe49749e 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -64,11 +64,6 @@
#
# Got that? Look at src/interfaces/libpq/Makefile for an example.
#
-# While the linker allows creation of most shared libraries,
-# -Bsymbolic requires resolution of all symbols, making the
-# compiler a better choice for shared library creation on ELF platforms.
-# With the linker, -Bsymbolic requires the crt1.o startup object file.
-# bjm 2001-02-10
COMPILER = $(CC) $(CFLAGS)
@@ -149,6 +144,11 @@ ifeq ($(PORTNAME), openbsd)
ifdef soname
LINK.shared += -Wl,-x,-soname,$(soname)
endif
+ BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+ exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
+ ifneq (,$(exports_file))
+ LINK.shared += -Wl,--version-script=$(exports_file)
+ endif
SHLIB_LINK += -lc
else
LINK.shared = $(LD) -x -Bshareable -Bforcearchive
@@ -164,6 +164,11 @@ ifeq ($(PORTNAME), freebsd)
ifdef soname
LINK.shared += -Wl,-x,-soname,$(soname)
endif
+ BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+ exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
+ ifneq (,$(exports_file))
+ LINK.shared += -Wl,--version-script=$(exports_file)
+ endif
else
ifdef SO_MAJOR_VERSION
shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
@@ -178,6 +183,11 @@ ifeq ($(PORTNAME), netbsd)
ifdef soname
LINK.shared += -Wl,-x,-soname,$(soname)
endif
+ BUILD.exports = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+ exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
+ ifneq (,$(exports_file))
+ LINK.shared += -Wl,--version-script=$(exports_file)
+ endif
else
LINK.shared = $(LD) -x -Bshareable -Bforcearchive
endif