Skip to content

Commit 34efe40

Browse files
authored
Vendor TCMalloc rather than using OS package with libunwind conflicts (#5113)
This replaces the debian package dependency on tcmalloc with a submodule. It doesn't seem especially invasive, so I think it might be a plausible solution to the problems we're having with conflicting libunwind dependencies in the OS package.
2 parents 2b2d603 + aeba4bb commit 34efe40

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@
4949
[submodule "src/rust/soroban/p26"]
5050
path = src/rust/soroban/p26
5151
url = https://github.com/stellar/rs-soroban-env.git
52+
[submodule "lib/gperftools"]
53+
path = lib/gperftools
54+
url = https://github.com/gperftools/gperftools.git

INSTALL.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ To install Postgresql, follow instructions from the [Postgresql download page](h
6666
- 64-bit system
6767
- `clang-format-20` (for `make format` to work)
6868
- `sed` and `perl`
69-
- `libgoogle-perftools-dev` (Linux only, for tcmalloc memory allocator)
7069
- Rust toolchain (see [Installing Rust](#installing-rust) subsection)
7170
- `cargo` >= 1.74
7271
- `rust` >= 1.74
@@ -118,7 +117,7 @@ sudo apt install gcc-14 g++-14
118117
```zsh
119118
# common packages
120119
sudo apt-get update
121-
sudo apt-get install git build-essential pkg-config autoconf automake libtool bison flex libpq-dev libgoogle-perftools-dev parallel sed perl
120+
sudo apt-get install git build-essential pkg-config autoconf automake libtool bison flex libpq-dev parallel sed perl
122121
# if using clang
123122
sudo apt-get -y install clang-20 llvm-20
124123
# clang with libc++

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
AM_CPPFLAGS = -isystem "$(top_srcdir)" -I"$(top_srcdir)/src" -I"$(top_builddir)/src"
44
AM_CPPFLAGS += $(libsodium_CFLAGS) $(xdrpp_CFLAGS) $(libmedida_CFLAGS) \
5-
$(soci_CFLAGS) $(sqlite3_CFLAGS) $(libasio_CFLAGS)
5+
$(soci_CFLAGS) $(sqlite3_CFLAGS) $(libasio_CFLAGS) $(libtcmalloc_CFLAGS)
66
AM_CPPFLAGS += -isystem "$(top_srcdir)/lib" \
77
-isystem "$(top_srcdir)/lib/autocheck/include" \
88
-isystem "$(top_srcdir)/lib/cereal/include" \

configure.ac

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,19 +343,22 @@ AM_CONDITIONAL(USE_POSTGRES, [test -n "$have_postgres"])
343343

344344
# tcmalloc_minimal - enabled by default on Linux for improved memory allocation performance
345345
# Disabled when using sanitizers (asan, memcheck, tsan) as they replace malloc
346+
# Uses vendored gperftools from lib/gperftools
346347
unset have_tcmalloc
347348
if test "x$enable_asan" = "xyes" -o "x$enable_memcheck" = "xyes" -o "x$enable_threadsanitizer" = "xyes"; then
348349
AC_MSG_NOTICE([tcmalloc disabled due to sanitizer being enabled])
349350
else
350351
case "${host_os}" in
351352
linux*)
352-
PKG_CHECK_MODULES(libtcmalloc, [libtcmalloc_minimal >= 2.0], [
353-
have_tcmalloc=1
354-
AC_DEFINE([USE_TCMALLOC], [1], [Define to 1 if using tcmalloc])
355-
AC_MSG_NOTICE([tcmalloc_minimal found and will be used])
356-
], [
357-
AC_MSG_ERROR([tcmalloc_minimal not found. Install libgoogle-perftools-dev])
358-
])
353+
# Configure gperftools for minimal tcmalloc only
354+
ac_configure_args="$ac_configure_args --enable-minimal --disable-cpu-profiler --disable-heap-profiler --disable-heap-checker --disable-debugalloc"
355+
AC_CONFIG_SUBDIRS([lib/gperftools])
356+
have_tcmalloc=1
357+
AC_DEFINE([USE_TCMALLOC], [1], [Define to 1 if using tcmalloc])
358+
# Use static library with early link order for malloc replacement
359+
libtcmalloc_LIBS='$(top_builddir)/lib/gperftools/.libs/libtcmalloc_minimal.a -lpthread'
360+
libtcmalloc_CFLAGS='-isystem $(top_srcdir)/lib/gperftools/src'
361+
AC_MSG_NOTICE([Using vendored tcmalloc_minimal from lib/gperftools])
359362
;;
360363
*)
361364
AC_MSG_NOTICE([tcmalloc is only used on Linux, skipping])

docker/Dockerfile.testing

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive
44
RUN apt-get update && \
55
apt-get -y install iproute2 procps lsb-release \
66
git build-essential pkg-config autoconf automake libtool \
7-
bison flex sed perl libpq-dev parallel libgoogle-perftools-dev \
7+
bison flex sed perl libpq-dev parallel \
88
clang-20 libc++abi-20-dev libc++-20-dev libclang-rt-20-dev \
99
postgresql curl
1010

lib/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Process this file with automake to produce Makefile.in
22

33
SUBDIRS = $(PKGCONFIG_SUBDIRS)
4+
if USE_TCMALLOC
5+
SUBDIRS += gperftools
6+
endif
47

58
include $(top_srcdir)/common.mk
69

lib/gperftools

Submodule gperftools added at 6ed7350

src/Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh
7272
$(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-curr >$@
7373
endif
7474

75-
stellar_core_LDADD = $(soci_LIBS) $(libmedida_LIBS) \
75+
# tcmalloc must be linked early to properly override malloc/free
76+
stellar_core_LDADD = $(libtcmalloc_LIBS) $(soci_LIBS) $(libmedida_LIBS) \
7677
$(top_builddir)/lib/lib3rdparty.a $(sqlite3_LIBS) \
77-
$(libpq_LIBS) $(xdrpp_LIBS) $(libsodium_LIBS) \
78-
$(libtcmalloc_LIBS)
78+
$(libpq_LIBS) $(xdrpp_LIBS) $(libsodium_LIBS)
7979

8080
TESTDATA_DIR = testdata
8181
TEST_FILES = $(TESTDATA_DIR)/stellar-core_example.cfg $(TESTDATA_DIR)/stellar-core_standalone.cfg \

0 commit comments

Comments
 (0)