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.
So you want to rewrite C source code in ways that try to prevent this?
You may want to look into the clang rewriter instead. LLVM has a
poorly maintained C backend (hopefully it will be better soon), but it
isn't really set up for high-level transformations.
Look into the ObjC rewriter for an example.
The LLVM Programmer’s Manual () and the Writing an LLVM Pass Guide () 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 () 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: SAFECode is publicly available at . CETS may be available from Santosh’s website. – John T.