[LLVMdev] llvm

John Criswell criswell at uiuc.edu
Wed Apr 7 07:50:56 PDT 2010

hui zhang wrote:
> i want to do something about llvm and valgrind.i have read some 
> # information about it in llvm.org <http://llvm.org>. Port Valgrind 
> <http://valgrind.org/> to use LLVM codegeneration and optimization 
> passes instead of its own.   is somebody working on it ? can you give 
> me some addvice? is there some project like it?    thank you  

A project similar to Valgrind's memcheck and ptrcheck tools is the 
SAFECode project (http://safecode.cs.illinois.edu).  SAFECode is a set 
of compiler passes that instrument code to detect memory errors such as 
buffer overflows, invalid loads and stores, violations of control-flow 
integrity, and (with an optional flag) dangling pointer dereferences.  
SAFECode uses static analysis to prove code safe and inserts run-time 
checks when the static analysis cannot prove safety.  While originally 
designed for production code, SAFECode now has a debugging mode where it 
attempts to print out the source file and line number of the instruction 
causing a memory error.

SAFECode currently works both with LLVM 2.6 and with LLVM 2.7 (although 
there are regressions which I am still fixing).

SAFECode's approach has several benefits over Valgrind in detecting 
memory safety errors:

1) It can use static analysis to optimize away run-checks.
2) It does not incur the binary translation overhead.
3) Being an LLVM compiler pass, LLVM knows which loads and stores are to 
memory objects and which are to stack spill slots.  Furthermore, 
SAFECode knows the boundaries of stack and global objects, giving it 
better accuracy than Valgrind's ptrcheck tool.

If you're interested in dynamic memory error detection tools, you may 
want to try out SAFECode.  Just keep in mind that SAFECode still has 
plenty of room for improvement.

-- John T.

More information about the llvm-dev mailing list