This is an automated email from the ASF dual-hosted git repository. avamingli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit d107ea4f017570d2fe71395f42d6cad52a840e8f Author: Zhang Mingli <[email protected]> AuthorDate: Thu May 28 18:22:28 2026 +0800 macOS: defer libpostgres.so's undefined symbols to load time With --enable-shared-postgres-backend (default) the libpostgres.so recipe filters out main/main.o, but other backend objects still reference symbols defined in main.o (progname, etc.). On Linux the default linker behaviour permits undefined references in a shared library; on macOS, ld -dynamiclib rejects them with 'Undefined symbols ... _progname'. Pass -Wl,-undefined,dynamic_lookup only when PORTNAME=darwin so those symbols resolve at load time against the postgres executable that loads libpostgres.so. The Linux behaviour is unchanged. --- src/backend/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 79dcdbb5ba3..675d97a6617 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -109,8 +109,18 @@ SYMBOL_MAPPING_FLAGS = -Wl,--version-script=$(SYMBOL_MAP_FILE) endif ifeq ($(enable_shared_postgres_backend),yes) all: libpostgres.so + +# On macOS, main/main.o (providing `progname` and other globals) is filtered +# out of libpostgres.so but is linked into the postgres executable. Tell ld +# to defer those undefined symbols to load time (resolved when the postgres +# binary loads libpostgres.so). Linux's ld allows undefined refs in shared +# libs by default, so no flag needed there. +ifeq ($(PORTNAME), darwin) +LIBPOSTGRES_SO_LDFLAGS = -Wl,-undefined,dynamic_lookup +endif + libpostgres.so: $(OBJS) $(SYMBOL_MAP_FILE) - $(CXX) -shared $(CXXFLAGS) $(LDFLAGS) $(LDFLAGS_SL) $(export_dynamic) \ + $(CXX) -shared $(CXXFLAGS) $(LDFLAGS) $(LDFLAGS_SL) $(LIBPOSTGRES_SO_LDFLAGS) $(export_dynamic) \ $(filter-out main/main.o, $(call expand_subsys,$(OBJS))) $(LIBS) $(SYMBOL_MAPPING_FLAGS) -o $@ # if enable-build-postgres-with-shared is yes, link postgres with shared library libpostgres.so --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
