项目作者: Machiry

项目描述 :
Tool to get kernel driver bitcode files.
高级语言: Python
项目地址: git://github.com/Machiry/clakerbu.git
创建时间: 2019-01-18T04:18:42Z
项目社区:https://github.com/Machiry/clakerbu

开源协议:BSD 2-Clause "Simplified" License

下载


clakerbu

License

Tool to get cumulative LLVM bitcode files for kernel drivers for architectures arm32 and aarch64.

This tool helps you get cumulative bitcode files for each of the kernel drivers. This is helpful for any instrumentation tasks based on LLVM. For instance, You can use this tool to build the bitcode file for a driver, perform instrumentation, convert it back to object file, and then use the make to create the kernel with the instrumented driver.

Note

For the kernels built using gcc this tool only works for arm32 or aarch64 architectures.

Dependencies

How to use:

Build your kernel.

Run make using the following command:

  1. bear make

The above command will create compile_commands.json in the current directory.

Running

  1. usage: clakerbu.py [-h] -l LLVM_BC_OUT -k KERNEL_SRC_DIR -m COMPILE_JSON -n
  2. ARCH_NUM [-isclang] [-clangp CLANG_PATH]
  3. [-llvmlinkp LLVMLINK_PATH]
  4. optional arguments:
  5. -h, --help show this help message and exit
  6. -l LLVM_BC_OUT Destination directory where all the generated bitcode
  7. files should be stored.
  8. -k KERNEL_SRC_DIR Base directory of the kernel sources.
  9. -m COMPILE_JSON Path to the json file generated by Bear.
  10. -n ARCH_NUM Destination architecture, 32 bit (1) or 64 bit (2).
  11. -isclang flag to indicate that clang was used to built the
  12. kernel
  13. -clangp CLANG_PATH Absolute path to the clang binary (if not provided,
  14. the one available in the path will be used)
  15. -llvmlinkp LLVMLINK_PATH
  16. Absolute path to the llvm-link binary (if not
  17. provided, the one available in the path will be used)

Example for aarch64 (if built using gcc):

  1. cd clakerbu/
  2. python clakerbu.py -l /llvm_bitcode_out -k <PATH_WHERE_YOU_RAN_MAKE> -m <PATH_TO_THE_COMPILE_COMMANDS_JSON_CREATED_ABOVE> -n 2

If your kernel was originally built with clang+llvm, then you should specify the flag -isclang, path to the clang that was used to build the kernel (this is usually what you would have provided for REAL_CC) and path to the llvm-link.

Example for aarch64 (if built using clang):

  1. cd clakerbu/
  2. python clakerbu.py -l /llvm_bitcode_out -k <PATH_WHERE_YOU_RAN_MAKE> -m <PATH_TO_THE_COMPILE_COMMANDS_JSON_CREATED_ABOVE> -n 2 -isclang -clangp <PATH_TO_CLANG_THAT_WAS_USED_TO_BUILT_THE_KERNEL> -llvmlinkp <PATH_TO_THE_LLVM_LINK (usually in the same folder as the clang)>

The driver bitcode files will be present in the folder <LLVM_BC_OUT> with extension final.linked.bc along with other intermediate files.

The kernel modules end with ..final.linked.bc i.e., if you find iproc-rng200..final.linked.bc, that means it is the bitcode file for iproc-rng200.ko from the kernel build.

Shoutouts