2018-04-30 19:42:25 +02:00
|
|
|
# Building a recent Linux Kernel.
|
|
|
|
|
2018-04-30 22:31:21 +02:00
|
|
|
In this directory we include all the necessary files needed to
|
|
|
|
build the kernel in a Ubuntu 16.04 vagrant box. We will guide the reader through
|
2018-05-02 22:07:16 +02:00
|
|
|
the relatively simple task. We assume familiarity with [Vagrant.](https://www.vagrantup.com/)
|
2018-04-30 22:31:21 +02:00
|
|
|
|
2018-04-30 19:42:25 +02:00
|
|
|
## Vagrantfile
|
|
|
|
|
2018-04-30 22:47:38 +02:00
|
|
|
```ruby
|
2018-04-30 22:31:21 +02:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
|
|
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
|
|
|
config.vm.box = "ubuntu/xenial64"
|
|
|
|
config.vm.provision :shell, path: "bootstrap.sh"
|
|
|
|
|
|
|
|
config.vm.provider "virtualbox" do |vb|
|
|
|
|
vb.memory = "4096"
|
|
|
|
vb.customize ["modifyvm", :id, "--ioapic", "on"]
|
|
|
|
vb.customize ["modifyvm", :id, "--memory", "4096"]
|
|
|
|
vb.customize ["modifyvm", :id, "--cpus", "4"]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2018-04-30 19:42:25 +02:00
|
|
|
## Bootstrapping
|
|
|
|
|
2018-04-30 22:47:38 +02:00
|
|
|
```bash
|
2018-04-30 22:31:21 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
# vagrant bootstrapping file
|
|
|
|
|
2018-04-30 22:31:21 +02:00
|
|
|
sudo apt-get update
|
|
|
|
|
|
|
|
sudo apt-get install -y emacs24 dbus-x11
|
2018-05-04 00:37:35 +02:00
|
|
|
sudo apt-get install -y git
|
2018-04-30 22:31:21 +02:00
|
|
|
sudo apt-get install -y llvm-5.0 libclang-5.0-dev clang-5.0
|
|
|
|
sudo apt-get install -y python-pip golang-go
|
|
|
|
sudo apt-get install -y flex bison bc libncurses5-dev
|
|
|
|
sudo apt-get install -y libelf-dev libssl-dev
|
|
|
|
|
|
|
|
echo ". /vagrant/bash_profile" >> /home/vagrant/.bashrc
|
|
|
|
```
|
|
|
|
|
2018-05-01 01:43:08 +02:00
|
|
|
## Shell Settings
|
|
|
|
|
|
|
|
```bash
|
2018-05-07 18:41:38 +02:00
|
|
|
#### /vagrant/bash_profile
|
|
|
|
|
2018-05-01 01:43:08 +02:00
|
|
|
#### llvm
|
|
|
|
export LLVM_HOME=/usr/lib/llvm-5.0
|
|
|
|
export GOPATH=/vagrant/go
|
|
|
|
|
|
|
|
######## gllvm/wllvm configuration #############
|
|
|
|
|
|
|
|
export LLVM_COMPILER=clang
|
|
|
|
export WLLVM_OUTPUT_LEVEL=WARNING
|
|
|
|
export WLLVM_OUTPUT_FILE=/vagrant/wrapper.log
|
2018-05-04 00:37:35 +02:00
|
|
|
export PATH=${GOPATH}/bin:${LLVM_HOME}/bin:${PATH}
|
2018-05-01 01:43:08 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-30 19:42:25 +02:00
|
|
|
## Configuration stuff.
|
|
|
|
|
2018-05-07 18:56:48 +02:00
|
|
|
The file [`tinyconfig64`](https://github.com/SRI-CSL/gllvm/blob/master/examples/linux-kernel/tinyconfig64) is generated
|
2018-05-07 18:58:38 +02:00
|
|
|
by `make tinyconfig` and then using `make menuconfig` to specialize the build to 64 bits.
|
2018-04-30 22:31:21 +02:00
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
## The Tarball Build with gllvm
|
2018-04-30 19:42:25 +02:00
|
|
|
|
2018-04-30 22:31:21 +02:00
|
|
|
The build process is carried out by running the `build_linux_gllvm.sh`
|
|
|
|
script.
|
|
|
|
|
2018-04-30 22:47:38 +02:00
|
|
|
```bash
|
2018-04-30 22:31:21 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
### building from a tarball with gllvm
|
|
|
|
|
2018-04-30 22:31:21 +02:00
|
|
|
go get github.com/SRI-CSL/gllvm/cmd/...
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
cd ${HOME}
|
|
|
|
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.39.tar.xz
|
|
|
|
tar xvf linux-4.14.39.tar.xz
|
|
|
|
cd linux-4.14.39
|
2018-04-30 22:31:21 +02:00
|
|
|
|
|
|
|
cp /vagrant/tinyconfig64 .config
|
|
|
|
|
|
|
|
make CC=gclang HOSTCC=gclang
|
|
|
|
|
|
|
|
get-bc -m -b built-in.o
|
|
|
|
get-bc -m vmlinux
|
2018-05-04 00:37:35 +02:00
|
|
|
```
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
## The Tarball Build with wllvm
|
2018-05-04 00:37:35 +02:00
|
|
|
|
|
|
|
The build process is carried out by running the `build_linux_wllvm.sh`
|
|
|
|
script.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
### building from a tarball with wllvm
|
|
|
|
|
2018-05-04 00:37:35 +02:00
|
|
|
sudo pip install wllvm
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
cd ${HOME}
|
|
|
|
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.39.tar.xz
|
|
|
|
tar xvf linux-4.14.39.tar.xz
|
|
|
|
cd linux-4.14.39
|
2018-05-04 00:37:35 +02:00
|
|
|
|
|
|
|
cp /vagrant/tinyconfig64 .config
|
|
|
|
|
|
|
|
|
|
|
|
make CC=wllvm HOSTCC=wllvm
|
2018-04-30 22:31:21 +02:00
|
|
|
|
2018-05-04 00:37:35 +02:00
|
|
|
extract-bc -m -b built-in.o
|
|
|
|
extract-bc -m vmlinux
|
2018-04-30 22:31:21 +02:00
|
|
|
```
|
|
|
|
|
2018-05-07 18:41:38 +02:00
|
|
|
## Building from a git clone
|
|
|
|
|
|
|
|
You can also build from a [git clone using gllvm,](https://github.com/SRI-CSL/gllvm/blob/master/examples/linux-kernel/build_linux_gllvm_git.sh)
|
|
|
|
or build from a [git clone using wllvm.](https://github.com/SRI-CSL/gllvm/blob/master/examples/linux-kernel/build_linux_wllvm_git.sh)
|
|
|
|
Though using a tarball is faster, and seemingly more reliable.
|
|
|
|
|