In order to diagnose a tricky memory corruption bug (memory is getting randomly overwritten) I thought about utilizing Electric Fence + some custom mprotect calls to ensure that the corrupted data structures are only writable when I want them to be written to (and I immediately get a SIGSEGV when they are attempted to be written to).
Unfortunately, said code is a Ruby C Extension, which makes running it under libefence a performance nightmare as running the whole ruby interpreter under libefence using
export LD_PRELOAD=libefence.so.0.0
is horribly slow.
OTOH, linking the ruby extension with libefence directly (by passing -lefence to the linker) seems to have no effect causing it to run without libefence's instrumentation.
Is there a way to run only the memory allocations happening in a specific shared library through libefence and leaving other shared libs and the main process alone?