clingfei / bc-files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KSplit bc-files

This repository hosts all the LLVM bitcode files and scripts to run the static analysis on them.

The steps to run the analysis is documented under ksplit-artifacts repository.

We use LLVM v10.0.1 across the KSplit infrastructure (e.g., static analysis). However, the extraction of bc files from the kernel should work on any version of LLVM above v10.

Generate LLVM bitcode files for Linux kernel

  • Recent versions of the linux kernel natively supports compilation via LLVM toolchain. More details are available on the official documentation https://docs.kernel.org/kbuild/llvm.html.

    • Recent kernel versions will require LLVM v11.1.0.
  • For older version, you need a few patches and a modified makefile to enable compilation via clang. A patched version of the v4.8.4 kernel we use in the ksplit project is available at https://github.com/ksplit/lvd-linux/tree/llvm_v4.8.

Compile and extract bitcode files

  • Download any supported kernel.

  • Install whole-program-llvm from https://pypi.org/project/wllvm/

    • Make sure you have wllvm and extract-bc binaries in your PATH post installation
  • Compile the kernel with wllvm.

export LLVM_COMPILER=clang
make CC=wllvm HOSTCC=wllvm olddefconfig
make CC=wllvm HOSTCC=wllvm -j $(nproc)

This should compile everything with wllvm

  • To extract the bc file from an object file, you can use extract-bc tool from wllvm.
extract-bc vmlinux.o

If everything works as expected, the tool should extract the bitcode file into vmlinux.o.bc

Generate driver bc files

  • driver.bc files can be generated by invoking extract-bc as shown above.
extract-bc drivers/net/ethernet/intel/ixgbe/ixgbe.ko

This should generate drivers/net/ethernet/intel/ixgbe/ixgbe.ko.bc

Generate kernel.bc files

  • kernel.bc file is the counterpart of the driver.bc file. Typically drivers interact with certain subsystems of the kernel. For instance, a kernel driver for the network card attached to a PCI bus interacts with both the network and PCI subsystem in the kernel.

  • In this project, we make an approximation of the set of files the driver interacts with using the https://github.com/ksplit/ksplit-boundary application.

  • One can invoke the application with the following arguments

./parse <driver_bc.list> <kernel_bc.list> <liblcd_funcs.txt>
  • driver_bc.list contains the absolute path of a driver.bc file (one per line).
  • kernel_bc.list contains the absolute path of all the .bc files generated by the wllvm program during the compilation phase.
    find $(KERNEL_PATH) -name "*.o.bc" > kernel_bc.list
    
  • liblcd_funcs.txt contains the list of functions that are available inside the isolated domain as part of the compilation environment (e.g., memset, kstrdup etc).

The program extracts the needed kernel.o.bc files and merges them into a single driver_kernel.bc file.

About


Languages

Language:Shell 64.5%Language:Python 35.5%