GDB

Debugging LLVM OPT

# Run gdb
gdb opt
# Set breakpoint
break llvm::Pass::preparePassManager
# Run pass
run -load ./mypass.so -hello < hello.bc > debug.log

Clang

Clang Get IR

clang -S -emit-llvm

Compiling CUDA with clang: official document, in short:

clang++ helloworld.cu -o helloworld --cuda-gpu-arch=<arch> \
  -L<CUDA install path>/<lib64 or lib>                     \
  -lcudart_static -ldl -lrt -pthread

Linker

GLIBCXX

Check if a string exists in the shared library

strings libstdc++.so.6 | grep GLIBCXX

Linker Arguments

  • The arguments could be passed to linker by clang -Wl,<comma seperated args>,for example, clang -Wl,-rpath,<a> -Wl,-rpath,<b>.
  • -rpath <path>: has the same effect as setting the LD_LIBRARY_PAH, but specifies it at link time.
  • -dynamic-linker: specifies the dynamic linker, see a good tutorial for dynamic linking

LLVM Tools

  • Emit machine code. Replace asm with obj to generate object file instead.
    echo 'define internal noundef i32 @myfunc() { ret i32 0 }' | llc -march=x86-64 -filetype=asm -