From 0f1e54c47c179bdbd69799170d9740e3e58e86db Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 16 Aug 2019 12:48:21 -0500 Subject: [PATCH] Pass -shared when linking some shared libraries Currently, we use $(LT_LDLIB_shlib) to build most of our shared libraries. This invokes libtool, passing our various flags like PTH_LDFLAGS and PTH_CFLAGS (since all of our shared-library code is for pthreads). Notably, we do NOT pass the -shared flag; the -shared flag tells libtool to only build a shared library, and to not also build a static library (on systems where libtool supports building shared and static libraries simultaneously). Because of this, our LT_LDLIB_shlib invocations build both, which is reasonably correct for our per-module convenience libraries (that end up getting linked statically into the binaries that we install), but is not entirely correct for the public libraries that we install. Specifically, for ABI compatibility purposes, we must provide both shared and static libraries of the public libraries that we install, and since libtool on AIX does not build (or install) a static library at all with --mode-link unless -static is passed, we have separate rules to build the shared and static libraries for final installation. This can cause install errors with parallel make (on non-AIX systems), and possibly other errors, when we go to install the relevant library into TOP_LIBDIR. For example, in src/kopenafs, we have the following rules: ${TOP_LIBDIR}/libkopenafs.${SHLIB_SUFFIX}: libkopenafs.la ${LT_INSTALL_DATA} libkopenafs.la ${TOP_LIBDIR}/libkopenafs.la ${RM} ${TOP_LIBDIR}/libkopenafs.la ${TOP_LIBDIR}/libkopenafs.a: libkopenafs.a ${INSTALL_DATA} libkopenafs.a $@ The rule to install libkopenafs.so will invoke libtool to do the install, which will install libkopenafs.so, libkopenafs.so.X.Y, and libkopenafs.a (from .libs/libkopenafs.a, not the libkopenafs.a we built separately). If we are running the rule to install libkopenafs.a in parallel, it may fail with an error like so: /usr/bin/install -c -m 644 libkopenafs.a /home/buildbot/openafs/fedora26-x86_64/build/lib/libkopenafs.a /usr/bin/install: cannot create regular file '/home/buildbot/openafs/fedora26-x86_64/build/lib/libkopenafs.a': File exists make[3]: *** [Makefile:35: /home/buildbot/openafs/fedora26-x86_64/build/lib/libkopenafs.a] Error 1 Even without that error, this confusion means that the libkopenafs.a installed into TOP_LIBDIR may be the one from src/kopenafs/libkopenafs.a, or the one from libtool's src/kopenafs/.libs/libkopenafs.a; it depends on what order the rules are run. If those libraries are different, that could potentially cause all sorts of other problems. To avoid this, we can pass -shared to libtool when building our shared libraries. We used to pass -shared when building shared libraries, since -shared is almost always one our SHLIB_LDFLAGS set in src/osconf.m4. However, ever since commit 2c3a517e (Retire Makefile.shared), SHD_CFLAGS, SHD_LDFLAGS, and SHD_CCRULE have all been unused, and SHD_LDFLAGS was the only place where we used SHLIB_LDFLAGS. As a result, we never use SHLIB_LDFLAGS anywhere, and so we never pass -shared to anything. However, we cannot pass -shared to libtool when building all of our shared libraries, since we do need the static library for our per-module convenience libraries. For example, liboafs_rx.la has no separately-built static library (librx.a is for LWP, liboafs_rx.{so,a} is for pthreads), but liboafs_rx needs to be linked statically into all of our command-line tools. So to fix this, introduce a new linking rule, called LT_LDLIB_shlib_only, which causes the given library to be built only as a shared library (by giving -shared to libtool), and not as a static library. Update the build rules to use this new linking rule for the libraries that need it, and leave the others alone. Since the only use of LT_LDLIB_shlib_missing is also used for a public library (afshcrypto), also pass -shared in that rule. Also remove SHD_* and SHLIB_LDFLAGS variables, since they are unused. Change-Id: Ia9e040afa3819f1ff70d050a400fecb9624bb9ba Reviewed-on: https://gerrit.openafs.org/13786 Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- src/cf/osconf.m4 | 23 ----------------------- src/config/Makefile.config.in | 11 +++-------- src/crypto/hcrypto/Makefile.in | 2 +- src/kopenafs/Makefile.in | 2 +- src/libafsauthent/Makefile.in | 2 +- src/libafsrpc/Makefile.in | 4 ++-- src/libuafs/Makefile.common.in | 2 +- 7 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/cf/osconf.m4 b/src/cf/osconf.m4 index b737041..69fd19c 100644 --- a/src/cf/osconf.m4 +++ b/src/cf/osconf.m4 @@ -51,7 +51,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -61,7 +60,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -80,7 +78,6 @@ case $AFS_SYSNAME in PAM_LIBS="/usr/lib/libpam.1" RANLIB="/usr/bin/ranlib" RM="/bin/rm" - SHLIB_LDFLAGS="-b -Bsymbolic" SHLIB_SUFFIX="sl" VFSCK_CFLAGS="-D_FILE64" XCFLAGS0="-ldld -lc -Wp,-H200000 -Wl,-a,archive -DAUTH_DBM_LOG +z -Wl,+k -D_LARGEFILE64_SOURCE" @@ -105,7 +102,6 @@ case $AFS_SYSNAME in PAM_LIBS="/usr/lib/libpam.1" RANLIB="/usr/bin/ranlib" RM="/bin/rm" - SHLIB_LDFLAGS="-b -Bsymbolic" SHLIB_SUFFIX="sl" VFSCK_CFLAGS="-I/usr/old/usr/include -D_FILE64" XCFLAGS0="-ldld -lc -Wp,-H200000 -Wl,-a,archive -DAUTH_DBM_LOG +z -Wl,+k -D_LARGEFILE64_SOURCE" @@ -131,7 +127,6 @@ case $AFS_SYSNAME in PAM_LIBS="/usr/lib/hpux32/libpam.so" RANLIB="/usr/bin/ranlib" RM="/bin/rm" - SHLIB_LDFLAGS="-b -Bsymbolic" SHLIB_SUFFIX="sl" VFSCK_CFLAGS="-I/usr/old/usr/include -D_FILE64" XCFLAGS0="-ldld -lc -Wp,-H200000 -Wl,-a,archive_shared -DAUTH_DBM_LOG +z -Wl,+k -D_LARGEFILE64_SOURCE" @@ -146,7 +141,6 @@ case $AFS_SYSNAME in MT_CFLAGS='-pthread -D_REENTRANT' PAM_OPTMZ=-O2 PAM_CFLAGS="-pipe -fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS="-pipe" ;; @@ -155,7 +149,6 @@ case $AFS_SYSNAME in MT_CFLAGS='-pthread -D_REENTRANT' PAM_OPTMZ=-O2 PAM_CFLAGS="-pipe -fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS="-pipe" ;; @@ -163,7 +156,6 @@ case $AFS_SYSNAME in amd64_fbsd_*) MT_CFLAGS='-pthread -D_REENTRANT' PAM_CFLAGS="-O2 -pipe -fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS="-O2 -pipe -fPIC" ;; @@ -173,7 +165,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-pipe -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS="-pipe" ;; @@ -182,7 +173,6 @@ case $AFS_SYSNAME in MT_LIBS='${XLIBS}' PAM_OPTMZ=-O2 PAM_CFLAGS="-pipe -fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS="-pipe" ;; @@ -193,7 +183,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" XCFLAGS="-G0" SHLIB_LINKER="${CC} -shared" ;; @@ -205,7 +194,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -213,7 +201,6 @@ case $AFS_SYSNAME in MT_CFLAGS='-pthread -D_REENTRANT' PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_CFLAGS="-fPIC" SHLIB_LINKER="${CC} -shared -m64" XCFLAGS="-m64" @@ -231,7 +218,6 @@ case $AFS_SYSNAME in OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -244,7 +230,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -256,7 +241,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-pipe -fpic" SHLIB_CFLAGS="-fpic" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" XCFLAGS= ;; @@ -355,7 +339,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -405,7 +388,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" SHLIB_LINKER="${CC} -shared" ;; @@ -417,7 +399,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x -Xlinker -Bsymbolic" OPTMZ=-O XCFLAGS="-D__s390x__" SHLIB_LINKER="${CC} -shared" @@ -478,7 +459,6 @@ case $AFS_SYSNAME in PAM_OPTMZ=-O2 PAM_CFLAGS="-Dlinux -DLINUX_PAM -fPIC" SHLIB_CFLAGS="-fPIC" - SHLIB_LDFLAGS="-shared -Xlinker -x" XCFLAGS64="-m64" XLDFLAGS64="-m64" SHLIB_LINKER="${CC} -shared" @@ -491,7 +471,6 @@ case $AFS_SYSNAME in PAM_CFLAGS="-KPIC" PAM_LIBS="-lc -lpam -lsocket -lnsl -lm" SHLIB_CFLAGS="-KPIC" - SHLIB_LDFLAGS="-G -Bsymbolic" XCFLAGS64='${XCFLAGS} -m64' XCFLAGS="-dy -Bdynamic" XLIBELFA="-lelf" @@ -530,7 +509,6 @@ case $AFS_SYSNAME in PAM_CFLAGS="-KPIC" PAM_LIBS="-lc -lpam -lsocket -lnsl -lm" SHLIB_CFLAGS="-KPIC" - SHLIB_LDFLAGS="-G -Bsymbolic" XCFLAGS0="-dy -Bdynamic" XCFLAGS64="${XCFLAGS0} -m64" XCFLAGS="${XCFLAGS0} ${XARCHFLAGS}" @@ -705,7 +683,6 @@ AC_SUBST(REGEX_OBJ) AC_SUBST(RM) AC_SUBST(RXDEBUG) AC_SUBST(SHLIB_CFLAGS) -AC_SUBST(SHLIB_LDFLAGS) AC_SUBST(SHLIB_LINKER) AC_SUBST(SHLIB_SUFFIX) AC_SUBST(VFSCK_CFLAGS) diff --git a/src/config/Makefile.config.in b/src/config/Makefile.config.in index ed4a5c5..a274925 100644 --- a/src/config/Makefile.config.in +++ b/src/config/Makefile.config.in @@ -103,7 +103,6 @@ ROKEN_HEADERS = @ROKEN_HEADERS@ ROKEN_LTLIBOBJS = @LTLIBOBJS@ SED = @SED@ SHLIB_CFLAGS = @SHLIB_CFLAGS@ -SHLIB_LDFLAGS = @SHLIB_LDFLAGS@ SHLIB_LINKER = @SHLIB_LINKER@ SHLIB_SUFFIX = @SHLIB_SUFFIX@ SYS_NAME = @AFS_SYSNAME@ @@ -242,12 +241,6 @@ PTH_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(MT_LDFLAGS) PTH_CCRULE =$(RUN_CC) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c PTH_CCRULE_NOQ=$(RUN_CC_NOQ) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c -# Shared -SHD_CFLAGS=$(MODULE_CFLAGS) $(COMMON_CFLAGS) $(MT_CFLAGS) $(SHLIB_CFLAGS) -SHD_LDFLAGS=$(MODULE_LDFLAGS) $(COMMON_LDFLAGS) $(SHLIB_LDFLAGS) -SHD_CCRULE =$(RUN_CC) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c -SHD_CCRULE_NOQ=$(RUN_CC_NOQ) $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(SHD_CFLAGS) $(CFLAGS_$(@)) -o $@ -c - # Libtool - for objects that are part of pthread-only libraries LT_CCRULE=$(RUN_CC) $(LIBTOOL) --quiet --mode=compile --tag=CC \ $(CC_WRAPPER) $(MT_CC) $(CPPFLAGS_$(@)) $(PTH_CFLAGS) $(CFLAGS_$(@)) -o $@ -c @@ -265,7 +258,9 @@ LT_LDLIB_shlib_common=$(LIBTOOL) --quiet --mode=link --tag=CC \ LT_LDLIB_shlib=$(LT_LDLIB_shlib_common) -export-symbols $(srcdir)/$@.sym -LT_LDLIB_shlib_missing=$(LT_LDLIB_shlib_common) -export-symbols-regex \ +LT_LDLIB_shlib_only=$(LT_LDLIB_shlib_common) -shared -export-symbols $(srcdir)/$@.sym + +LT_LDLIB_shlib_missing=$(LT_LDLIB_shlib_common) -shared -export-symbols-regex \ "($$(sed -e 's/^/^/' -e 's/$$/$$|/' -e '$$ s/|$$//' $(srcdir)/$@.sym | \ tr -d '\n'))" diff --git a/src/crypto/hcrypto/Makefile.in b/src/crypto/hcrypto/Makefile.in index 16abc10..3a2ebdf 100644 --- a/src/crypto/hcrypto/Makefile.in +++ b/src/crypto/hcrypto/Makefile.in @@ -72,7 +72,7 @@ clean: $(LT_objs): $(HEADERS) libafshcrypto.la: libafshcrypto.la.sym $(LT_objs) - $(LT_LDLIB_shlib) $(LT_objs) $(LT_libs) + $(LT_LDLIB_shlib_only) $(LT_objs) $(LT_libs) libafshcrypto.a: $(LT_objs) $(LT_LDLIB_static) $(LT_objs) diff --git a/src/kopenafs/Makefile.in b/src/kopenafs/Makefile.in index 7a1c8f5..111393d 100644 --- a/src/kopenafs/Makefile.in +++ b/src/kopenafs/Makefile.in @@ -75,7 +75,7 @@ libkopenafs.a: $(LT_objs) $(LT_LDLIB_static) $(LT_objs) libkopenafs.la: libkopenafs.la.sym $(LT_objs) - $(LT_LDLIB_shlib) $(LT_objs) + $(LT_LDLIB_shlib_only) $(LT_objs) test-unlog: test-unlog.lo libkopenafs.la $(LT_LDRULE_static) test-unlog.lo libkopenafs.la $(XLIBS) diff --git a/src/libafsauthent/Makefile.in b/src/libafsauthent/Makefile.in index 1993b8f..4dda1dc 100644 --- a/src/libafsauthent/Makefile.in +++ b/src/libafsauthent/Makefile.in @@ -39,7 +39,7 @@ all: libafsauthent.la libafsauthent_pic.la \ $(TOP_LIBDIR)/libafsauthent_pic.a libafsauthent.la: libafsauthent.la.sym $(LT_objs) $(LT_deps) libafsauthent_pic.la - $(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs) + $(LT_LDLIB_shlib_only) $(LT_objs) $(LT_deps) $(LT_libs) libafsauthent_pic.la: $(LT_objs) $(LT_LDLIB_pic) $(LT_objs) diff --git a/src/libafsrpc/Makefile.in b/src/libafsrpc/Makefile.in index a037ed8..0b3a305 100644 --- a/src/libafsrpc/Makefile.in +++ b/src/libafsrpc/Makefile.in @@ -41,10 +41,10 @@ all: libafsrpc.la libafsrpc.a libafsrpc_pic.la \ libafsrpc.la: libafsrpc.la.sym $(LT_objs) $(LT_deps) libafsrpc_pic.la @set -e; set -x; case "$(SYS_NAME)" in \ rs_aix*) \ - $(LT_LDLIB_shlib) -Wl,-bI:../sys/afsl.exp \ + $(LT_LDLIB_shlib_only) -Wl,-bI:../sys/afsl.exp \ $(LT_objs) $(LT_deps) $(LT_libs) ;; \ *) \ - $(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs);; \ + $(LT_LDLIB_shlib_only) $(LT_objs) $(LT_deps) $(LT_libs);; \ esac libafsrpc_pic.la: $(LT_objs) diff --git a/src/libuafs/Makefile.common.in b/src/libuafs/Makefile.common.in index b93d550..de3d2be 100644 --- a/src/libuafs/Makefile.common.in +++ b/src/libuafs/Makefile.common.in @@ -194,7 +194,7 @@ ${TOP_LIBDIR}/libuafs_pic.a: libuafs_pic.la $(LT_objs): h libuafs.la: $(LT_objs) - $(LT_LDLIB_shlib) $(LT_objs) + $(LT_LDLIB_shlib_only) $(LT_objs) libuafs.a: $(LT_objs) $(LT_LDLIB_static) $(LT_objs) -- 1.9.4