为什么 tcmalloc 不打印通过 dlopen 提供的函数名称

Why tcmalloc don't print function name, which provided via dlopen

本文关键字:函数 dlopen tcmalloc 打印 为什么      更新时间:2023-10-16

我有下一个项目:main.cpp

#include <iostream>
#include <cstddef>
#include <dlfcn.h>
int main()
{
    void* handle = dlopen("./shared_libs/libshared.so", RTLD_LAZY);
    if (NULL == handle)
    {
        std::cerr << "Cannot open library: " << dlerror() << 'n';
        return -1;
    }

    typedef int (*foo_t)(const std::size_t);
    foo_t foo = reinterpret_cast<foo_t>(dlsym(handle, "foo"));

    const char* dlsym_error = dlerror();
    if (dlsym_error)
    {
        std::cerr << "Cannot load symbol 'foo': " << dlsym_error << 'n';
        dlclose(handle);
        return -2;
    }

    std::cout << "call foo" << std::endl;
    foo(10);

    dlclose(handle);

    return 0;
}

shared.cpp:

#include <cstddef>
#include <iostream>

extern "C"
{
    int foo(const std::size_t size)
    {
        int b = size / size;
        int* a = new int[size];
        std::cout << "leaky code here" << std::endl;
    }
}

和Makefile:

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

我使用tcmalloc调试这个测试程序,它动态加载libshared.so:foo并执行它。run命令:LD_PRELOAD=/usr/local/lib/libtcmalloc.so HEAPCHECK=正常/a.out

最大的1次泄漏:

  • 使用本地文件/a.out
  • 从以下位置分配的1个对象中有40个字节泄漏:
  • @7fe3460bd9ba 0x00007fe3460bd9ba
  • @400b43主
  • @7月346c33日__图书馆_开始_分钟
  • @400999_启动
  • @0(_I)

为什么我在foo函数中得到地址0x00007fe3460bd9ba而不是行?请帮助

附言:我试着用gdb和LD_PRELOAD=/tcmalloc.so,但我得到:"有人正在ptrace()攻击我们;将自行关闭关闭perftools堆泄漏检查"

尝试删除dlclose调用。

堆检查器&分析程序无法处理卸载的共享对象。