tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.3k stars 99 forks source link

undefined reference to `__malloc_hook' #92

Open PsiACE opened 2 years ago

PsiACE commented 2 years ago

run cargo test --all-features on a platform with glibc 2.34 (such as Fedora 35)

some error message

  = note: /usr/bin/ld: $HOME/pprof-rs/target/debug/deps/pprof-b3a0e5c36a90b5b6.3fe154bcu86215js.rcgu.o: in function `pprof::collector::malloc_free_test::malloc_hook':
          $HOME/pprof-rs/src/collector.rs:385: undefined reference to `__malloc_hook'
          /usr/bin/ld: $HOME/pprof-rs/src/collector.rs:394: undefined reference to `__malloc_hook'
          /usr/bin/ld: $HOME/pprof-rs/target/debug/deps/pprof-b3a0e5c36a90b5b6.3fe154bcu86215js.rcgu.o: in function `pprof::collector::malloc_free_test::malloc_free':
          $HOME/pprof-rs/src/collector.rs:406: undefined reference to `__malloc_hook'
          /usr/bin/ld: $HOME/pprof-rs/src/collector.rs:415: undefined reference to `__malloc_hook'
          /usr/bin/ld: $HOME/pprof-rs/target/debug/deps/pprof-b3a0e5c36a90b5b6.51fjuio59woik1f1.rcgu.o: in function `pprof::profiler::tests::malloc_hook':
          $HOME/pprof-rs/src/profiler.rs:377: undefined reference to `__malloc_hook'
          /usr/bin/ld: $HOME/pprof-rs/target/debug/deps/pprof-b3a0e5c36a90b5b6.51fjuio59woik1f1.rcgu.o:$HOME/pprof-rs/src/profiler.rs:386: more undefined references to `__malloc_hook' follow
          collect2: error: ld returned 1 exit status

tips

* The deprecated memory allocation hooks __malloc_hook, __realloc_hook,
  __memalign_hook and __free_hook are now removed from the API.  Compatibility
  symbols are present to support legacy programs but new applications can no
  longer link to these symbols.  These hooks no longer have any effect on glibc
  functionality.  The malloc debugging DSO libc_malloc_debug.so currently
  supports hooks and can be preloaded to get this functionality back for older
  programs.  However this is a transitional measure and may be removed in a
  future release of the GNU C Library.  Users may port away from these hooks by
  writing and preloading their own malloc interposition library.
YangKeao commented 2 years ago

I have developed a tool (https://github.com/YangKeao/plthook) to inject PLT Hook into the running process (https://github.com/YangKeao/plthook/blob/master/examples/parse_sym.rs here is the demo), which could be an alternative to the original __malloc_hook. Though it is still a toy project, I will make it ready for production ASAP.

Or do you have any ideas on other options to check whether malloc is used in the test?

Xuanwo commented 2 years ago

Should be fixed by #140 (at least it works)