Skip to content
준화 edited this page Jun 28, 2021 · 2 revisions

Some helpful links

Build and Test LLVM

Testing and Debugging

You shall build up a test suite of several bitcode files by compiling test C programs with "-S -emit-llvm." You shall test your your pass by running opt on these bitcode files.

Use the lldb you built yourself to debug your pass, not gdb. Then you have get have this: http://homes.cs.washington.edu/~bholt/posts/llvm-debugging.html

You may use an lldbinit file to automate starting your process, setting breakpoints, etc.

Actual Information

If you disagree with me about whatever, make your own workflow but at least know you need "-fstandalone-debug" to get lldb to print LLVM stuff nicely.

Getting Things Done

You want to implement X in LLVM. You shall find a place in the LLVM source code that does something like X and use it as a guide to write your implementation of X.

Really Crazy Stuff

CMake can generate projects for Eclipse, KDevelop, Visual Studio, etc. You could try these things. Scott has. Scott always goes back to Vim.

Scott recommends YouCompleteMe for vim and using grep to search the LLVM code base when YouCompleteMe is not enough.

Great Artists Steal

You should look at these patches for guidelines on how to add new functionality:

FCFI Patch

SafeStack Clang Patch

SafeStack Compiler-rt Patch

SafeStack LLVM Patch

Command Line Options

You probably want a command line option so you can benchmark with and without your instrumentation.

You can do this: http://bholt.org/posts/llvm-commandline.html

The gotcha is if your pass is in LLVM (not clang) you need -mllvm before your option

For example:

clang -mllvm -dataconf test.c

Build Fast

The LLVM build takes a really long time. You should use -DBUILD_SHARED_LIBS at least. For more information on speeding up your build see:

http://blogs.s-osg.org/a-conclusion-to-accelerating-your-build-with-clang

http://blogs.s-osg.org/an-introduction-to-accelerating-your-build-with-clang/

These are some notes on using LLDB to debug you custom LLVM

LLDB

First you will need a version of LLDB that matches you LLVM (see scotts notes on building LLVM

Then run your build command with -v, this will printout the really long nasty command actually given to the linker

clang -v <your build options>

Get the long nasty command to the linker and run

lldb -- <long nasty command>

Find location of an assert

Use the up command until you get to a location you recognize

(lldb) up