[LLVMdev] own source transformation

John Criswell criswell at illinois.edu
Tue Dec 7 09:51:41 PST 2010


On 12/7/10 10:16 AM, Vincent De Bruyne wrote:
> Hi,
>
> I'm a student who is going to make a countermeasure for dangling 
> pointers in c for his thesis.
> I need to make my source transformation using llvm. Nobody in my 
> university already used LLVM.
>
> I already read a some documentation about llvm but i'm still lost.
>
> Do there exist some " examples/Tutorials" for making small source 
> transformations.
> Or is there somebody who can help me a bit to get started.

The LLVM Programmer's Manual 
(http://llvm.org/docs/ProgrammersManual.html) and the Writing an LLVM 
Pass Guide (http://llvm.org/docs/WritingAnLLVMPass.html) are good 
documents on how to write transform and analysis passes that plug into 
the LLVM opt tool.

Some of the passes in the SAFECode compiler 
(http://safecode.cs.illinois.edu) are pretty simple and illustrate 
simple tasks like instrumenting loads and stores or modifying calls to 
functions.  If you check out the mainline code, you can look at 
lib/InsertPoolChecks/LoadStoreChecks.cpp, 
lib/InsertPoolChecks/insert.cpp, and 
lib/DebugInstrumentation/DebugInstrumentation.cpp for examples of 
relatively simple passes.

That said, LLVM is not really suitable for Source to Source 
transformations.  While LLVM can convert C code to LLVM IR and back to C 
code, it does not preserve comments, and the generated C code isn't 
really designed to be readable by humans.  I would normally recommend 
Clang for Source to Source transformations, but in your case, working 
with Clang's AST is probably more trouble than it's worth (from what I 
hear).  For dangling pointer detection, working on the LLVM IR is 
probably easier.

As an aside, I work on SAFECode which (among other memory safety 
guarantees) provides various protections for dangling pointer errors.  
It enforces the points-to graph at run-time (as described in Dinakar 
Dhurjati's PLDI 2006 paper) and includes a prototype implementation of 
Dhurjati's et. al. dangling pointer detection method  (DSN 2006).  You 
may want to take a look the CETS paper by Santosh Nagarakatte et. al. 
(ISMM 2010) and Dinakar Dhurjati's PLDI 2006 paper (for which I can 
provide an informal explanation if you don't like type-system proofs).

Links to these papers are at:
http://llvm.org/pubs/2006-DSN-DanglingPointers.html
http://www.cis.upenn.edu/~santoshn/ismm10-cets.pdf
http://llvm.org/pubs/2006-06-12-PLDI-SAFECode.html

SAFECode is publicly available at http://safecode.cs.illinois.edu.  CETS 
may be available from Santosh's website.

-- John T.

>
> Thx
> Vincent
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101207/73ae32e3/attachment.html>


More information about the llvm-dev mailing list