Skip to content

Commit

Permalink
Ticket 49141 - Enable tcmalloc
Browse files Browse the repository at this point in the history
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: vashirov (Thanks!)
  • Loading branch information
Firstyear committed Feb 28, 2017
1 parent 4c1a5c7 commit f9351cf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
11 changes: 7 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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@
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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).
Expand Down
16 changes: 13 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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([[]],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 34 additions & 14 deletions m4/tcmalloc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)


8 changes: 7 additions & 1 deletion rpm/389-ds-base.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit f9351cf

Please sign in to comment.