有没有快速的方法来删除 glibc 中的 malloc/free/memalign/realloc 钩子?

Is there a fast way to remove malloc/free/memalign/realloc hooks in glibc?

我已经尝试修补我正在使用的 libc 以从不调用 malloc 挂钩。但是这个钩子实际上是用指向这个函数的指针初始化的:

malloc_hook_ini (size_t sz, const void *caller)
{
      __malloc_hook = NULL;
      ptmalloc_init ();
      return __libc_malloc (sz);
}

我认为这个函数负责malloc中的关键初始化,所以至少需要调用一次。例如,由于 free hook 没有用关键函数初始化,我可以只 nop 调用指令

DJ Delorie posted a patch 去除了挂钩。不过,它需要一些移植到当前树。

或者,您可以 interpose a different malloc 没有这样的钩子。如果这样做,glibc 将使用插入的 malloc,因此也永远不会调用挂钩。