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