简体   繁体   English

当我使用共享库编译并运行该程序时,为什么tcmalloc失败?

[英]Why does tcmalloc fail when I compile and run this program with a shared library?

Code simular to code here: Why tcmalloc don't print function name, which provided via dlopen 与此处的代码类似的代码: 为什么tcmalloc不打印通过dlopen提供的函数名

makefile: 生成文件:

  • all: 所有:
  • g++ -fPIC -g -c shared.cpp -ltcmalloc g ++ -fPIC -g -c shared.cpp -ltcmalloc
  • g++ -shared -o shared_libs/libshared.so -g shared.o -ltcmalloc g ++ -shared -o shared_libs / libshared.so -g shared.o -ltcmalloc
  • g++ -L shared_libs/ -g main.cpp -ldl -ltcmalloc g ++ -L shared_libs / -g main.cpp -ldl -ltcmalloc

When I execute my program: 当我执行程序时:

$ HEAPCHECK=normal ./a.out
No live heap object at 0x2582aa0 to ignore
Check failed: heap_profile->FindAlloc(test_str, &size): our own new/delete not linked?
Aborted (core dumped)

gdb with core file says: 具有核心文件的gdb表示:

Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007f51bfef6cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'

It looks like your code that doesn't call malloc/new from main.cpp is causing linked not to link libtcmalloc.so to ./a.out. 看来您的代码没有从main.cpp调用malloc / new导致链接不将libtcmalloc.so链接到./a.out。 Ie you can see it by doing ldd ./a.out. 也就是说,您可以通过执行ldd ./a.out来查看它。 It is not how it's supposed to work. 它不是应该如何工作的。

As a result of this tcmalloc is loaded together with your shared object which is too late and not supported. 结果,tcmalloc与共享对象一起加载,这太晚了,不被支持。

You can work around this "initiative" (which is as usual, clearly, result of good intentions) by adding -Wl,--no-as-needed before -ltcmalloc when you build your main executable. 您可以通过在构建主可执行文件时在-ltcmalloc之前添加-Wl(不需要),来解决此“启动”问题(通常,这显然是出于良好意愿)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM