Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2017 Swift Navigation Inc.
# Copyright (C) 2017-2018 Swift Navigation Inc.
# Contact: Swift Navigation <dev@swiftnav.com>
#
# This source is subject to the license found in the file 'LICENSE' which must
Expand All @@ -13,14 +13,19 @@ FROM ubuntu:16.04
RUN mkdir /work
WORKDIR /work

ENV TOOLCHAIN_URL_BASE https://toolchains.bootlin.com/downloads/releases/toolchains

ENV TOOLCHAIN_X86_URL ${TOOLCHAIN_URL_BASE}/x86-64-core-i7/tarballs/x86-64-core-i7--glibc--stable-2018.02-2.tar.bz2
ENV TOOLCHAIN_ARM_URL ${TOOLCHAIN_URL_BASE}/armv7-eabihf/tarballs/armv7-eabihf--glibc--stable-2018.02-2.tar.bz2

RUN apt-get update \
&& apt-get install -y wget \
&& wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main" \
>/etc/apt/sources.list.d/llvm40.list \
&& apt-get update \
&& apt-get upgrade \
&& apt-get install -y libcurl4-openssl-dev \
checkinstall \
build-essential \
bison \
flex \
Expand All @@ -29,25 +34,32 @@ RUN apt-get update \
llvm-4.0-dev \
clang-4.0 \
git \
binutils-dev \
python \
binutils-multiarch-dev \
g++-4.8-arm-linux-gnueabihf \
gcc-4.8-arm-linux-gnueabihf \
gcc-4.8-multilib-arm-linux-gnueabihf \
binutils-arm-linux-gnueabihf \
libgcc1-armhf-cross \
libsfgcc1-armhf-cross \
libstdc++6-armhf-cross \
binutils-dev \
binutils-multiarch-dev \
python \
&& wget -O /tmp/bootlin-toolchain-x86.tbz2 ${TOOLCHAIN_X86_URL} \
&& wget -O /tmp/bootlin-toolchain-arm.tbz2 ${TOOLCHAIN_ARM_URL} \
&& mkdir -p /toolchain/x86 /toolchain/arm \
&& tar -C /toolchain/x86 --strip-components=1 -xvjf \
/tmp/bootlin-toolchain-x86.tbz2 \
&& tar -C /toolchain/arm --strip-components=1 -xvjf \
/tmp/bootlin-toolchain-arm.tbz2 \
&& rm /tmp/bootlin-toolchain-x86.tbz2 /tmp/bootlin-toolchain-arm.tbz2 \
&& mkdir -p cmake-build && cd cmake-build \
&& wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz \
&& tar -xzf cmake-3.10.1.tar.gz \
&& cd cmake-3.10.1 \
&& ./configure \
&& make -j4 \
&& checkinstall -yD make install \
&& make install \
&& cd .. && rm -rf cmake-* \
&& apt-get -y --force-yes remove checkinstall \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ cpp_wrapper: cpp_wrapper.c
gcc -O3 -std=c99 -Wall cpp_wrapper.c -o cpp_wrapper

check:
docker run -v $(CURDIR):/mnt koalaman/shellcheck -x $(SCRIPTS)
docker run --rm -v $(CURDIR):/mnt koalaman/shellcheck -x $(SCRIPTS)

check-%:
docker run -v $(CURDIR):/mnt koalaman/shellcheck -x $*.bash
docker run --rm -v $(CURDIR):/mnt koalaman/shellcheck -x $*.bash

ifeq ($(NO_TTY),y)
NO_TTY_ARG := --no-tty
Expand All @@ -37,3 +37,8 @@ build-example: check-build_example

run: check-run_build_shell
$(CURDIR)/run_build_shell.bash $(NO_TTY_ARG)

clean:
docker volume rm obfuscator-llvm-build || :
docker volume rm obfuscator-llvm || :
sudo rm -rf output/*
13 changes: 10 additions & 3 deletions base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ IFS=$'\n\t'

[[ -z "${DEBUG:-}" ]] || set -x

[[ -n "${LOCAL_BUILD:-}" ]] || \
[[ -n "${DOCKER_USER:-}" ]] || {
echo "DOCKER_USER: must not be empty"
exit 1
}

[[ -n "${LOCAL_BUILD:-}" ]] || \
[[ -n "${DOCKER_PASS:-}" ]] || {
echo "DOCKER_PASS: must not be empty"
exit 1
Expand All @@ -46,7 +48,8 @@ query_build_pushed() {
| grep "$repo_tag"
}

if [[ -n "$(query_build_pushed "$DOCKER_NAMETAG")" ]]; then
if [[ -z "${LOCAL_BUILD:-}" ]] && \
[[ -n "$(query_build_pushed "$DOCKER_NAMETAG")" ]]; then
echo "Build already pushed, exiting..."
exit 0
fi
Expand All @@ -55,5 +58,9 @@ docker build \
--force-rm --no-cache \
-f Dockerfile -t "$DOCKER_NAMETAG" .

echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
docker push "$DOCKER_NAMETAG"
if [[ -n "${DOCKER_USER:-}" ]] && [[ -n "${DOCKER_PASS:-}" ]]; then
echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
docker push "$DOCKER_NAMETAG"
else
echo "WARNING: not pushing new image to Docker Hub..." >&2
fi
64 changes: 25 additions & 39 deletions bin/arm-linux-gnueabihf-clang
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,36 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

if [[ "${LLVM_OBF_USE_BR_TOOLCHAIN}" ]]; then
D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )

if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
T=${HOST_DIR}/opt/ext-toolchain
export LD_LIBRARY_PATH="${T}/lib/gcc/arm-linux-gnueabihf/6.2.1:$LD_LIBRARY_PATH"

TOOLCHAIN_OPTS="\
--sysroot=${T}/arm-linux-gnueabihf/libc \
\
-fuse-ld=${T}/arm-linux-gnueabihf/bin/ld \
\
-B ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
\
-L ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
-L /piksi_buildroot/buildroot/host_output/host/opt/ext-toolchain/lib/gcc/i686-pc-linux-gnu/4.7.2 \
-Wno-unused-command-line-argument"

if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
export LD_LIBRARY_PATH="${T}/lib"
else
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
fi
else

D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
R=$D/sysroot

export LD_LIBRARY_PATH="${R}/usr/lib/x86_64-linux-gnu:${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib:${R}/usr/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH"

TOOLCHAIN_OPTS="\
\
-fuse-ld=${D}/wrappers/bin/arm-linux-gnueabihf-ld \
--sysroot=${R} \
\
-B ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
\
-I ${R}/usr/arm-linux-gnueabihf/include \
\
-L ${R}/usr/arm-linux-gnueabi/libhf \
-L ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
-L ${R}/usr/lib/x86_64-linux-gnu \
-L ${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib \
-L ${R}/usr/arm-linux-gnueabihf/lib \
\
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabi/libhf \
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabihf/lib \
\
-Wno-unused-command-line-argument"
export LD_LIBRARY_PATH=${BR2_TOOLCHAIN_LD_LIBRARY_PATH}
T=${BR2_TOOLCHAIN_PATH}
fi

toolchain_prefix="arm-buildroot-linux-gnueabihf"
toolchain_version="6.4.0"

TOOLCHAIN_OPTS="\
--sysroot=${T}/${toolchain_prefix}/sysroot \
-L ${T}/${toolchain_prefix}/lib \
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/usr/lib \
-B ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
-L ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
-Wl,-rpath-link=${T}/lib/gcc/${toolchain_prefix} \
-Wl,-rpath-link=${T}/${toolchain_prefix}/sysroot/lib \
-Wl,-rpath-link=${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
-fuse-ld=${T}/${toolchain_prefix}/bin/ld \
-Wno-unused-command-line-argument"

exec ${D}/bin/clang \
${TOOLCHAIN_OPTS} \
-ccc-gcc-name arm-linux-gnueabihf-gcc \
Expand Down
74 changes: 30 additions & 44 deletions bin/arm-linux-gnueabihf-clang++
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,45 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

if [[ "${LLVM_OBF_USE_BR_TOOLCHAIN}" ]]; then
D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )

if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
T=${HOST_DIR}/opt/ext-toolchain
export LD_LIBRARY_PATH="${T}/lib/gcc/arm-linux-gnueabihf/6.2.1"

TOOLCHAIN_OPTS="\
--sysroot=${T}/arm-linux-gnueabihf/libc \
\
-fuse-ld=${T}/arm-linux-gnueabihf/bin/ld \
\
-B ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
\
-I ${T}/arm-linux-gnueabihf/include/c++/6.2.1/ \
-I ${T}/arm-linux-gnueabihf/include/c++/6.2.1/arm-linux-gnueabihf/ \
\
-L ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
-L /piksi_buildroot/buildroot/host_output/host/opt/ext-toolchain/lib/gcc/i686-pc-linux-gnu/4.7.2 \
-Wno-unused-command-line-argument"

if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
export LD_LIBRARY_PATH="${T}/lib"
else
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
fi
else

D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
R=$D/sysroot

export LD_LIBRARY_PATH="${R}/usr/lib/x86_64-linux-gnu:${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib:${R}/usr/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH"

TOOLCHAIN_OPTS="\
\
-fuse-ld=${D}/wrappers/bin/arm-linux-gnueabihf-ld \
--sysroot=${R} \
\
-B ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
\
-I ${R}/usr/arm-linux-gnueabihf/include \
-I ${R}/usr/arm-linux-gnueabihf/include/c++/4.8.5 \
-I ${R}/usr/arm-linux-gnueabihf/include/c++/4.8.5/arm-linux-gnueabihf \
\
-L ${R}/usr/arm-linux-gnueabi/libhf \
-L ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
-L ${R}/usr/lib/x86_64-linux-gnu \
-L ${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib \
-L ${R}/usr/arm-linux-gnueabihf/lib \
\
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabi/libhf \
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabihf/lib \
\
-Wno-unused-command-line-argument"
export LD_LIBRARY_PATH=${BR2_TOOLCHAIN_LD_LIBRARY_PATH}
T=${BR2_TOOLCHAIN_PATH}
fi

export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"

toolchain_prefix="arm-buildroot-linux-gnueabihf"
toolchain_version="6.4.0"

TOOLCHAIN_OPTS="\
--sysroot=${T}/${toolchain_prefix}/sysroot \
-I ${T}/${toolchain_prefix}/include/c++/${toolchain_version}/ \
-I ${T}/${toolchain_prefix}/include/c++/${toolchain_version}/${toolchain_prefix} \
-L ${T}/${toolchain_prefix}/lib \
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/usr/lib \
-B ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
-L ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
-Wl,-rpath-link=${T}/lib/gcc/${toolchain_prefix} \
-Wl,-rpath-link=${T}/${toolchain_prefix}/sysroot/lib \
-Wl,-rpath-link=${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
-fuse-ld=${T}/${toolchain_prefix}/bin/ld \
-Wno-unused-command-line-argument"

exec ${D}/bin/clang++ \
${TOOLCHAIN_OPTS} \
-ccc-gcc-name arm-linux-gnueabihf-gcc \
--target=arm-linux-gnueabihf \
-mfloat-abi=hard \
-mcpu=cortex-a9 \
$@

13 changes: 10 additions & 3 deletions bin/arm-linux-gnueabihf-ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
R=$D/sysroot

export LD_LIBRARY_PATH="${R}/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
toolchain_prefix="arm-buildroot-linux-gnueabihf"
toolname="ld"

exec ${R}/usr/bin/arm-linux-gnueabihf-ld $@
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
T=${HOST_DIR}/opt/ext-toolchain
else
T=${BR2_TOOLCHAIN_PATH}
fi

export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"

exec ${T}/bin/${toolchain_prefix}-${toolname} $@
13 changes: 10 additions & 3 deletions bin/arm-linux-gnueabihf-objcopy
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
R=$D/sysroot

export LD_LIBRARY_PATH="${R}/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
toolchain_prefix="arm-buildroot-linux-gnueabihf"
toolname="objcopy"

exec ${R}/usr/bin/arm-linux-gnueabihf-objcopy $@
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
T=${HOST_DIR}/opt/ext-toolchain
else
T=${BR2_TOOLCHAIN_PATH}
fi

export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"

exec ${T}/bin/${toolchain_prefix}-${toolname} $@
14 changes: 11 additions & 3 deletions bin/arm-linux-gnueabihf-strip
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
R=$D/sysroot

export LD_LIBRARY_PATH="${R}/usr/lib/x86_64-linux-gnu:${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib:$LD_LIBRARY_PATH"
toolchain_prefix="arm-buildroot-linux-gnueabihf"
toolname="strip"

exec ${R}/usr/bin/arm-linux-gnueabihf-strip $@
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
T=${HOST_DIR}/opt/ext-toolchain
else
T=${BR2_TOOLCHAIN_PATH}
fi

export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"

exec ${T}/bin/${toolchain_prefix}-${toolname} $@
7 changes: 4 additions & 3 deletions build.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright (C) 2017 Swift Navigation Inc.
# Copyright (C) 2017-2018 Swift Navigation Inc.
# Contact: Swift Navigation <dev@swiftnav.com>
#
# This source is subject to the license found in the file 'LICENSE' which must
Expand Down Expand Up @@ -41,14 +41,15 @@ if [[ -z "${ARCH:-}" ]]; then
fi

set -x
# -DLLVM_BUILD_TOOLS:BOOL=FALSE \

CMAKE_COMMAND="\
cmake -G Ninja \
/work/obfuscator-llvm \
-DCMAKE_INSTALL_PREFIX=/opt/llvm-obfuscator \
-DLLVM_TARGETS_TO_BUILD=$ARCH \
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1' \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include' \
-DCMAKE_C_COMPILER=/toolchain/x86/bin/x86_64-linux-gcc \
-DCMAKE_CXX_COMPILER=/bin/cpp_wrapper \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BINUTILS_INCDIR=/usr/include \
Expand Down
4 changes: 4 additions & 0 deletions build_example.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -euo pipefail
IFS=$'\n\t'

DOCKER_NAMETAG=$(cat docker_nametag)
BR2_TOOLCHAIN_LD_LIBRARY_PATH=/toolchain/x86/x86_64-buildroot-linux-gnu/lib64

mkdir -p output/opt

Expand Down Expand Up @@ -41,6 +42,9 @@ docker run ${INTERACTIVE[@]:-} --rm \
-v "$PWD/output/opt:/opt" \
-v obfuscator-llvm:/work/obfuscator-llvm \
-v obfuscator-llvm-build:/work/build \
-e BR2_TOOLCHAIN_PATH=/toolchain/arm \
"$DOCKER_NAMETAG" \
/bin/bash -c "export PATH=/opt/llvm-obfuscator/bin:/opt/llvm-obfuscator/wrappers/bin:\$PATH; \
export BR2_TOOLCHAIN_PATH=/toolchain/arm; \
export BR2_TOOLCHAIN_LD_LIBRARY_PATH=$BR2_TOOLCHAIN_LD_LIBRARY_PATH; \
make -C example"
Loading