Using Electric Fence (libefence) for shared library only

To diagnose an error memory corruption error (memory gets accidentally overwritten), I thought about using Electric Fence + some mprotect user calls to ensure that damaged data structures are write-only when I want them to be written (and I get it right away SIGSEGV when they try to record them in).

Unfortunately, the above code is a Ruby C extension that forces it to run a performance nightmare under winfence since the entire ruby ​​interpreter runs under libefence using

export LD_PRELOAD=libefence.so.0.0

So slow.

OTOH, linking the ruby ​​extension to libefence directly (by passing -lefence to the linker) seems to have no effect, making it work without the libefence toolkit.

Is there a way to only run memory allocations that occur in a specific shared library through libefence and leaving other shared libraries and the main process?

+3
source share
1 answer

The easiest way is to link the Ruby C extension to the libefence static library. There may still be problems - what if something is malloc () in your extension but freed inside ruby?

SIGSEGV, - gdb. SIGSEGV, .

valgrind , .

+1

Source: https://habr.com/ru/post/1769437/


All Articles