linking abseil to tcmalloc

253 views
Skip to first unread message

Karan Aggarwal

unread,
Nov 16, 2021, 4:10:23 AM11/16/21
to Abseil.io
Hi
How to link abseil in tcmalloc.so?

Andy Getzendanner

unread,
Nov 18, 2021, 5:25:00 PM11/18/21
to Karan Aggarwal, Abseil.io
How are you building tcmalloc.so now, and what do you hope to achieve by linking abseil into it?

On Tue, Nov 16, 2021 at 4:10 AM Karan Aggarwal <karan.ag...@gmail.com> wrote:
Hi
How to link abseil in tcmalloc.so?

--
You received this message because you are subscribed to the Google Groups "Abseil.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to abseil-io+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/abseil-io/939ab619-1d3c-4d65-a771-174a3bfa4173n%40googlegroups.com.

Karan Aggarwal

unread,
Nov 19, 2021, 12:45:06 AM11/19/21
to Abseil.io
Hi Andy,

I am building the tcmalloc using bazel (https://github.com/google/tcmalloc.git). I was able to build tcmalloc.so with the help comments given in the following issues: (1) https://github.com/google/tcmalloc/issues/27, and (2) https://github.com/google/tcmalloc/issues/71

Then, I tried to use the libtcmalloc.so, by linking it to the binary, with the help of LD_PRELOAD. I got the following error when I executed the binary: 
symbol lookup error: /home/karan/allocator/binaries/libtcmalloc.so: undefined symbol: tcmalloc::tcmalloc_internal::Static::cpu_cache_active_

Many people have commented that tcmalloc is dependent on abseil so I wanted to check if abseil linking helps to solve this error.

Best regards

Andy Getzendanner

unread,
Nov 22, 2021, 4:08:29 PM11/22/21
to Karan Aggarwal, Abseil.io
I'm not a Bazel wizard, but IIUC that approach would work if you built a .so for every target in the transitive dependency chain and LD_PRELOADed them all.  Not ideal.

This seems to work for me:

diff --git a/tcmalloc/BUILD b/tcmalloc/BUILD
index 11d2f50..9ad458f 100644
--- a/tcmalloc/BUILD
+++ b/tcmalloc/BUILD
@@ -1391,3 +1391,10 @@ cc_test(
         "@com_google_protobuf//:protobuf",
     ],
 )
+
+cc_binary(
+    name = "tcmalloc.so",
+    deps = [":tcmalloc"],
+    linkshared = 1,
+    copts = TCMALLOC_DEFAULT_COPTS,
+)


$ bazel build //tcmalloc:tcmalloc.so
$ LD_PRELOAD=bazel-bin/tcmalloc/tcmalloc.so ls

Reply all
Reply to author
Forward
0 new messages