On 12/12/2011 02:59 PM, Tom Lane wrote:
Peter Eisentraut<pete...@gmx.net>  writes:
On lör, 2011-12-10 at 20:26 -0500, Tom Lane wrote:
Right now, libpq laboriously rebuilds all the .o files it needs from
src/port/ so as to get them with -fpic.  It would be nice if we could
clean that up while we're doing this.  It might be all right to always
build the client-side version of libpgport with -fpic, though I'd be sad
if that leaked into the server-side build.
So would we continue to build the client binaries (psql, pg_dump, etc.)
against the static libpgport.a, thus keeping it "invisible" there, or
would we dynamically link them, thus creating a new dependency.
I think that if possible we should avoid creating a new dependency for
either the client binaries or libpq.so itself; what I suggest above
is only a simplification of the build process for libpq.  If we create
a new dependency we risk packagers breaking things by forgetting to
include it.

The Fedora/RHEL rule against static libraries is meant to prevent
situations where changes in a library would require rebuilding other
packages to get the fixes in place.  If we had to make a quick security
fix in libpq, for example, it would suck if dozens of other packages had
to be rebuilt to propagate the change everywhere.  However, I don't think
that concern applies to programs that are in the same source package as
the library --- they'd get rebuilt anyway.  So I see nothing wrong with
continuing to statically link these .o files into files belonging to the
postgresql package.  It's just that I can't export them in a .a file for
*other* source packages to use.

(Whether a security issue in libpgport is really likely to happen is not
a question that this policy concerns itself with ...)



OK, my possibly naïve approach is shown in the attached. Essentially it builds libpgport-shared.so and then installs it as libpgport.so. That ensures that the library is not used in building any postgres binaries or libraries. Places such as libpq that formerly symlinked and recompiled the sources in a way that is suitable for a shared library now just link in the already built object files.

Is there a better way to do this?

cheers

andrew


*** src/port/Makefile	2011-12-03 17:21:59.944509111 -0500
--- src/port/GNUmakefile	2011-12-12 22:32:50.875312294 -0500
***************
*** 37,47 ****
  # foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
  OBJS_SRV = $(OBJS:%.o=%_srv.o)
  
! all: libpgport.a libpgport_srv.a
  
! # libpgport is needed by some contrib
  install: all installdirs
! 	$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
  
  installdirs:
  	$(MKDIR_P) '$(DESTDIR)$(libdir)'
--- 37,55 ----
  # foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
  OBJS_SRV = $(OBJS:%.o=%_srv.o)
  
! NAME = pgport-shared
! SO_MAJOR_VERSION= 1
! SO_MINOR_VERSION= 1
  
! include $(top_srcdir)/src/Makefile.shlib
! 
! all: all-lib libpgport_srv.a
! 	rm -f libpgport.a && $(LN_S) libpgport-shared.a libpgport.a
! 
! # libpgport is needed by any exe built with pgxs
  install: all installdirs
! 	rm -f libpgport.so* && $(LN_S) libpgport-shared.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION) libpgport.so.$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
! 	$(MAKE) -f GNUmakefile.installshared install
  
  installdirs:
  	$(MKDIR_P) '$(DESTDIR)$(libdir)'
***************
*** 49,57 ****
  uninstall:
  	rm -f '$(DESTDIR)$(libdir)/libpgport.a'
  
- libpgport.a: $(OBJS)
- 	$(AR) $(AROPT) $@ $^
- 
  # thread.o needs PTHREAD_CFLAGS (but thread_srv.o does not)
  thread.o: thread.c
  	$(CC) $(CFLAGS) $(CPPFLAGS) $(PTHREAD_CFLAGS) -c $<
--- 57,62 ----
***************
*** 64,70 ****
  	$(AR) $(AROPT) $@ $^
  
  %_srv.o: %.c
! 	$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
  
  $(OBJS_SRV): | submake-errcodes
  
--- 69,75 ----
  	$(AR) $(AROPT) $@ $^
  
  %_srv.o: %.c
! 	$(CC) $(subst $(CFLAGS_SL),,$(CFLAGS)) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
  
  $(OBJS_SRV): | submake-errcodes
  
***************
*** 97,100 ****
  	echo "#define MANDIR \"$(mandir)\"" >>$@
  
  clean distclean maintainer-clean:
! 	rm -f libpgport.a libpgport_srv.a $(OBJS) $(OBJS_SRV) pg_config_paths.h
--- 102,105 ----
  	echo "#define MANDIR \"$(mandir)\"" >>$@
  
  clean distclean maintainer-clean:
! 	rm -f libpgport.so* libpgport.a libpgport_srv.a $(OBJS) $(OBJS_SRV) pg_config_paths.h
*** /dev/null	2011-12-12 18:04:00.410999999 -0500
--- src/port/GNUmakefile.installshared	2011-12-12 22:29:29.508512245 -0500
***************
*** 0 ****
--- 1,11 ----
+ subdir = src/port
+ top_builddir = ../..
+ include $(top_builddir)/src/Makefile.global
+ 
+ NAME = pgport
+ SO_MAJOR_VERSION= 1
+ SO_MINOR_VERSION= 1
+ 
+ include $(top_srcdir)/src/Makefile.shlib
+ 
+ install: install-lib
*** src/interfaces/libpq/Makefile	2011-11-02 18:40:03.040342172 -0400
--- src/interfaces/libpq/GNUmakefile	2011-12-13 15:42:16.477592793 -0500
***************
*** 88,94 ****
  # For some libpgport modules, this only happens if configure decides 
  # the module is needed (see filter hack in OBJS, above).
  
! chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c inet_net_ntop.c noblock.c open.c pgsleep.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c thread.c win32error.c win32setlocale.c: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  ip.c md5.c: % : $(backend_src)/libpq/%
--- 88,94 ----
  # For some libpgport modules, this only happens if configure decides 
  # the module is needed (see filter hack in OBJS, above).
  
! chklocale.o crypt.o getaddrinfo.o getpeereid.o inet_aton.o inet_net_ntop.o noblock.o open.o pgsleep.o pgstrcasecmp.o snprintf.o strerror.o strlcpy.o thread.o win32error.o win32setlocale.o: % : $(top_builddir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  ip.c md5.c: % : $(backend_src)/libpq/%
***************
*** 134,142 ****
  	rm -f $(OBJS) pthread.h libpq.rc
  # Might be left over from a Win32 client-only build
  	rm -f pg_config_paths.h
! 	rm -f inet_net_ntop.c noblock.c pgstrcasecmp.c thread.c
! 	rm -f chklocale.c crypt.c getaddrinfo.c getpeereid.c inet_aton.c open.c snprintf.c strerror.c strlcpy.c win32error.c win32setlocale.c
! 	rm -f pgsleep.c	
  	rm -f md5.c ip.c
  	rm -f encnames.c wchar.c
  
--- 134,142 ----
  	rm -f $(OBJS) pthread.h libpq.rc
  # Might be left over from a Win32 client-only build
  	rm -f pg_config_paths.h
! 	rm -f inet_net_ntop.o noblock.o pgstrcasecmp.o thread.o
! 	rm -f chklocale.o crypt.o getaddrinfo.o getpeereid.o inet_aton.o open.o snprintf.o strerror.o strlcpy.o win32error.o win32setlocale.o
! 	rm -f pgsleep.o	
  	rm -f md5.c ip.c
  	rm -f encnames.c wchar.c
  
*** src/interfaces/ecpg/pgtypeslib/Makefile	2011-07-06 12:01:06.112433940 -0400
--- src/interfaces/ecpg/pgtypeslib/GNUmakefile	2011-12-13 15:00:27.382807330 -0500
***************
*** 42,48 ****
  # necessarily use the same object files as the backend uses. Instead,
  # symlink the source files in here and build our own object file.
  
! pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  install: all installdirs install-lib
--- 42,48 ----
  # necessarily use the same object files as the backend uses. Instead,
  # symlink the source files in here and build our own object file.
  
! pgstrcasecmp.o rint.o snprintf.o: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  install: all installdirs install-lib
***************
*** 52,57 ****
  uninstall: uninstall-lib
  
  clean distclean: clean-lib
! 	rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c
  
  maintainer-clean: distclean maintainer-clean-lib
--- 52,57 ----
  uninstall: uninstall-lib
  
  clean distclean: clean-lib
! 	rm -f $(OBJS) pgstrcasecmp.o rint.o snprintf.o
  
  maintainer-clean: distclean maintainer-clean-lib
*** src/interfaces/ecpg/ecpglib/Makefile	2011-11-02 18:40:03.037342166 -0400
--- src/interfaces/ecpg/ecpglib/GNUmakefile	2011-12-13 15:23:14.110599114 -0500
***************
*** 57,67 ****
  # necessarily use the same object files as the backend uses. Instead,
  # symlink the source files in here and build our own object file.
  
! path.c pgstrcasecmp.c snprintf.c strlcpy.c thread.c win32setlocale.c: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
- path.o: path.c $(top_builddir)/src/port/pg_config_paths.h
  
  $(top_builddir)/src/port/pg_config_paths.h:
  	$(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
--- 57,66 ----
  # necessarily use the same object files as the backend uses. Instead,
  # symlink the source files in here and build our own object file.
  
! path.o pgstrcasecmp.o snprintf.o strlcpy.o thread.o win32setlocale.o: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
  
  $(top_builddir)/src/port/pg_config_paths.h:
  	$(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
***************
*** 74,79 ****
  
  clean distclean: clean-lib
  	rm -f $(OBJS)
! 	rm -f path.c pgstrcasecmp.c snprintf.c strlcpy.c thread.c win32setlocale.c
  
  maintainer-clean: distclean maintainer-clean-lib
--- 73,78 ----
  
  clean distclean: clean-lib
  	rm -f $(OBJS)
! 	rm -f path.o pgstrcasecmp.o snprintf.o strlcpy.o thread.o win32setlocale.o
  
  maintainer-clean: distclean maintainer-clean-lib
*** src/interfaces/ecpg/compatlib/Makefile	2011-07-06 12:01:06.104433942 -0400
--- src/interfaces/ecpg/compatlib/GNUmakefile	2011-12-13 15:36:03.603199693 -0500
***************
*** 45,51 ****
  # Shared library stuff
  include $(top_srcdir)/src/Makefile.shlib
  
! snprintf.c: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  install: all installdirs install-lib
--- 45,51 ----
  # Shared library stuff
  include $(top_srcdir)/src/Makefile.shlib
  
! snprintf.o: % : $(top_srcdir)/src/port/%
  	rm -f $@ && $(LN_S) $< .
  
  install: all installdirs install-lib
***************
*** 55,60 ****
  uninstall: uninstall-lib
  
  clean distclean: clean-lib
! 	rm -f $(OBJS) snprintf.c
  
  maintainer-clean: distclean maintainer-clean-lib
--- 55,60 ----
  uninstall: uninstall-lib
  
  clean distclean: clean-lib
! 	rm -f $(OBJS) snprintf.o
  
  maintainer-clean: distclean maintainer-clean-lib
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to