Code Monkey home page Code Monkey logo

clang-kernel-build's Introduction

clang-kernel-build

Steps to build the Linux kernel using Clang

  1. Start with an empty dir

    git clone https://github.com/ramosian-glider/clang-kernel-build.git
    cd clang-kernel-build
    export WORLD=`pwd`
    
  2. Install Clang from Chromium:

    cd $WORLD
    # Instruction taken from http://llvm.org/docs/LibFuzzer.html
    mkdir TMP_CLANG
    cd TMP_CLANG
    git clone https://chromium.googlesource.com/chromium/src/tools/clang
    cd ..
    TMP_CLANG/clang/scripts/update.py
    

(To update Clang later on, do (cd TMP_CLANG/clang ; git pull) and run update.py again.)

  1. Clone the Linux source tree

    cd $WORLD
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
    cd linux-stable
    git reset --hard v4.14-rc2
    
  2. Configure and build the kernel

    cd $WORLD
    export CLANG_PATH=`pwd`/third_party/llvm-build/Release+Asserts/bin/
    cd linux-stable
    make CC=$CLANG_PATH/clang defconfig
    make CC=$CLANG_PATH/clang -j64 2>&1 | tee build.log
    
  3. Set up the VM:

    cd $WORLD
    wget https://raw.githubusercontent.com/google/sanitizers/master/address-sanitizer/kernel_buildbot/create_os_image.sh
    # create_os_image.sh requires sudo
    sh create_os_image.sh
    
  4. Run the VM

    cd $WORLD
    ./run_qemu.sh
    # in a separate console:
    ssh -i ssh/id_rsa -p 10023 root@localhost
    

Known problems

  1. The kernel doesn't boot if configured with CONFIG_PARAVIRT (e.g. make kvmconfig)

Debugging

```
# Start the VM before running GDB
cd $WORLD
gdb -x gdb.script
(gdb) br dump_stack
```

Hacking

```
# Perform these steps instead of Step 4 above.
cd $WORLD/linux-stable
make CC=$CLANG_PATH/clang defconfig
make CC=`pwd`/../clang_wrapper.py 2>&1 | tee build.log
```

The handy clang_wrapper.py lets you add arguments to Clang invocation, measure compilation times or fall back to GCC for certain files.

Also, get yourself a log symbolizer: https://raw.githubusercontent.com/google/sanitizers/master/address-sanitizer/tools/kasan_symbolize.py

clang-kernel-build's People

Contributors

ramosian-glider avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.