Skip to content

Commit 474b6c1

Browse files
author
Jason Mobarak
authored
Merge pull request #9 from swift-nav/silverjam/stage-include
Use bootlin x86_64 toolchain to build
2 parents acfae4d + 9fa51d8 commit 474b6c1

14 files changed

+150
-154
lines changed

Dockerfile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2017 Swift Navigation Inc.
1+
# Copyright (C) 2017-2018 Swift Navigation Inc.
22
# Contact: Swift Navigation <[email protected]>
33
#
44
# This source is subject to the license found in the file 'LICENSE' which must
@@ -13,14 +13,19 @@ FROM ubuntu:16.04
1313
RUN mkdir /work
1414
WORKDIR /work
1515

16+
ENV TOOLCHAIN_URL_BASE https://toolchains.bootlin.com/downloads/releases/toolchains
17+
18+
ENV TOOLCHAIN_X86_URL ${TOOLCHAIN_URL_BASE}/x86-64-core-i7/tarballs/x86-64-core-i7--glibc--stable-2018.02-2.tar.bz2
19+
ENV TOOLCHAIN_ARM_URL ${TOOLCHAIN_URL_BASE}/armv7-eabihf/tarballs/armv7-eabihf--glibc--stable-2018.02-2.tar.bz2
20+
1621
RUN apt-get update \
1722
&& apt-get install -y wget \
1823
&& wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
1924
&& echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main" \
2025
>/etc/apt/sources.list.d/llvm40.list \
2126
&& apt-get update \
27+
&& apt-get upgrade \
2228
&& apt-get install -y libcurl4-openssl-dev \
23-
checkinstall \
2429
build-essential \
2530
bison \
2631
flex \
@@ -29,25 +34,32 @@ RUN apt-get update \
2934
llvm-4.0-dev \
3035
clang-4.0 \
3136
git \
37+
binutils-dev \
38+
python \
39+
binutils-multiarch-dev \
3240
g++-4.8-arm-linux-gnueabihf \
3341
gcc-4.8-arm-linux-gnueabihf \
3442
gcc-4.8-multilib-arm-linux-gnueabihf \
3543
binutils-arm-linux-gnueabihf \
3644
libgcc1-armhf-cross \
3745
libsfgcc1-armhf-cross \
3846
libstdc++6-armhf-cross \
39-
binutils-dev \
40-
binutils-multiarch-dev \
41-
python \
47+
&& wget -O /tmp/bootlin-toolchain-x86.tbz2 ${TOOLCHAIN_X86_URL} \
48+
&& wget -O /tmp/bootlin-toolchain-arm.tbz2 ${TOOLCHAIN_ARM_URL} \
49+
&& mkdir -p /toolchain/x86 /toolchain/arm \
50+
&& tar -C /toolchain/x86 --strip-components=1 -xvjf \
51+
/tmp/bootlin-toolchain-x86.tbz2 \
52+
&& tar -C /toolchain/arm --strip-components=1 -xvjf \
53+
/tmp/bootlin-toolchain-arm.tbz2 \
54+
&& rm /tmp/bootlin-toolchain-x86.tbz2 /tmp/bootlin-toolchain-arm.tbz2 \
4255
&& mkdir -p cmake-build && cd cmake-build \
4356
&& wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz \
4457
&& tar -xzf cmake-3.10.1.tar.gz \
4558
&& cd cmake-3.10.1 \
4659
&& ./configure \
4760
&& make -j4 \
48-
&& checkinstall -yD make install \
61+
&& make install \
4962
&& cd .. && rm -rf cmake-* \
50-
&& apt-get -y --force-yes remove checkinstall \
5163
&& apt-get clean \
5264
&& rm -rf /var/lib/apt/lists/*
5365

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ cpp_wrapper: cpp_wrapper.c
1212
gcc -O3 -std=c99 -Wall cpp_wrapper.c -o cpp_wrapper
1313

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

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

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

3838
run: check-run_build_shell
3939
$(CURDIR)/run_build_shell.bash $(NO_TTY_ARG)
40+
41+
clean:
42+
docker volume rm obfuscator-llvm-build || :
43+
docker volume rm obfuscator-llvm || :
44+
sudo rm -rf output/*

base.bash

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ IFS=$'\n\t'
1515

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

18+
[[ -n "${LOCAL_BUILD:-}" ]] || \
1819
[[ -n "${DOCKER_USER:-}" ]] || {
1920
echo "DOCKER_USER: must not be empty"
2021
exit 1
2122
}
2223

24+
[[ -n "${LOCAL_BUILD:-}" ]] || \
2325
[[ -n "${DOCKER_PASS:-}" ]] || {
2426
echo "DOCKER_PASS: must not be empty"
2527
exit 1
@@ -46,7 +48,8 @@ query_build_pushed() {
4648
| grep "$repo_tag"
4749
}
4850

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

58-
echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
59-
docker push "$DOCKER_NAMETAG"
61+
if [[ -n "${DOCKER_USER:-}" ]] && [[ -n "${DOCKER_PASS:-}" ]]; then
62+
echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
63+
docker push "$DOCKER_NAMETAG"
64+
else
65+
echo "WARNING: not pushing new image to Docker Hub..." >&2
66+
fi

bin/arm-linux-gnueabihf-clang

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,36 @@
1010
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
1111
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1212

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

15+
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
1516
T=${HOST_DIR}/opt/ext-toolchain
16-
export LD_LIBRARY_PATH="${T}/lib/gcc/arm-linux-gnueabihf/6.2.1:$LD_LIBRARY_PATH"
17-
18-
TOOLCHAIN_OPTS="\
19-
--sysroot=${T}/arm-linux-gnueabihf/libc \
20-
\
21-
-fuse-ld=${T}/arm-linux-gnueabihf/bin/ld \
22-
\
23-
-B ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
24-
\
25-
-L ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
26-
-L /piksi_buildroot/buildroot/host_output/host/opt/ext-toolchain/lib/gcc/i686-pc-linux-gnu/4.7.2 \
27-
-Wno-unused-command-line-argument"
28-
17+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
18+
export LD_LIBRARY_PATH="${T}/lib"
19+
else
20+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
21+
fi
2922
else
30-
31-
D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
32-
R=$D/sysroot
33-
34-
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"
35-
36-
TOOLCHAIN_OPTS="\
37-
\
38-
-fuse-ld=${D}/wrappers/bin/arm-linux-gnueabihf-ld \
39-
--sysroot=${R} \
40-
\
41-
-B ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
42-
\
43-
-I ${R}/usr/arm-linux-gnueabihf/include \
44-
\
45-
-L ${R}/usr/arm-linux-gnueabi/libhf \
46-
-L ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
47-
-L ${R}/usr/lib/x86_64-linux-gnu \
48-
-L ${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib \
49-
-L ${R}/usr/arm-linux-gnueabihf/lib \
50-
\
51-
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabi/libhf \
52-
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabihf/lib \
53-
\
54-
-Wno-unused-command-line-argument"
23+
export LD_LIBRARY_PATH=${BR2_TOOLCHAIN_LD_LIBRARY_PATH}
24+
T=${BR2_TOOLCHAIN_PATH}
5525
fi
5626

27+
toolchain_prefix="arm-buildroot-linux-gnueabihf"
28+
toolchain_version="6.4.0"
29+
30+
TOOLCHAIN_OPTS="\
31+
--sysroot=${T}/${toolchain_prefix}/sysroot \
32+
-L ${T}/${toolchain_prefix}/lib \
33+
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
34+
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/usr/lib \
35+
-B ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
36+
-L ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
37+
-Wl,-rpath-link=${T}/lib/gcc/${toolchain_prefix} \
38+
-Wl,-rpath-link=${T}/${toolchain_prefix}/sysroot/lib \
39+
-Wl,-rpath-link=${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
40+
-fuse-ld=${T}/${toolchain_prefix}/bin/ld \
41+
-Wno-unused-command-line-argument"
42+
5743
exec ${D}/bin/clang \
5844
${TOOLCHAIN_OPTS} \
5945
-ccc-gcc-name arm-linux-gnueabihf-gcc \

bin/arm-linux-gnueabihf-clang++

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,45 @@
1010
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
1111
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1212

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

15+
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
1516
T=${HOST_DIR}/opt/ext-toolchain
16-
export LD_LIBRARY_PATH="${T}/lib/gcc/arm-linux-gnueabihf/6.2.1"
17-
18-
TOOLCHAIN_OPTS="\
19-
--sysroot=${T}/arm-linux-gnueabihf/libc \
20-
\
21-
-fuse-ld=${T}/arm-linux-gnueabihf/bin/ld \
22-
\
23-
-B ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
24-
\
25-
-I ${T}/arm-linux-gnueabihf/include/c++/6.2.1/ \
26-
-I ${T}/arm-linux-gnueabihf/include/c++/6.2.1/arm-linux-gnueabihf/ \
27-
\
28-
-L ${T}/lib/gcc/arm-linux-gnueabihf/6.2.1/ \
29-
-L /piksi_buildroot/buildroot/host_output/host/opt/ext-toolchain/lib/gcc/i686-pc-linux-gnu/4.7.2 \
30-
-Wno-unused-command-line-argument"
31-
17+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
18+
export LD_LIBRARY_PATH="${T}/lib"
19+
else
20+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
21+
fi
3222
else
33-
34-
D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) )
35-
R=$D/sysroot
36-
37-
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"
38-
39-
TOOLCHAIN_OPTS="\
40-
\
41-
-fuse-ld=${D}/wrappers/bin/arm-linux-gnueabihf-ld \
42-
--sysroot=${R} \
43-
\
44-
-B ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
45-
\
46-
-I ${R}/usr/arm-linux-gnueabihf/include \
47-
-I ${R}/usr/arm-linux-gnueabihf/include/c++/4.8.5 \
48-
-I ${R}/usr/arm-linux-gnueabihf/include/c++/4.8.5/arm-linux-gnueabihf \
49-
\
50-
-L ${R}/usr/arm-linux-gnueabi/libhf \
51-
-L ${R}/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 \
52-
-L ${R}/usr/lib/x86_64-linux-gnu \
53-
-L ${R}/usr/x86_64-linux-gnu/arm-linux-gnueabihf/lib \
54-
-L ${R}/usr/arm-linux-gnueabihf/lib \
55-
\
56-
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabi/libhf \
57-
-Wl,-rpath-link=${R}/usr/arm-linux-gnueabihf/lib \
58-
\
59-
-Wno-unused-command-line-argument"
23+
export LD_LIBRARY_PATH=${BR2_TOOLCHAIN_LD_LIBRARY_PATH}
24+
T=${BR2_TOOLCHAIN_PATH}
6025
fi
6126

27+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
28+
29+
toolchain_prefix="arm-buildroot-linux-gnueabihf"
30+
toolchain_version="6.4.0"
31+
32+
TOOLCHAIN_OPTS="\
33+
--sysroot=${T}/${toolchain_prefix}/sysroot \
34+
-I ${T}/${toolchain_prefix}/include/c++/${toolchain_version}/ \
35+
-I ${T}/${toolchain_prefix}/include/c++/${toolchain_version}/${toolchain_prefix} \
36+
-L ${T}/${toolchain_prefix}/lib \
37+
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
38+
-L ${HOST_DIR}/${toolchain_prefix}/sysroot/usr/lib \
39+
-B ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
40+
-L ${T}/lib/gcc/${toolchain_prefix}/${toolchain_version} \
41+
-Wl,-rpath-link=${T}/lib/gcc/${toolchain_prefix} \
42+
-Wl,-rpath-link=${T}/${toolchain_prefix}/sysroot/lib \
43+
-Wl,-rpath-link=${HOST_DIR}/${toolchain_prefix}/sysroot/lib \
44+
-fuse-ld=${T}/${toolchain_prefix}/bin/ld \
45+
-Wno-unused-command-line-argument"
46+
6247
exec ${D}/bin/clang++ \
6348
${TOOLCHAIN_OPTS} \
6449
-ccc-gcc-name arm-linux-gnueabihf-gcc \
6550
--target=arm-linux-gnueabihf \
6651
-mfloat-abi=hard \
6752
-mcpu=cortex-a9 \
6853
$@
54+

bin/arm-linux-gnueabihf-ld

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1212

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

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

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

24+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
25+
26+
exec ${T}/bin/${toolchain_prefix}-${toolname} $@

bin/arm-linux-gnueabihf-objcopy

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1212

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

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

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

24+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
25+
26+
exec ${T}/bin/${toolchain_prefix}-${toolname} $@

bin/arm-linux-gnueabihf-strip

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1212

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

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

18-
exec ${R}/usr/bin/arm-linux-gnueabihf-strip $@
18+
if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then
19+
T=${HOST_DIR}/opt/ext-toolchain
20+
else
21+
T=${BR2_TOOLCHAIN_PATH}
22+
fi
23+
24+
export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH"
25+
26+
exec ${T}/bin/${toolchain_prefix}-${toolname} $@

build.bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Copyright (C) 2017 Swift Navigation Inc.
3+
# Copyright (C) 2017-2018 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
55
#
66
# This source is subject to the license found in the file 'LICENSE' which must
@@ -41,14 +41,15 @@ if [[ -z "${ARCH:-}" ]]; then
4141
fi
4242

4343
set -x
44+
# -DLLVM_BUILD_TOOLS:BOOL=FALSE \
4445

4546
CMAKE_COMMAND="\
4647
cmake -G Ninja \
4748
/work/obfuscator-llvm \
4849
-DCMAKE_INSTALL_PREFIX=/opt/llvm-obfuscator \
4950
-DLLVM_TARGETS_TO_BUILD=$ARCH \
50-
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1' \
51-
-DCMAKE_C_COMPILER=/usr/bin/gcc \
51+
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include' \
52+
-DCMAKE_C_COMPILER=/toolchain/x86/bin/x86_64-linux-gcc \
5253
-DCMAKE_CXX_COMPILER=/bin/cpp_wrapper \
5354
-DCMAKE_BUILD_TYPE=Release \
5455
-DLLVM_BINUTILS_INCDIR=/usr/include \

build_example.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -euo pipefail
1414
IFS=$'\n\t'
1515

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

1819
mkdir -p output/opt
1920

@@ -41,6 +42,9 @@ docker run ${INTERACTIVE[@]:-} --rm \
4142
-v "$PWD/output/opt:/opt" \
4243
-v obfuscator-llvm:/work/obfuscator-llvm \
4344
-v obfuscator-llvm-build:/work/build \
45+
-e BR2_TOOLCHAIN_PATH=/toolchain/arm \
4446
"$DOCKER_NAMETAG" \
4547
/bin/bash -c "export PATH=/opt/llvm-obfuscator/bin:/opt/llvm-obfuscator/wrappers/bin:\$PATH; \
48+
export BR2_TOOLCHAIN_PATH=/toolchain/arm; \
49+
export BR2_TOOLCHAIN_LD_LIBRARY_PATH=$BR2_TOOLCHAIN_LD_LIBRARY_PATH; \
4650
make -C example"

0 commit comments

Comments
 (0)