From ee089509690eabf3ae1603896652190d3ff41f41 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 30 Sep 2026 15:58:33 -0400 Subject: [PATCH] Fix incorrect parallel build of jsonapi.o with Makefiles. Commit 0785d1b8b wrote jsonapi_shlib.o: override CPPFLAGS += -DJSONAPI_USE_PQEXPBUFFER forgetting that GNU make treats this change to CPPFLAGS as affecting not only jsonapi_shlib.o, but anything that gets built in pursuit of building jsonapi_shlib.o. Because of an even more ancient hack (cf 7143b3e82), that will include jsonapi.o if it's not been built already. If we do apply this -D switch to jsonapi.o, it gets built with the wrong expansible-string infrastructure, which manifests immediately as a link failure in pg_combinebackup and would misbehave at runtime even if the build somehow completed. Perhaps remarkably, we'd not seen field reports of build failures till now, but it's pretty easy to reproduce a mis-build by trying to build src/common/ with --shuffle and a high -j factor. To fix, don't modify CPPFLAGS this way; instead make a dedicated build rule for jsonapi_shlib.o that injects the additional switches. There might be other places with similar problems, but some desultory attempts with -j32 --shuffle on a 32-thread CPU didn't find any more build failures. Also, it looks like the meson build infrastructure lacks this problem (but I'm no meson expert). Bug: #19727 Reported-by: Ross Burton Author: Tom Lane Reviewed-by: Ross Burton Discussion: https://postgr.es/m/19727-32d67d9dea410f38@postgresql.org Backpatch-through: 18 --- src/common/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/Makefile b/src/common/Makefile index 3404601b6bf..a19995a5795 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -162,11 +162,6 @@ libpgcommon_shlib.a: $(OBJS_SHLIB) rm -f $@ $(AR) $(AROPT) $@ $^ -# The JSON API normally exits on out-of-memory; disable that behavior for shared -# library builds. This requires libpq's pqexpbuffer.h. -jsonapi_shlib.o: override CPPFLAGS += -DJSONAPI_USE_PQEXPBUFFER -jsonapi_shlib.o: override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) - # Because this uses its own compilation rule, it doesn't use the # dependency tracking logic from Makefile.global. To make sure that # dependency tracking works anyway for the *_shlib.o files, depend on @@ -176,6 +171,12 @@ jsonapi_shlib.o: override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) %_shlib.o: %.c %.o $(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@ +# The JSON API normally exits on out-of-memory; disable that behavior for shared +# library builds. This requires libpq's pqexpbuffer.h. +# This rule overrides the previous one, so must duplicate all its effects. +jsonapi_shlib.o: jsonapi.c jsonapi.o + $(CC) $(CFLAGS) $(CFLAGS_SL) -DJSONAPI_USE_PQEXPBUFFER -I$(libpq_srcdir) $(CPPFLAGS) -c $< -o $@ + libpgcommon_excluded_shlib.a: $(OBJS_EXCLUDED_SHLIB) rm -f $@ $(AR) $(AROPT) $@ $^