gperftools: [macOS+macports+cmake] tcmalloc does not link on aarch64: `Undefined symbols: _tc_delete_aligned` etc.

Something was broken after 2.10 here:

[ 82%] Linking CXX shared library libtcmalloc.dylib
/opt/local/bin/cmake -E cmake_link_script CMakeFiles/tcmalloc.dir/link.txt --verbose=ON
/usr/bin/clang++ -pipe -Os -Wno-deprecated-declarations -Wno-error=unknown-warning-option -Wno-unknown-warning-option -DNDEBUG -I/opt/local/include -stdlib=libc++ -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -fsized-deallocation -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -mmacosx-version-min=14.0 -dynamiclib -Wl,-headerpad_max_install_names -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -compatibility_version 9.14.5 -current_version 9.14.5 -o libtcmalloc.9.14.5.dylib -install_name @rpath/libtcmalloc.9.14.5.dylib CMakeFiles/tcmalloc.dir/src/tcmalloc.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/common.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/internal_logging.cc.o "CMakeFiles/tcmalloc_internal_object.dir/src/system-alloc.cc.o" CMakeFiles/tcmalloc_internal_object.dir/src/memfs_malloc.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/safe_strerror.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/central_freelist.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/page_heap.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/sampler.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/span.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/stack_trace_table.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/static_vars.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/symbolize.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/thread_cache.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/malloc_hook.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/malloc_extension.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/base/low_level_alloc.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/mmap_hook.cc.o "CMakeFiles/tcmalloc_internal_object.dir/src/heap-profile-table.cc.o" "CMakeFiles/tcmalloc_internal_object.dir/src/heap-profiler.cc.o" CMakeFiles/tcmalloc_internal_object.dir/src/raw_printer.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/emergency_malloc.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/emergency_malloc_for_stacktrace.cc.o CMakeFiles/tcmalloc_internal_object.dir/src/memory_region_map.cc.o CMakeFiles/stacktrace_object.dir/src/stacktrace.cc.o CMakeFiles/stacktrace_object.dir/src/base/elf_mem_image.cc.o CMakeFiles/stacktrace_object.dir/src/base/vdso_support.cc.o  -Wl,-rpath,/opt/local/lib libspinlock.a libsysinfo.a liblogging.a 
ld: Undefined symbols:
  _tc_delete_aligned, referenced from:
      operator delete(void*, std::align_val_t) in tcmalloc.cc.o
  _tc_delete_aligned_nothrow, referenced from:
      operator delete(void*, std::align_val_t, std::nothrow_t const&) in tcmalloc.cc.o
  _tc_delete_sized_aligned, referenced from:
      operator delete(void*, unsigned long, std::align_val_t) in tcmalloc.cc.o
  _tc_deletearray_aligned, referenced from:
      operator delete[](void*, std::align_val_t) in tcmalloc.cc.o
  _tc_deletearray_aligned_nothrow, referenced from:
      operator delete[](void*, std::align_val_t, std::nothrow_t const&) in tcmalloc.cc.o
  _tc_deletearray_sized_aligned, referenced from:
      operator delete[](void*, unsigned long, std::align_val_t) in tcmalloc.cc.o
  _tc_new_aligned, referenced from:
      operator new(unsigned long, std::align_val_t) in tcmalloc.cc.o
  _tc_new_aligned_nothrow, referenced from:
      operator new(unsigned long, std::align_val_t, std::nothrow_t const&) in tcmalloc.cc.o
  _tc_newarray_aligned, referenced from:
      operator new[](unsigned long, std::align_val_t) in tcmalloc.cc.o
  _tc_newarray_aligned_nothrow, referenced from:
      operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) in tcmalloc.cc.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtcmalloc.9.14.5.dylib] Error 1

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

Ah btw if you intend to debug more of cmake stuff, here is malloc_bench patch that “fix” building with cmake on my osx test box:

diff --git a/benchmark/malloc_bench.cc b/benchmark/malloc_bench.cc
index 070e6e5..6f6bbdd 100644
--- a/benchmark/malloc_bench.cc
+++ b/benchmark/malloc_bench.cc
@@ -77,7 +77,7 @@ static void bench_fastpath_simple(long iterations,
   }
 }
 
-#ifdef __GNUC__
+#if defined(__GNUC__) && !defined(__APPLE__)
 #define HAVE_SIZED_FREE_OPTION
 
 extern "C" void tc_delete_sized(void *ptr, size_t size) __attribute__((weak));

I can simply merge it as is, but on the other hand, it would disable one feature even on autotools build where this at least compiles without trouble without patch. So perhaps we investigate some before doing more ifdefs mess.

I submitted your proposed changes. Thanks.

As for this specific ticket, I don’t promise much attention. This seems specific to osx+cmake and perhaps plus whatever ports stuff you use. On my osx test box cmake nearly builds (there is one odd thing about weak functions that affects malloc_bench only; and somehow only happens with whatever flags or something cmake build does on osex). So your failures, I’d strongly prefer you investigate more yourself. Can we somehow separate those failures from ports stuff ?

Also please be aware of https://github.com/gperftools/gperftools/issues/1462

And finally, I don’t approve that ports thingy choosing cmake build. We do have known issues there. And for example plenty of tests fail. If you can affect it somehow, please make it stop doing cmake stuff.

Or perhaps I should consider just amputating our “best but in practice not so good effort” cmake support?