From 227614e9021f87aa31a744916b1d84dd9fd991c3 Mon Sep 17 00:00:00 2001 From: Shaoqi Bai Date: Wed, 24 Jun 2020 21:11:46 +0000 Subject: [PATCH] Using $ORIGIN as RUNPATH for runtime link When upgrading from GPDB5 to GPDB6, gpupgrade will need to be able to call binaries from both major versions. Relying on LD_LIBRARY_PATH is not an option because this can cause binaries to load libraries from the wrong version. Instead, we need the libraries to have RPATH/RUNPATH set correctly. Since the built binaries may be relocated we need to use a relative path. This commit disables the rpath configure option (which would result in an absolute path) and exports LD_RUN_PATH to use `$ORIGIN`. For most ELF files a RUNPATH of `$ORIGIN/../lib` is correct. For pygresql python module, the RUNPATH needs to be adjusted accordingly. Authored-by: Shaoqi Bai --- gpAux/Makefile | 12 +++++++++++- gpMgmt/bin/Makefile | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gpAux/Makefile b/gpAux/Makefile index fc2113504e..a261cce2d3 100644 --- a/gpAux/Makefile +++ b/gpAux/Makefile @@ -253,6 +253,12 @@ ifdef ADDON_DIR CONFIGFLAGS+=ADDON_DIR=$(ADDON_DIR) endif +ifneq "$(findstring $(BLD_ARCH),rhel6 rhel7)" "" +CONFIGFLAGS+= --disable-rpath +CONFIGFLAGS+= LDFLAGS='-Wl,--enable-new-dtags -Wl,-rpath,\$$$$ORIGIN/../lib' +CONFIGFLAGS+= LDFLAGS_SL='-Wl,--enable-new-dtags -Wl,-rpath,\$$$$ORIGIN/../lib' +endif + RECONFIG : rm -f Debug/GNUmakefile rm -f Release/GNUmakefile @@ -334,7 +340,11 @@ BLD_GPDB_BUILDSET=$($(BLD_ARCH)_GPDB_BUILDSET) # set default build steps define BUILD_STEPS @rm -rf $(INSTLOC) - cd $(BUILDDIR) && $(MAKE) $(PARALLEL_MAKE_OPTS) install + if [ "$(findstring $(BLD_ARCH),rhel6 rhel7)" = "" ]; then \ + cd $(BUILDDIR) && $(MAKE) $(PARALLEL_MAKE_OPTS) install; \ + else \ + cd $(BUILDDIR) && PYGRESQL_LDFLAGS='-Wl,-rpath,\$$$$ORIGIN/../../../lib -Wl,--enable-new-dtags' $(MAKE) $(PARALLEL_MAKE_OPTS) install; \ + fi \ #@$(MAKE) greenplum_path INSTLOC=$(INSTLOC) #@$(MAKE) mgmtcopy INSTLOC=$(INSTLOC) @$(MAKE) mkpgbouncer INSTLOC=$(INSTLOC) BUILDDIR=$(BUILDDIR) diff --git a/gpMgmt/bin/Makefile b/gpMgmt/bin/Makefile index 6683a1ed9b..490aec482e 100644 --- a/gpMgmt/bin/Makefile +++ b/gpMgmt/bin/Makefile @@ -64,7 +64,7 @@ pygresql: elif [ "$(BLD_ARCH)" = 'aix7_ppc_64' ]; then \ cd $(PYLIB_SRC)/$(PYGRESQL_DIR) && DESTDIR="$(DESTDIR)" CC="$(CC)" python_64 setup.py build; \ else \ - cd $(PYLIB_SRC)/$(PYGRESQL_DIR) && DESTDIR="$(DESTDIR)" CC="$(CC)" python setup.py build; \ + cd $(PYLIB_SRC)/$(PYGRESQL_DIR) && DESTDIR="$(DESTDIR)" CC="$(CC)" LDFLAGS='$(LDFLAGS) $(PYGRESQL_LDFLAGS)' python setup.py build; \ fi mkdir -p $(PYLIB_DIR)/pygresql if [ `uname -s` = 'Darwin' ]; then \ -- GitLab