PG12, PGXS and linking pgfeutils

Ian Barwick <ian.barwick@2ndquadrant.com>

From: Ian Barwick <ian.barwick@2ndquadrant.com>
To: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2019-05-07T05:24:19Z
Lists: pgsql-hackers

Attachments

Hi

Commit cc8d4151 [*] introduced a dependency between some functions in
libpgcommon and libpgfeutils, which is not reflected in the linker options
provided when building an external program using PGXS, e.g. attempting to
build the attached (trivial) example results in:

     $ PATH=$PG_HEAD:$PATH USE_PGXS=1 make
     gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -ggdb -Og -g3 -fno-omit-frame-pointer -I. -I./ -I/home/ibarwick/devel/builds/HEAD/include/postgresql/server -I/home/ibarwick/devel/builds/HEAD/include/postgresql/internal  -D_GNU_SOURCE   -c -o pgxs-test.o pgxs-test.c
     gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -ggdb -Og -g3 -fno-omit-frame-pointer pgxs-test.o  -L/home/ibarwick/devel/builds/HEAD/lib   -Wl,--as-needed -Wl,-rpath,'/home/ibarwick/devel/builds/HEAD/lib',--enable-new-dtags  -L/home/ibarwick/devel/builds/HEAD/lib -lpgcommon -lpgport -L/home/ibarwick/devel/builds/HEAD/lib -lpq -lpgcommon -lpgport -lpthread -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lrt -lcrypt -ldl -lm  -o pgxs-test
     /home/ibarwick/devel/builds/HEAD/lib/libpgcommon.a(pgfnames.o): In function `pgfnames':
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:48: undefined reference to `__pg_log_level'
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:48: undefined reference to `pg_log_generic'
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:69: undefined reference to `__pg_log_level'
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:69: undefined reference to `pg_log_generic'
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:74: undefined reference to `__pg_log_level'
     /home/ibarwick/devel/postgresql/src/common/pgfnames.c:74: undefined reference to `pg_log_generic'
     collect2: error: ld returned 1 exit status
     make: *** [pgxs-test] Error 1

which is a regression compared to PG11 and earlier.

Workaround/possible fix is to include "pgfeutils" in the "libpq_pgport" definition, i.e.:

     *** a/src/Makefile.global.in
     --- b/src/Makefile.global.in
     *************** libpq = -L$(libpq_builddir) -lpq
     *** 561,567 ****
       # on client link lines, since that also appears in $(LIBS).
       # libpq_pgport_shlib is the same idea, but for use in client shared libraries.
       ifdef PGXS
     ! libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
       libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
       else
       libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
     --- 561,567 ----
       # on client link lines, since that also appears in $(LIBS).
       # libpq_pgport_shlib is the same idea, but for use in client shared libraries.
       ifdef PGXS
     ! libpq_pgport = -L$(libdir) -lpgcommon -lpgport -lpgfeutils $(libpq)
       libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
       else
       libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)

I presume a similar modification may need to be added to the following lines in
that section but haven't had a chance to look in detail yet (and may be barking
up the wrong tree entirely of course).

[*] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cc8d41511721d25d557fc02a46c053c0a602fed


Regards


Ian Barwick

-- 
  Ian Barwick                   https://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services

Commits

  1. Move logging.h and logging.c from src/fe_utils/ to src/common/.

  2. Remove pg_rewind's private logging.h/logging.c files.

  3. Unified logging system for command-line programs