Last active
September 22, 2016 18:22
-
-
Save quend/c8d42ca4464cda9cc3c6ca897049adb5 to your computer and use it in GitHub Desktop.
Script to compile the OpenSSL project to LLVM Bitcode on a Linux system.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#!/usr/bin/env bash | |
# Run this script in the main directory of openssl. | |
# Requires python3 | |
set -e | |
# download necessary parsing script | |
wget https://gist.githubusercontent.com/quend/e44520133e2cd8a6da98ce1c2a02a7b1/raw/8c93794dc2dc6cdd84255eb2de8416b59cf53a9b/comp_db_generate.py | |
# Install Bear | |
onerr() { | |
echo "Errored" | |
} | |
trap onerr ERR | |
# First, install bear | |
mkdir -p bear/build | |
wget -O Bear-2.2.0.tar.gz https://github.com/rizsotto/Bear/archive/2.2.0.tar.gz | |
tar xfz Bear-2.2.0.tar.gz --strip-components=1 -C bear | |
pushd bear/build | |
cmake .. | |
make | |
sudo make install | |
popd | |
echo "[+] Bear Installed" | |
# Install updated llvm | |
BUILD_DIR=$(dirname $0)/build | |
LLVM_DIR=llvm | |
ARCH=$(uname -m) | |
LLVM_VER=3.8.0 | |
case $(uname -s) in | |
Darwin) | |
OS=apple-darwin | |
FILE=clang+llvm-${LLVM_VER}-${ARCH}-${OS}.tar.xz | |
;; | |
Linux) | |
OS=linux-gnu | |
DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]') | |
DIST_VERSION=$(lsb_release -sr) | |
if [ $DIST_VERSION == "15.04" ]; then | |
DIST_VERSION="14.04" | |
fi | |
FILE=clang+llvm-${LLVM_VER}-${ARCH}-${OS}-${DISTRO}-${DIST_VERSION}.tar.xz | |
;; | |
*) | |
echo '[!] Unsupported OS' | |
exit 1 | |
;; | |
esac | |
echo "[+] Creating '${BUILD_DIR}'" | |
mkdir -p ${BUILD_DIR} | |
cd ${BUILD_DIR} | |
if [ ! -f ${FILE} ]; then | |
echo "[+] Downloading Clang+LLVM.." | |
wget http://llvm.org/releases/${LLVM_VER}/${FILE} | |
if [ "$?" != "0" ]; then | |
echo "[!] Unsupported operating system." | |
echo "[!] Check http://llvm.org/releases/${LLVM_VER}/ to see what LLVM" | |
echo "[!] packages are available." | |
exit 2 | |
fi | |
fi | |
if [ ! -d ${LLVM_DIR} ]; then | |
echo "[+] Extracting.." | |
mkdir ${LLVM_DIR} | |
tar xf ${FILE} -C ${LLVM_DIR} --strip-components=1 | |
fi | |
echo "[+] LLVM Installed" | |
# Build openssl, this is needed so the autogenerated dependancy files are there when we create bc. | |
./config | |
make clean build_libs | |
# Build the bear database | |
bear -n -o compile_db.json sh -c 'make clean build_libs' | |
# Parse and alter the database to output a build script that will build LLVM bitcode. | |
python3 comp_db_generate.py -o ./build.sh -l llvm compile_db.json generate | |
/bin/bash ./build.sh | |
echo "Built bitcode files (2) " | |
ls *.bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment