rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.79k stars 314 forks source link

Missing flag when running custom LLVM pass #394

Closed deadly-platypus closed 3 years ago

deadly-platypus commented 3 years ago

Describe the bug When building with Clang, if you want to run a custom LLVM pass, -Xclang -load -Xclang path/to/LLVM/pass.so must be added to the Clang invocation. Bear seems to miss the -load flag when building the Linux kernel

To Reproduce Steps to reproduce the behavior:

  1. On Linux, build clang from source, or somehow get the Hello World LLVM pass, LLVMHello.so
  2. Clone the Linux repo
  3. make ARCH=arm64 CC=clang HOSTCC=clang CROSS_COMPILE=aarch64-linux-gnu- LLVM=1 O=build KBUILD_CFLAGS="-Xclang -load -Xclang /path/to/LLVMHello.so" defconfig
  4. bear -- make ARCH=arm64 CC=clang HOSTCC=clang CROSS_COMPILE=aarch64-linux-gnu- LLVM=1 O=build KBUILD_CFLAGS="-Xclang -load -Xclang /path/to/LLVMHello.so" -i

Expected behavior

  1. compile_commands.json contains build arguments -Xclang, -load, -Xclang, /path/to/LLVMHello.so

Actual behavior

  1. compile_commands.json contains build arguments -Xclang, -Xclang, /path/to/LLVMHello.so

Environment:

Additional context

rizsotto commented 3 years ago

Hey @deadly-platypus, I have a fix on devel branch for this problem. Could you try it out?

The fix cares about the -Xclang specifically, but if you are using any other Clang specific flag, that might be missing. Let me know if your build needs other flag support.

deadly-platypus commented 3 years ago

It works for what we need, thanks!

rizsotto commented 3 years ago

Closing it, the fix will be released as 3.0.14.