From 28ebafe49a2c3a71ee87082918205bab6c26f062 Mon Sep 17 00:00:00 2001 From: "Paul m. p. Peny" Date: Tue, 21 Jan 2025 11:18:47 +0100 Subject: [PATCH 1/2] add a llvm-ar step before link optimisation goal: keep libplite.a static with all debug speed up link/optimisation pass by re using the same static lib --- src/backend/Makefile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index adf3f16d2a7ff..bda01ff3abaa7 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -37,9 +37,11 @@ LOCALOBJS += utils/probes.o endif endif -OBJS = \ +ONLYOBJS = \ $(LOCALOBJS) \ - $(SUBDIROBJS) \ + $(SUBDIROBJS) +OBJS = \ + $(ONLYOBJS) \ $(top_builddir)/src/common/libpgcommon_srv.a \ $(top_builddir)/src/port/libpgport_srv.a @@ -60,16 +62,28 @@ override LDFLAGS := $(LDFLAGS) $(LDFLAGS_EX) $(LDFLAGS_EX_BE) all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP) +ifneq ($(PORTNAME), emscripten) ifneq ($(PORTNAME), cygwin) ifneq ($(PORTNAME), win32) ifneq ($(PORTNAME), aix) postgres: $(OBJS) - $(CC) $(MAIN_MODULE) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@ + $(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@ endif endif endif +endif + +ifeq ($(PORTNAME), emscripten) +PGLITE += $(top_builddir)/libpglite.a +PGLITE += $(top_builddir)/src/common/libpgcommon_srv.a +PGLITE += $(top_builddir)/src/port/libpgport_srv.a +PGMAIN = main/main.o tcop/postgres.o +postgres: $(OBJS) + $(AR) cr ../../libpglite.a $(filter-out $(PGMAIN),$(call expand_subsys,$(ONLYOBJS))) + COPTS="-Oz -g0 --closure 1" $(CC) $(MAIN_MODULE) $(CFLAGS) $(LDFLAGS) -o $@ $(PGMAIN) $(PGLITE) $(LIBS) +endif ifeq ($(PORTNAME), cygwin) From 5c926e307684e3be1e1aaccc127f37166e09cf06 Mon Sep 17 00:00:00 2001 From: "Paul m. p. Peny" Date: Wed, 22 Jan 2025 16:16:54 +0100 Subject: [PATCH 2/2] use clang partial linkin (-r) --- src/backend/Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index bda01ff3abaa7..0304de6f4e0eb 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -76,13 +76,17 @@ endif endif ifeq ($(PORTNAME), emscripten) -PGLITE += $(top_builddir)/libpglite.a -PGLITE += $(top_builddir)/src/common/libpgcommon_srv.a -PGLITE += $(top_builddir)/src/port/libpgport_srv.a +AR ?= llvm-ar +LIBPGLITE ?= $(top_builddir)/libpglite.a +LIBPG = $(top_builddir)/libpostgres.a +PGLITE = $(top_builddir)/src/common/libpgcommon_srv.a $(top_builddir)/src/port/libpgport_srv.a $(LIBPG) PGMAIN = main/main.o tcop/postgres.o postgres: $(OBJS) - $(AR) cr ../../libpglite.a $(filter-out $(PGMAIN),$(call expand_subsys,$(ONLYOBJS))) - COPTS="-Oz -g0 --closure 1" $(CC) $(MAIN_MODULE) $(CFLAGS) $(LDFLAGS) -o $@ $(PGMAIN) $(PGLITE) $(LIBS) + $(AR) rcs $(top_builddir)/libpgmain.a $(PGMAIN) + $(AR) rcs $(LIBPG) $(filter-out $(PGMAIN),$(call expand_subsys,$(ONLYOBJS))) + $(CC) -r -o $(top_builddir)/libpglite.o -Wl,--whole-archive $(PGLITE) + $(AR) rcs $(LIBPGLITE) $(top_builddir)/libpglite.o + COPTS="$(LOPTS)" $(CC) $(MAIN_MODULE) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPGLITE) $(top_builddir)/libpgmain.a $(LIBS) endif ifeq ($(PORTNAME), cygwin)