Category Archives: LLVM


The Linux package lcov is a set of Perl scripts to convert gcov coverage information into nice looking HTML pages wherein the project’s coverage metrics are concisely visible. Fortunately, the Clang compiler is also capable to generate GCOV-compatible data such that lcov may be used with the LLVM tool chain. To get LLVM working together with lcov, the following steps have to be performed:

  1. Get the latest version of lcov, at least 1.12 from the project’s web page
  2. Follow the instructions here

Macro Definitions

When trying to analyze a compiler and/or build error involving macro definitions, e.g. the nasty feature test macros, it might be useful to find out where a macro has been defined and which value it takes. A straightforward approach could be to look at the compiler output after pre-processing, typically enforced by adding the -E option. Unfortunately, this output only shows the final pre-processed output where all the macros have already been expanded. Fortunately, there is an additional option in clang and gcc that prints both, the expanded macros as well as the location of the definition. To exemplify this, we take the following source program:

To finally get the pre-processed output containing the macro definitions, we have to add the -E and -dD arguments to the compile command. Since -E prints the pre-processed file to stdout, we have to redirect the output into a file, typically with the file extension .i:

The pre-processed file is then the following. Please note that the file also includes builtin macros, e.g. like __x86_64__, which are however truncated in the below output for clarity:

LLVM Setup

This short post is about small Python script that facilitates the setup of LLVM software builds. The documentation about how-to build LLVM by yourself is great and detailed in e.g. LLVM Getting Started, however there is one problem that I am usually confronted with once I want to build LLVM including all its components like clang, compiler-rt, libcxx, etc.: what is the exact download path for each component (either compressed archives or SVN/GIT) and more importantly which directory inside the LLVM source tree do I have to put the components’ files into?

I wrote a small and simple Python script, available on Github that takes care for you to setup the LLVM source tree containing the LLVM components that you would like to build. For usage details, please checkout the Github link, here is just a sample command sequence on how-to use the script: