From 7205751c32f4d3f6c4a7d4de48e78619c90834ca Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 22 Feb 2017 16:41:07 +1000 Subject: [PATCH 4/4] Ticket 49141 - Enable tcmalloc Bug Description: tcmallon conflicts with asan. Additionally, tcmalloc needs to use -lpthread, so we should guarantee this with the use of the pkg-config file. Fix Description: Fix the rpm to use asan *or* tcmalloc. Fix configure to explode if you try and use both. Fix m4/tcmalloc to use pkg-config file. Update bundled tcmalloc link to apply to all binaries to ensure proper behaviour of the server. This also limits tcmalloc to supported arches (IE exclude s390) https://pagure.io/389-ds-base/issue/49141 Author: wibrown Review by: ??? --- Makefile.am | 11 +++++++---- configure.ac | 16 +++++++++++++--- m4/tcmalloc.m4 | 48 ++++++++++++++++++++++++++++++++++-------------- rpm/389-ds-base.spec.in | 8 +++++++- 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1910958..d712aba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,8 @@ NSPR_INCLUDES = @nspr_inc@ SVRCORE_INCLUDES = @svrcore_inc@ SASL_INCLUDES = @sasl_inc@ EVENT_INCLUDES = @event_inc@ +# Not used currently +# TCMALLOC_INCLUDES = @tcmalloc_inc@ # We can't add the lfds includes all the time as they have a "bomb" in them that # prevents compilation on unsupported hardware arches. @@ -125,7 +127,7 @@ PCRE_LINK = @pcre_lib@ -lpcre NETSNMP_LINK = @netsnmp_lib@ @netsnmp_link@ PAM_LINK = -lpam KERBEROS_LINK = $(kerberos_lib) -TCMALLOC_LINK = @tcmalloc_link@ +TCMALLOC_LINK = @tcmalloc_lib@ EVENT_LINK = @event_lib@ LIBSOCKET=@LIBSOCKET@ @@ -141,7 +143,8 @@ if HPUX AM_LDFLAGS = -lpthread else #AM_LDFLAGS = -Wl,-z,defs -AM_LDFLAGS = $(ASAN_DEFINES) $(PROFILING_LINKS) +# Provide the tcmalloc links if needed +AM_LDFLAGS = $(ASAN_DEFINES) $(PROFILING_LINKS) $(TCMALLOC_LINK) endif #end hpux # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info @@ -1224,7 +1227,7 @@ libslapd_la_CPPFLAGS = $(AM_CPPFLAGS) $(DSPLUGIN_CPPFLAGS) $(SASL_INCLUDES) @db_ if SPARC libslapd_la_SOURCES += ldap/servers/slapd/slapi_counter_sunos_sparcv9.S endif -libslapd_la_LIBADD = $(LDAPSDK_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(NSS_LINK) $(NSPR_LINK) $(KERBEROS_LINK) $(PCRE_LINK) $(THREADLIB) $(SYSTEMD_LINK) $(TCMALLOC_LINK) +libslapd_la_LIBADD = $(LDAPSDK_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(NSS_LINK) $(NSPR_LINK) $(KERBEROS_LINK) $(PCRE_LINK) $(THREADLIB) $(SYSTEMD_LINK) libslapd_la_LDFLAGS = $(AM_LDFLAGS) $(SLAPD_LDFLAGS) @@ -1954,7 +1957,7 @@ ns_slapd_SOURCES = ldap/servers/slapd/abandon.c \ ns_slapd_CPPFLAGS = $(AM_CPPFLAGS) $(DSPLUGIN_CPPFLAGS) $(SASL_INCLUDES) $(SVRCORE_INCLUDES) ns_slapd_LDADD = libnunc-stans.la libslapd.la libldaputil.a $(LDAPSDK_LINK) $(NSS_LINK) $(LIBADD_DL) \ - $(NSPR_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(LIBNSL) $(LIBSOCKET) $(THREADLIB) $(SYSTEMD_LINK) $(EVENT_LINK) $(TCMALLOC_LINK) + $(NSPR_LINK) $(SASL_LINK) $(SVRCORE_LINK) $(LIBNSL) $(LIBSOCKET) $(THREADLIB) $(SYSTEMD_LINK) $(EVENT_LINK) ns_slapd_DEPENDENCIES = libslapd.la libnunc-stans.la # We need to link ns-slapd with the C++ compiler on HP-UX since we load # some C++ shared libraries (such as icu). diff --git a/configure.ac b/configure.ac index de7f3cb..4e3e9fb 100644 --- a/configure.ac +++ b/configure.ac @@ -551,6 +551,7 @@ case $host in platform="linux" initdir='$(sysconfdir)/rc.d/init.d' # do arch specific linux stuff here + # TCMalloc is only on i686, x86_64, ppc64 and arm, so we pick that here. case $host in i*86-*-linux*) AC_DEFINE([CPU_x86], [], [cpu type x86]) @@ -585,9 +586,19 @@ case $host in aarch64-*-linux*) AC_DEFINE([CPU_arm], [], [cpu type arm]) ;; - arm*-linux*) + arm-*-linux*) AC_DEFINE([CPU_arm], [], [cpu type arm]) ;; + ppc64le-*-linux*) + ;; + ppc64-*-linux*) + ;; + ppc-*-linux*) + ;; + s390-*-linux*) + ;; + s390x-*-linux*) + ;; esac AC_MSG_CHECKING([for GCC provided 64-bit atomic bool cas function ...]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], @@ -740,9 +751,9 @@ m4_include(m4/pcre.m4) m4_include(m4/selinux.m4) m4_include(m4/systemd.m4) m4_include(m4/cmocka.m4) -m4_include(m4/tcmalloc.m4) m4_include(m4/doxygen.m4) m4_include(m4/event.m4) +m4_include(m4/tcmalloc.m4) PACKAGE_BASE_VERSION=`echo $PACKAGE_VERSION | awk -F\. '{print $1"."$2}'` AC_SUBST(PACKAGE_BASE_VERSION) @@ -807,7 +818,6 @@ AC_SUBST(localrundir) AC_SUBST(systemd_inc) AC_SUBST(systemd_lib) AC_SUBST(systemd_defs) -AC_SUBST(tcmalloc_link) AC_SUBST(brand) AC_SUBST(capbrand) diff --git a/m4/tcmalloc.m4 b/m4/tcmalloc.m4 index da9a722..4da8600 100644 --- a/m4/tcmalloc.m4 +++ b/m4/tcmalloc.m4 @@ -6,24 +6,44 @@ # See LICENSE for details. # END COPYRIGHT BLOCK -AC_CHECKING(for tcmalloc) +AC_CHECKING(for --enable-tcmalloc) -# check for --with-tcmalloc -AC_MSG_CHECKING(for --with-tcmalloc) -AC_ARG_WITH(tcmalloc, AS_HELP_STRING([--with-tcmalloc],[Use TCMalloc memory allocator.]), +AC_ARG_ENABLE(tcmalloc, AS_HELP_STRING([--enable-tcmalloc], [Enable tcmalloc based tests (default: no)]), [ - if test "$withval" = yes - then - AC_MSG_RESULT([using tcmalloc memory allocator]) - with_tcmalloc=yes - else - AC_MSG_RESULT(no) + AC_MSG_RESULT(yes) + AC_DEFINE([WITH_TCMALLOC], [1], [With tcmalloc]) + with_tcmalloc="yes" + + if test "$enable_asan" = "yes" ; then + AC_MSG_ERROR([CRITICAL: You may not enable ASAN and TCMALLOC simultaneously]) fi + + case $host in + s390-*-linux*) + AC_MSG_ERROR([tcmalloc not support on s390]) + ;; + s390x-*-linux*) + AC_MSG_ERROR([tcmalloc not support on s390x]) + ;; + *) + AC_MSG_CHECKING(for tcmalloc) + if $PKG_CONFIG --exists libtcmalloc; then + tcmalloc_inc=`$PKG_CONFIG --cflags libtcmalloc` + tcmalloc_lib=`$PKG_CONFIG --libs libtcmalloc` + AC_MSG_RESULT([using system tcmalloc]) + else + AC_MSG_ERROR([pkg-config could not find tcmalloc!]) + fi + esac + ], -AC_MSG_RESULT(no)) +[ + AC_MSG_RESULT(no) + with_tcmalloc="0" +]) -if test "$with_tcmalloc" = yes; then - tcmalloc_link=-ltcmalloc -fi +AM_CONDITIONAL([WITH_TCMALLOC], [test "$with_tcmalloc" = "yes"]) +AC_SUBST(tcmalloc_inc) +AC_SUBST(tcmalloc_lib) diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in index ac69090..a76d00e 100644 --- a/rpm/389-ds-base.spec.in +++ b/rpm/389-ds-base.spec.in @@ -11,7 +11,6 @@ # also need the relprefix field for a pre-release e.g. .0 - also comment out for official release #% global relprefix 0. -%global use_tcmalloc 1 %global use_openldap 1 %global use_db4 0 # If perl-Socket-2.000 or newer is available, set 0 to use_Socket6. @@ -23,7 +22,14 @@ # This enables an ASAN build. This should not go to production, so we rename. %global use_asan __ASAN_ON__ %if %{use_asan} +%global use_tcmalloc 0 %global variant base-asan +%else +%if %{_arch} != "s390x" && %{_arch} != "s390" +%global use_tcmalloc 1 +%else +%global use_tcmalloc 0 +%endif %endif # fedora 15 and later uses tmpfiles.d -- 1.8.3.1