Skip to content

[bp/1.35] compat/openssl: Ensure OpenSSL uses tcmalloc functions - #596

Open
tedjpoole wants to merge 1 commit into
envoyproxy:release/v1.35from
tedjpoole:fix-openssl-use-tcmalloc-1.35
Open

[bp/1.35] compat/openssl: Ensure OpenSSL uses tcmalloc functions#596
tedjpoole wants to merge 1 commit into
envoyproxy:release/v1.35from
tedjpoole:fix-openssl-use-tcmalloc-1.35

Conversation

@tedjpoole

Copy link
Copy Markdown
Contributor

When dynamically loading the OpenSSL shared libraries, we use the RTLD_DEEPBIND option so that the compatibility layer's wrapper symbols don't shadow the real OpenSSL ones. As an unintended consequence of this, it causes OpenSSL's calls to malloc/realloc/free to bind to glibc's allocator instead of the tcmalloc that is statically linked into Envoy.

The result is that OpenSSL operates on a completely separate heap, defeating tcmalloc's performance benefits on the TLS hot path and making all OpenSSL allocations invisible to tcmalloc heap profiling and memory dumps.

This is fixed by calling CRYPTO_set_mem_functions() immediately after loading libcrypto.so, thus redirecting OpenSSL's malloc/realloc/free calls to the main executable's tcmalloc functions.

Also added a test to verify that OpenSSL is using allocator functions that reside in the main executable (tcmalloc) rather than inside libcrypto.so (glibc via RTLD_DEEPBIND), preventing regressions.

Backport of envoyproxy/envoy#46562 & envoyproxy/envoy#46576

When dynamically loading the OpenSSL shared libraries, we use the
RTLD_DEEPBIND option so that the compatibility layer's wrapper symbols
don't shadow the real OpenSSL ones. As an unintended consequence of
this, it causes OpenSSL's calls to malloc/realloc/free to bind to
glibc's allocator instead of the tcmalloc that is statically linked into
Envoy.

The result is that OpenSSL operates on a completely separate heap,
defeating tcmalloc's performance benefits on the TLS hot path and making
all OpenSSL allocations invisible to tcmalloc heap profiling and memory
dumps.

This is fixed by calling CRYPTO_set_mem_functions() immediately after
loading libcrypto.so, thus redirecting OpenSSL's malloc/realloc/free
calls to the main executable's tcmalloc functions.

Also added a test to verify that OpenSSL is using allocator functions
that reside in the main executable (tcmalloc) rather than inside
`libcrypto.so` (glibc via `RTLD_DEEPBIND`), preventing regressions.

Backport of envoyproxy/envoy#46562 & envoyproxy/envoy#46576

Signed-off-by: Ted Poole <tpoole@redhat.com>
Signed-off-by: Jonh Wendell <jwendell@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@tedjpoole
tedjpoole requested a review from jwendell August 14, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant