Commit 9956ddc1 authored by Peter Eisentraut's avatar Peter Eisentraut

Link postgres from all object files at once, to avoid the error-prone

SUBSYS.o step and allow for better optimization by the linker.

Instead of partial linking into SUBSYS.o, the list of object files is
assembled in objfiles.txt files that are expanded when the final
linking is done.

Because we are not yet sure how long command lines different platforms
can handle, the old way of linking is still available, by defining the
make variable PARTIAL_LINKING (e.g., make all PARTIAL_LINKING=1).  If
we determine that this is necessary for some platforms, then we will
document this in a more prominent place.
parent ad20c990
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.125 2008/01/01 19:45:45 momjian Exp $ # $PostgreSQL: pgsql/src/backend/Makefile,v 1.126 2008/02/25 17:55:42 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -14,17 +14,17 @@ subdir = src/backend ...@@ -14,17 +14,17 @@ subdir = src/backend
top_builddir = ../.. top_builddir = ../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
DIRS = access bootstrap catalog parser commands executor lib libpq \ SUBDIRS = access bootstrap catalog parser commands executor lib libpq \
main nodes optimizer port postmaster regex rewrite \ main nodes optimizer port postmaster regex rewrite \
storage tcop tsearch utils $(top_builddir)/src/timezone storage tcop tsearch utils $(top_builddir)/src/timezone
SUBSYSOBJS = $(DIRS:%=%/SUBSYS.o) include $(srcdir)/common.mk
ifeq ($(enable_dtrace), yes) ifeq ($(enable_dtrace), yes)
LOCALOBJS += utils/probes.o LOCALOBJS += utils/probes.o
endif endif
OBJS = $(SUBSYSOBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
# We put libpgport into OBJS, so remove it from LIBS; also add libldap # We put libpgport into OBJS, so remove it from LIBS; also add libldap
LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE) LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
...@@ -41,7 +41,7 @@ ifneq ($(PORTNAME), win32) ...@@ -41,7 +41,7 @@ ifneq ($(PORTNAME), win32)
ifneq ($(PORTNAME), aix) ifneq ($(PORTNAME), aix)
postgres: $(OBJS) postgres: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
endif endif
endif endif
...@@ -51,13 +51,13 @@ ifeq ($(PORTNAME), cygwin) ...@@ -51,13 +51,13 @@ ifeq ($(PORTNAME), cygwin)
postgres: $(OBJS) postgres.def libpostgres.a postgres: $(OBJS) postgres.def libpostgres.a
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(OBJS) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
rm -f $@.exp $@.base rm -f $@.exp $@.base
postgres.def: $(OBJS) postgres.def: $(OBJS)
$(DLLTOOL) --export-all --output-def $@ $^ $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
libpostgres.a: postgres.def libpostgres.a: postgres.def
$(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@ $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
...@@ -69,13 +69,13 @@ LIBS += -lsecur32 ...@@ -69,13 +69,13 @@ LIBS += -lsecur32
postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES) postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(WIN32RES) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(OBJS) $(WIN32RES) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
rm -f $@.exp $@.base rm -f $@.exp $@.base
postgres.def: $(OBJS) postgres.def: $(OBJS)
$(DLLTOOL) --export-all --output-def $@ $^ $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
libpostgres.a: postgres.def libpostgres.a: postgres.def
$(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@ $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
...@@ -85,10 +85,10 @@ endif # win32 ...@@ -85,10 +85,10 @@ endif # win32
ifeq ($(PORTNAME), aix) ifeq ($(PORTNAME), aix)
postgres: $(POSTGRES_IMP) postgres: $(POSTGRES_IMP)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
$(POSTGRES_IMP): $(OBJS) $(POSTGRES_IMP): $(OBJS)
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $^ $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
ifeq ($(host_os), aix3.2.5) ifeq ($(host_os), aix3.2.5)
$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@ $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
else else
...@@ -102,19 +102,14 @@ endif ...@@ -102,19 +102,14 @@ endif
endif # aix endif # aix
# Parallel make trickery
$(SUBSYSOBJS): $(DIRS:%=%-recursive) ;
.PHONY: $(DIRS:%=%-recursive)
# Update the commonly used headers before building the subdirectories # Update the commonly used headers before building the subdirectories
$(DIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h $(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h
$(MAKE) -C $(subst -recursive,,$@) all
# The postgres.o target is needed by the rule in Makefile.global that # The postgres.o target is needed by the rule in Makefile.global that
# creates the exports file when MAKE_EXPORTS = true. # creates the exports file when MAKE_EXPORTS = true.
postgres.o: $(OBJS) postgres.o: $(OBJS)
$(CC) $(LDREL) $(LDFLAGS) $^ $(LIBS) -o $@ $(CC) $(LDREL) $(LDFLAGS) $(call expand_subsys,$^) $(LIBS) -o $@
# The following targets are specified in make commands that appear in # The following targets are specified in make commands that appear in
...@@ -141,7 +136,7 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h ...@@ -141,7 +136,7 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
$(LN_S) ../../../$(subdir)/utils/fmgroids.h . $(LN_S) ../../../$(subdir)/utils/fmgroids.h .
utils/probes.o: utils/probes.d $(SUBSYSOBJS) utils/probes.o: utils/probes.d $(SUBDIROBJS)
$(DTRACE) $(DTRACEFLAGS) -G -s $^ -o $@ $(DTRACE) $(DTRACEFLAGS) -G -s $^ -o $@
...@@ -241,7 +236,6 @@ endif ...@@ -241,7 +236,6 @@ endif
ifeq ($(PORTNAME), win32) ifeq ($(PORTNAME), win32)
rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES) rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES)
endif endif
for i in $(DIRS); do $(MAKE) -C $$i clean || exit; done
distclean: clean distclean: clean
rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
...@@ -264,4 +258,4 @@ maintainer-clean: distclean ...@@ -264,4 +258,4 @@ maintainer-clean: distclean
# are up to date. It saves the time of doing all the submakes. # are up to date. It saves the time of doing all the submakes.
.PHONY: quick .PHONY: quick
quick: $(OBJS) quick: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o postgres $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres
# #
# Common make rules for backend # Common make rules for backend
# #
# $PostgreSQL: pgsql/src/backend/common.mk,v 1.1 2008/02/19 10:30:06 petere Exp $ # $PostgreSQL: pgsql/src/backend/common.mk,v 1.2 2008/02/25 17:55:42 petere Exp $
# #
SUBDIROBJS = $(SUBDIRS:%=%/SUBSYS.o) # When including this file, set OBJS to the object files created in
# this directory and SUBDIRS to subdirectories containing more things
# to build.
all: SUBSYS.o ifdef PARTIAL_LINKING
# old style: linking using SUBSYS.o
subsysfilename = SUBSYS.o
else
# new style: linking all object files at once
subsysfilename = objfiles.txt
endif
SUBDIROBJS = $(SUBDIRS:%=%/$(subsysfilename))
# top-level backend directory obviously has its own "all" target
ifneq ($(subdir), src/backend)
all: $(subsysfilename)
endif
SUBSYS.o: $(SUBDIROBJS) $(OBJS) SUBSYS.o: $(SUBDIROBJS) $(OBJS)
$(LD) $(LDREL) $(LDOUT) $@ $^ $(LD) $(LDREL) $(LDOUT) $@ $^
objfiles.txt: $(SUBDIROBJS) $(OBJS)
( $(if $(SUBDIROBJS),cat $(SUBDIROBJS); )echo $(addprefix $(subdir)/,$(OBJS)) ) >$@
# make function to expand objfiles.txt contents
expand_subsys = $(foreach file,$(filter %/objfiles.txt,$(1)),$(patsubst ../../src/backend/%,%,$(addprefix $(top_builddir)/,$(shell cat $(file))))) $(filter-out %/objfiles.txt,$(1))
# Parallel make trickery
$(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ; $(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ;
.PHONY: $(SUBDIRS:%=%-recursive) .PHONY: $(SUBDIRS:%=%-recursive)
$(SUBDIRS:%=%-recursive): $(SUBDIRS:%=%-recursive):
$(MAKE) -C $(subst -recursive,,$@) SUBSYS.o $(MAKE) -C $(subst -recursive,,$@) all
clean: clean-local clean: clean-local
clean-local: clean-local:
ifdef SUBDIRS ifdef SUBDIRS
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean || exit; done for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean || exit; done
endif endif
rm -f SUBSYS.o $(OBJS) rm -f $(subsysfilename) $(OBJS)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment