Skip to content

Instantly share code, notes, and snippets.

@deanberris
Created December 14, 2017 03:36
Show Gist options
  • Save deanberris/8827a3664717a6800b682e46ff9ffdaa to your computer and use it in GitHub Desktop.
Save deanberris/8827a3664717a6800b682e46ff9ffdaa to your computer and use it in GitHub Desktop.
Building an XRay instrumented clang binary
set -x
# Step 1: Build a clang using the system compiler that can build with XRay instrumentation.
mkdir llvm-build
cd llvm-build
cmake -GNinja \
-DLLVM_ENABLE_PROJECTS="clang:compiler-rt" \
-DCMAKE_BUILD_TYPE=Release ../llvm-project/llvm
ninja clang # Probably get a beverage and/or watch some videos
# Step 2: Build clang again, this time with the just-built clang with XRay support
cd ../
mkdir llvm-instrumented-build
cd llvm-instrumented-build
cmake -GNinja \
-DLLVM_ENABLE_PROJECTS="clang" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER=../llvm-build/bin/clang++ \
-DCMAKE_C_COMPILER=../llvm-build/bin/clang \
-DCMAKE_CXX_FLAGS="-fxray-instrument" \
-DCMAKE_CXX_FLAGS_RELEASE="-fxray-instrument" \
../llvm-project
ninja clang # Probably get a beverage and/or watch some videos
# Step 3: Use the newly built clang with XRay enabled
XRAY_OPTIONS="patch_premain=true xray_mode=basic verbosity=1" ./bin/clang++ -o hello hello.cc -O3
# Step 4: You should now see a couple of XRay log files... profit?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment