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

Commit dc227eb

Browse files
committed
Add a build-time check that libpq doesn't call exit() or abort().
Directly exiting or aborting seems like poor form for a general-purpose library. Now that libpq liberally uses bits out of src/common/, it's very easy to accidentally include code that would do something unwanted like calling exit(1) after OOM --- see for example 8ec00dc. Hence, add a simple cross-check that no such calls have made it into libpq.so. The cross-check depends on nm(1) being available and being able to work on a shared library, which probably isn't true everywhere. But we can just make the test silently do nothing if nm fails. As long as the check is effective on common platforms, that should be good enough. (By the same logic, I've not worried about providing an equivalent test in MSVC builds.) Discussion: https://postgr.es/m/3128896.1624742969@sss.pgh.pa.us
1 parent aaddf6b commit dc227eb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/interfaces/libpq/Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,19 @@ SHLIB_EXPORTS = exports.txt
9696

9797
PKG_CONFIG_REQUIRES_PRIVATE = libssl libcrypto
9898

99-
all: all-lib
99+
all: all-lib check-libpq-refs
100100

101101
# Shared library stuff
102102
include $(top_srcdir)/src/Makefile.shlib
103103
backend_src = $(top_srcdir)/src/backend
104104

105+
# Check for functions that libpq must not call, currently abort() and exit().
106+
# If nm doesn't exist or doesn't work on shlibs, this test will silently
107+
# do nothing, which is fine. The exclusion of _eprintf.o is to prevent
108+
# complaining about <assert.h> infrastructure on ancient macOS releases.
109+
.PHONY: check-libpq-refs
110+
check-libpq-refs: $(shlib)
111+
! nm -A -g -u $< 2>/dev/null | grep -v '_eprintf\.o:' | grep -e abort -e exit
105112

106113
# Make dependencies on pg_config_paths.h visible in all builds.
107114
fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h

0 commit comments

Comments
 (0)