diff --git a/examples/linux-kernel/README.md b/examples/linux-kernel/README.md index eaed465..e1e6522 100644 --- a/examples/linux-kernel/README.md +++ b/examples/linux-kernel/README.md @@ -1,10 +1,88 @@ # Building a recent Linux Kernel. +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 +the relatively simple task. We assume familiarity with Vagrant. + ## Vagrantfile +``` +# -*- 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 +``` + ## Bootstrapping +``` +#!/usr/bin/env bash + +sudo apt-get update + +sudo apt-get install -y emacs24 dbus-x11 +sudo apt-get install -y git subversion wget +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 + +sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-5.0 1000 +sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 1000 +sudo update-alternatives --install /usr/bin/llvm-dis++ llvm-dis /usr/bin/llvm-dis-5.0 1000 +sudo update-alternatives --install /usr/bin/llvm-dis llvm-dis /usr/bin/llvm-dis-5.0 1000 +sudo update-alternatives --install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-5.0 1000 +sudo update-alternatives --install /usr/bin/llvm-link llvm-link /usr/bin/llvm-link-5.0 1000 +sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-5.0 1000 + +cp /vagrant/bash_profile ~/.bash_profile + +echo ". /vagrant/bash_profile" >> /home/vagrant/.bashrc + +``` + ## Configuration stuff. +The file `tinyconfig64` is generated ... + ## The Build +The build process is carried out by running the `build_linux_gllvm.sh` +script. + +``` +#!/usr/bin/env bash + +export GOPATH=/vagrant/go + +mkdir -p ${GOPATH} +go get github.com/SRI-CSL/gllvm/cmd/... + +mkdir ${HOME}/linux_kernel +cd ${HOME}/linux_kernel +git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git + +cd linux-stable +git checkout tags/v4.14.34 +cp /vagrant/tinyconfig64 .config + +make CC=gclang HOSTCC=gclang + +get-bc -m -b built-in.o +get-bc -m vmlinux + +``` + diff --git a/examples/tutorial-ubuntu-16.04.md b/examples/tutorial-ubuntu-16.04.md new file mode 100644 index 0000000..451ec96 --- /dev/null +++ b/examples/tutorial-ubuntu-16.04.md @@ -0,0 +1,86 @@ +# Compiling Apache on Ubuntu + + +On a clean 16.04 server machine I will build apache. Desktop instructions should be no different. + +``` +>more /etc/lsb-release + +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=16.04 +DISTRIB_CODENAME=xenial +DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS" +``` + + +## Step 1. + +Install `gllvm`. + +``` +>export GOPATH=/vagrant/go + +>mkdir -p ${GOPATH} + +>go get github.com/SRI-CSL/gllvm/cmd/... + +>export PATH=${GOPATH}/bin:${PATH} +``` + +## Step 2. + +I am only going to build apache, not apr, so I first install the prerequisites. + +``` +>sudo apt-get install llvm libclang-dev clang libapr1-dev libaprutil1-dev libpcre3-dev make + +``` + +At this point, you could check your clang version with `which clang` and `ls -l /usr/bin/clang`. +It should be at least clang-3.8. + +## Step 3. + + Configure the gllvm tool to be relatively quiet: + +``` +>export WLLVM_OUTPUT_LEVEL=WARNING +>export WLLVM_OUTPUT_FILE=/vagrant/apache-build.log +``` + +## Step 4. + + Fetch apache, untar, configure, then build: + +``` + +>wget https://archive.apache.org/dist/httpd/httpd-2.4.33.tar.gz + +>tar xfz httpd-2.4.33.tar.gz + +>cd httpd-2.4.33 + +>CC=gllvm ./configure + +>make +``` + +## Step 5. + +Extract the bitcode. + +``` +>get-bc httpd + +>ls -la httpd.bc +-rw-r--r-- 1 vagrant vagrant 1119584 Aug 4 20:02 httpd.bc +``` + +## Step 6. + +Turn the bitcode into a second executable binary. (optional -- just for fun and sanity checking) + +``` +llc -filetype=obj httpd.bc +gcc httpd.o -lpthread -lapr-1 -laprutil-1 -lpcre -o httpd.new +``` diff --git a/examples/tutorial.md b/examples/tutorial.md new file mode 100644 index 0000000..938956f --- /dev/null +++ b/examples/tutorial.md @@ -0,0 +1,82 @@ +# Compiling Apache on Ubuntu + + +On a clean 14.04 machine I will build apache. + +``` +>pwd + +/vagrant + +>more /etc/lsb-release + +DISTRIB_ID=Ubuntu +DISTRIB_RELEASE=14.04 +DISTRIB_CODENAME=trusty +DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS" +``` + + +## Step 1. + + +Install `gllvm`. + +``` +>export GOPATH=/vagrant/go + +>mkdir -p ${GOPATH} + +>go get github.com/SRI-CSL/gllvm/cmd/... + +>export PATH=${GOPATH}/bin:${PATH} +``` + +## Step 2. + +I am only going to build apache, not apr, so I first install the prerequisites. + +``` +>sudo apt-get install llvm libclang-dev clang libapr1-dev libaprutil1-dev + +``` Note `gclang` is agnostic with respect to llvm versions +so feel free to install a more recent version if you +wish. However, if you are going to use dragonegg the llvm version is +tightly coupled to the gcc and plugin versions you are using. + + +## Step 3. + + Configure the gllvm tool to be relatively quiet: + +``` +>export WLLVM_OUTPUT_LEVEL=WARNING +>export WLLVM_OUTPUT_FILE=/vagrant/apache-build.log +``` + + +## Step 4. + + Fetch apache, untar, configure, then build: + +``` +>wget https://archive.apache.org/dist/httpd/httpd-2.4.33.tar.gz + +>tar xfz httpd-2.4.33.tar.gz + +>cd httpd-2.4.33 + +>CC=gclang ./configure + +>make +``` + +## Step 5. + +Extract the bitcode. + +``` +>get-bc httpd + +``` +