我试图通过LD_PRELOAD设置malloc/free/calloc/realloc等与一些插入器.在我的小测试中,malloc即使free被检测到,也似乎只是插入(见输出).
我希望输出包含一行"NANO:free(x)" - 但这行不见了.
特定
// compile with: gcc test.cc
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
void* p = malloc(123);
printf("HOST p=%p\n", p);
free(p);
}
Run Code Online (Sandbox Code Playgroud)
和
// compile with: g++ -O2 -Wall -fPIC -ldl -o libnano.so -shared main.cc
#include <stdio.h>
#include <dlfcn.h>
typedef void *(*MallocFunc)(size_t size);
typedef void (*FreeFunc)(void*);
// Original functions
static MallocFunc real_malloc = NULL;
static FreeFunc real_free = NULL;
static void __nano_init(void) {
// Override original functions
real_malloc = …Run Code Online (Sandbox Code Playgroud)