mephi42 / memtrace

Valgrind tool for tracing memory accesses
12 stars 2 forks source link

tracer: save non-instrumented vex #12

Open mephi42 opened 4 years ago

mephi42 commented 4 years ago

... analyzer should then parse and dump it

Does this have to be vex though? llvm might be better and here are several reasons why:

Converting vex to llvm should be doable - this worked with tcg after all.

One problem is that it has to be done within the valgrind tool, which runs without libc, let alone libstdc++. A good starting point would be to make a static llvm build, try to link it with the tool and see what symbols are missing.

mephi42 commented 3 years ago

PoC:

cd llvm/build
cmake -GNinja -DCMAKE_CXX_FLAGS=-fno-stack-protector ..
ninja lib/IR/all
g++ -I../include -I. -fPIC -shared -otest.so test.cpp -nostdlib -z defs -lLLVMCore -lLLVMSupport -Llib

#include "llvm-c/Core.h"

extern "C"
void
__assert_fail (const char *assertion, const char *file, unsigned int line,
               const char *function) {}

extern "C" void* malloc(size_t) { return NULL; }
extern "C" void free(void*) {}

void* operator new(size_t) { return NULL; }
void operator delete(void*, size_t) {}
void operator delete[](void*, size_t) {}

extern "C" int memcmp(const void*, const void*, size_t) { return 0; }
extern "C" char* strdup(const char*) { return NULL; }
extern "C" void* memcpy(void*, const void*, size_t) { return NULL; };

void foo(void) { (void)LLVMInt32Type(); }

Still need to build libcxx for std::string.