From 83d904f0741c8daf1b485f252732af7b7d6e86b8 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Tue, 1 May 2018 18:08:12 -0700 Subject: [PATCH 1/8] Stage /usr/include into toolchain's sysroot --- stage_sysroot.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/stage_sysroot.bash b/stage_sysroot.bash index caa33c8..1581eab 100755 --- a/stage_sysroot.bash +++ b/stage_sysroot.bash @@ -47,6 +47,7 @@ stage_sysroot() { SYSROOT_DIRS=( "/usr/arm-linux-gnueabihf" "/usr/arm-linux-gnueabi" + "/usr/include" "/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8" ) From 8384e7eb290bf78d9603996063848595a4aa55dd Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Wed, 2 May 2018 17:58:18 -0700 Subject: [PATCH 2/8] Harmonize llvm toolchain with BR toolchain --- Dockerfile | 23 ++++++++++++----- Makefile | 5 ++++ base.bash | 13 +++++++--- bin/arm-linux-gnueabihf-clang | 47 +++++++---------------------------- build.bash | 5 ++-- cpp_wrapper.c | 19 ++++++++------ docker_nametag | 2 +- run_build_shell.bash | 6 ++++- 8 files changed, 62 insertions(+), 58 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ec7204..05bcf86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,14 +13,18 @@ FROM ubuntu:16.04 RUN mkdir /work WORKDIR /work +ENV TOOLCHAIN_X86_URL https://toolchains.bootlin.com/downloads/releases/toolchains/x86-64-core-i7/tarballs/x86-64-core-i7--glibc--bleeding-edge-2018.02-1.tar.bz2 + +ENV TOOLCHAIN_ARM_URL https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--glibc--bleeding-edge-2018.02-1.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 \ @@ -29,6 +33,9 @@ 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 \ @@ -36,18 +43,22 @@ RUN apt-get update \ 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/* diff --git a/Makefile b/Makefile index 51cd187..0b4f46c 100644 --- a/Makefile +++ b/Makefile @@ -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 || : + rm -rf output/* diff --git a/base.bash b/base.bash index 9f8591f..d7cf8ef 100755 --- a/base.bash +++ b/base.bash @@ -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 @@ -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 @@ -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 diff --git a/bin/arm-linux-gnueabihf-clang b/bin/arm-linux-gnueabihf-clang index 3299181..46fe3fa 100755 --- a/bin/arm-linux-gnueabihf-clang +++ b/bin/arm-linux-gnueabihf-clang @@ -10,49 +10,20 @@ # 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 - +if [[ -z "${BR_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" - else + T=${BR_TOOLCHAIN_PATH} +fi - D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) ) - R=$D/sysroot +export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" - 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_prefix="arm-buildroot-linux-gnueabihf" - 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" -fi +TOOLCHAIN_OPTS="\ + --sysroot=${T}/${toolchain_prefix}/sysroot \ + -fuse-ld=${T}/${toolchain_prefix}/bin/ld \ + -Wno-unused-command-line-argument" exec ${D}/bin/clang \ ${TOOLCHAIN_OPTS} \ diff --git a/build.bash b/build.bash index 6f51436..bfe052d 100755 --- a/build.bash +++ b/build.bash @@ -47,13 +47,14 @@ CMAKE_COMMAND="\ /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/7.3.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 \ -DLLDB_DISABLE_CURSES:BOOL=TRUE \ -DLLVM_ENABLE_TERMINFO=0 \ + -DLLVM_BUILD_TOOLS:BOOL=FALSE \ -DLLVM_INCLUDE_TESTS=OFF" PATCH_COMMAND="{ git apply /patches/*.patch || : ; }" diff --git a/cpp_wrapper.c b/cpp_wrapper.c index 679ada4..036fbcf 100644 --- a/cpp_wrapper.c +++ b/cpp_wrapper.c @@ -15,9 +15,10 @@ #include #include -//#define DEBUG +#define DEBUG -const char* real_cpp_path = "/usr/bin/g++"; +//const char* real_cpp_path = "/toolchain/x86/bin/x86_64-linux-g++"; +const char* real_cpp_path = "/toolchain/x86/bin/x86_64-buildroot-linux-gnu-c++.br_real"; const char* new_argv_entry = "lib/libLLVMTransformUtils.a"; int main(int argc, const char* argv[]) { @@ -31,7 +32,7 @@ int main(int argc, const char* argv[]) { } #ifdef DEBUG - printf("%zu\n", args_str_size); + fprintf(stderr, "%zu\n", args_str_size); #endif // Make space for spaces in between argument values + null terminator @@ -50,7 +51,7 @@ int main(int argc, const char* argv[]) { *p = '\0'; #ifdef DEBUG - printf("All args: %s\n", all_args_buf); + fprintf(stderr, "All args: %s\n", all_args_buf); #endif bool append_new_arg = false; @@ -69,6 +70,7 @@ int main(int argc, const char* argv[]) { } argv[0] = real_cpp_path; + int execv_ret; if (append_new_arg) { @@ -77,7 +79,7 @@ int main(int argc, const char* argv[]) { for (int x = 0; x < argc; x++) { - size_t length = (lengths[x] + 1); + size_t length = x == 0 ? strlen(real_cpp_path) : (lengths[x] + 1); new_argv[x] = (char*) malloc(length * sizeof(char)); memcpy((void*) new_argv[x], argv[x], length * sizeof(char)); @@ -92,6 +94,11 @@ int main(int argc, const char* argv[]) { argc = new_argc; argv = new_argv; + + execv_ret = execv(real_cpp_path, (char*const*)new_argv); + } + else { + execv_ret = execv(real_cpp_path, (char*const*)argv); } #if 0 // This causes a heap corruption error trigger? @@ -99,8 +106,6 @@ int main(int argc, const char* argv[]) { free(all_args_buf); #endif - int execv_ret = execv(real_cpp_path, (char*const*)argv); - fprintf(stderr, "execv() failure: %d\n", execv_ret); return -42; } diff --git a/docker_nametag b/docker_nametag index 81f2ee9..2f65926 100644 --- a/docker_nametag +++ b/docker_nametag @@ -1 +1 @@ -swiftnav/arm-llvm-obf:4.0-ubuntu1604-2018.01.16 +swiftnav/arm-llvm-obf:4.0-ubuntu1604-2018.05.01 diff --git a/run_build_shell.bash b/run_build_shell.bash index 73de96d..43e118f 100755 --- a/run_build_shell.bash +++ b/run_build_shell.bash @@ -22,7 +22,11 @@ docker run -i -t --rm \ -v "$PWD/output/opt:/opt" \ -v "$PWD/bin:/wrapper-bin" \ -v "$PWD/patches:/patches" \ + -v "$PWD:/this_dir" \ -v obfuscator-llvm:/work/obfuscator-llvm \ -v obfuscator-llvm-build:/work/build \ "$DOCKER_NAMETAG" \ - /bin/bash -c "export PATH=/opt/llvm-obfuscator/bin:/opt/llvm-obfuscator/wrappers/bin:\$PATH; exec /bin/bash" + /bin/bash -c "export PATH=/opt/llvm-obfuscator/bin:/opt/llvm-obfuscator/wrappers/bin:\$PATH; \ + cp -v /this_dir/cpp_wrapper.c /work/cpp_wrapper.c \ + && gcc -std=c99 -O3 -Wall /work/cpp_wrapper.c -o /bin/cpp_wrapper; \ + exec /bin/bash" From 55e686c832f63075f974f1602879abdbbea861cc Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 17:04:48 -0700 Subject: [PATCH 3/8] Remove support for built-in toolchain We only support the "harmonized" bootlin toolchain now. --- bin/arm-linux-gnueabihf-clang | 14 ++++++- bin/arm-linux-gnueabihf-clang++ | 68 ++++++++++++--------------------- bin/arm-linux-gnueabihf-ld | 13 +++++-- bin/arm-linux-gnueabihf-objcopy | 13 +++++-- bin/arm-linux-gnueabihf-strip | 14 +++++-- build.bash | 2 +- stage_sysroot.bash | 40 ------------------- 7 files changed, 68 insertions(+), 96 deletions(-) diff --git a/bin/arm-linux-gnueabihf-clang b/bin/arm-linux-gnueabihf-clang index 46fe3fa..77668fb 100755 --- a/bin/arm-linux-gnueabihf-clang +++ b/bin/arm-linux-gnueabihf-clang @@ -10,10 +10,12 @@ # EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. -if [[ -z "${BR_TOOLCHAIN_PATH:-}" ]]; then +D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) ) + +if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then T=${HOST_DIR}/opt/ext-toolchain else - T=${BR_TOOLCHAIN_PATH} + T=${BR2_TOOLCHAIN_PATH} fi export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" @@ -22,6 +24,14 @@ toolchain_prefix="arm-buildroot-linux-gnueabihf" 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" diff --git a/bin/arm-linux-gnueabihf-clang++ b/bin/arm-linux-gnueabihf-clang++ index 8ed7cb6..685315f 100755 --- a/bin/arm-linux-gnueabihf-clang++ +++ b/bin/arm-linux-gnueabihf-clang++ @@ -10,55 +10,34 @@ # 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" - 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" + T=${BR2_TOOLCHAIN_PATH} fi +export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" + +toolchain_prefix="arm-buildroot-linux-gnueabihf" +toolchain_version="7.3.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 \ @@ -66,3 +45,4 @@ exec ${D}/bin/clang++ \ -mfloat-abi=hard \ -mcpu=cortex-a9 \ $@ + diff --git a/bin/arm-linux-gnueabihf-ld b/bin/arm-linux-gnueabihf-ld index 2ccab86..f147e97 100755 --- a/bin/arm-linux-gnueabihf-ld +++ b/bin/arm-linux-gnueabihf-ld @@ -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} $@ diff --git a/bin/arm-linux-gnueabihf-objcopy b/bin/arm-linux-gnueabihf-objcopy index 62b464b..a1817c7 100755 --- a/bin/arm-linux-gnueabihf-objcopy +++ b/bin/arm-linux-gnueabihf-objcopy @@ -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} $@ diff --git a/bin/arm-linux-gnueabihf-strip b/bin/arm-linux-gnueabihf-strip index 874639a..e8ab075 100755 --- a/bin/arm-linux-gnueabihf-strip +++ b/bin/arm-linux-gnueabihf-strip @@ -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} $@ diff --git a/build.bash b/build.bash index bfe052d..8a14413 100755 --- a/build.bash +++ b/build.bash @@ -41,6 +41,7 @@ if [[ -z "${ARCH:-}" ]]; then fi set -x +# -DLLVM_BUILD_TOOLS:BOOL=FALSE \ CMAKE_COMMAND="\ cmake -G Ninja \ @@ -54,7 +55,6 @@ CMAKE_COMMAND="\ -DLLVM_BINUTILS_INCDIR=/usr/include \ -DLLDB_DISABLE_CURSES:BOOL=TRUE \ -DLLVM_ENABLE_TERMINFO=0 \ - -DLLVM_BUILD_TOOLS:BOOL=FALSE \ -DLLVM_INCLUDE_TESTS=OFF" PATCH_COMMAND="{ git apply /patches/*.patch || : ; }" diff --git a/stage_sysroot.bash b/stage_sysroot.bash index 1581eab..867319e 100755 --- a/stage_sysroot.bash +++ b/stage_sysroot.bash @@ -44,18 +44,6 @@ stage_sysroot() { rm -rf "$OUT" mkdir -p "$OUT" - SYSROOT_DIRS=( - "/usr/arm-linux-gnueabihf" - "/usr/arm-linux-gnueabi" - "/usr/include" - "/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8" - ) - - for SYSROOT_DIR in "${SYSROOT_DIRS[@]}"; do - mkdir -p "${OUT}/${SYSROOT_DIR}" - rsync -azv "${SYSROOT_DIR}/" "${OUT}/${SYSROOT_DIR}/" - done - WRAPPERS_BIN=/opt/llvm-obfuscator/wrappers/bin mkdir -p $WRAPPERS_BIN @@ -64,36 +52,8 @@ stage_sysroot() { LICENSE=/opt/llvm-obfuscator/ cp -v /this_dir/LICENSE $LICENSE - BINTOOLS=( - /usr/bin/arm-linux-gnueabihf-ar - /usr/bin/arm-linux-gnueabihf-as - /usr/bin/arm-linux-gnueabihf-ld - /usr/bin/arm-linux-gnueabihf-ld.bfd - /usr/bin/arm-linux-gnueabihf-ld.gold - /usr/bin/arm-linux-gnueabihf-nm - /usr/bin/arm-linux-gnueabihf-objcopy - /usr/bin/arm-linux-gnueabihf-objdump - /usr/bin/arm-linux-gnueabihf-ranlib - /usr/bin/arm-linux-gnueabihf-readelf - /usr/bin/arm-linux-gnueabihf-strip - ) - - mkdir -p "${OUT}/usr/bin/" - - for BINTOOL in "${BINTOOLS[@]}"; do - cp -v "$BINTOOL" "${OUT}/usr/bin/" - done - mkdir -p "${OUT}/buildroot" cp -v /this_dir/toolchainfile.cmake "${OUT}/buildroot" - - D="${OUT}/usr/lib/x86_64-linux-gnu/" - - mkdir -p "$D" - - for ARMHF in /usr/lib/x86_64-linux-gnu/*armhf*; do - cp -v "${ARMHF}" "$D/" - done } run() { From 9481a10d48e8c6e06a89b05b56814ae6379363e5 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 17:11:55 -0700 Subject: [PATCH 4/8] Switch to stable toolchain --- Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 05bcf86..d24e6cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Copyright (C) 2017 Swift Navigation Inc. +# Copyright (C) 2017-2018 Swift Navigation Inc. # Contact: Swift Navigation # # This source is subject to the license found in the file 'LICENSE' which must @@ -13,9 +13,10 @@ FROM ubuntu:16.04 RUN mkdir /work WORKDIR /work -ENV TOOLCHAIN_X86_URL https://toolchains.bootlin.com/downloads/releases/toolchains/x86-64-core-i7/tarballs/x86-64-core-i7--glibc--bleeding-edge-2018.02-1.tar.bz2 +ENV TOOLCHAIN_URL_BASE https://toolchains.bootlin.com/downloads/releases/toolchains -ENV TOOLCHAIN_ARM_URL https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--glibc--bleeding-edge-2018.02-1.tar.bz2 +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 \ From d2e0cd75a57007789865a5b0e2fa4614b096bc25 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 17:15:37 -0700 Subject: [PATCH 5/8] GCC version 6.4.0 --- bin/arm-linux-gnueabihf-clang | 1 + bin/arm-linux-gnueabihf-clang++ | 2 +- build.bash | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/arm-linux-gnueabihf-clang b/bin/arm-linux-gnueabihf-clang index 77668fb..f2aca80 100755 --- a/bin/arm-linux-gnueabihf-clang +++ b/bin/arm-linux-gnueabihf-clang @@ -21,6 +21,7 @@ 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 \ diff --git a/bin/arm-linux-gnueabihf-clang++ b/bin/arm-linux-gnueabihf-clang++ index 685315f..c2b6c99 100755 --- a/bin/arm-linux-gnueabihf-clang++ +++ b/bin/arm-linux-gnueabihf-clang++ @@ -21,7 +21,7 @@ fi export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" toolchain_prefix="arm-buildroot-linux-gnueabihf" -toolchain_version="7.3.0" +toolchain_version="6.4.0" TOOLCHAIN_OPTS="\ --sysroot=${T}/${toolchain_prefix}/sysroot \ diff --git a/build.bash b/build.bash index 8a14413..b397469 100755 --- a/build.bash +++ b/build.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (C) 2017 Swift Navigation Inc. +# Copyright (C) 2017-2018 Swift Navigation Inc. # Contact: Swift Navigation # # This source is subject to the license found in the file 'LICENSE' which must @@ -48,7 +48,7 @@ CMAKE_COMMAND="\ /work/obfuscator-llvm \ -DCMAKE_INSTALL_PREFIX=/opt/llvm-obfuscator \ -DLLVM_TARGETS_TO_BUILD=$ARCH \ - -DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/7.3.0/plugin/include' \ + -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 \ From 1459bce6d547225240b4ee6ec254902ea16247ac Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 17:20:51 -0700 Subject: [PATCH 6/8] Purge debug --- Makefile | 2 +- cpp_wrapper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0b4f46c..d9347fa 100644 --- a/Makefile +++ b/Makefile @@ -41,4 +41,4 @@ run: check-run_build_shell clean: docker volume rm obfuscator-llvm-build || : docker volume rm obfuscator-llvm || : - rm -rf output/* + sudo rm -rf output/* diff --git a/cpp_wrapper.c b/cpp_wrapper.c index 036fbcf..99feb78 100644 --- a/cpp_wrapper.c +++ b/cpp_wrapper.c @@ -15,7 +15,7 @@ #include #include -#define DEBUG +//#define DEBUG //const char* real_cpp_path = "/toolchain/x86/bin/x86_64-linux-g++"; const char* real_cpp_path = "/toolchain/x86/bin/x86_64-buildroot-linux-gnu-c++.br_real"; From af22bf9f6e1028d63340b8f6c932780539569295 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 17:48:56 -0700 Subject: [PATCH 7/8] Use --rm for shellcheck --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d9347fa..d672ceb 100644 --- a/Makefile +++ b/Makefile @@ -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 From 9fa51d8c7a50c0f78dcb97a9553ea0e7bff513b8 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Mon, 7 May 2018 19:41:15 -0700 Subject: [PATCH 8/8] Fix example compilation --- bin/arm-linux-gnueabihf-clang | 8 ++++++-- bin/arm-linux-gnueabihf-clang++ | 6 ++++++ build_example.bash | 4 ++++ run_build_shell.bash | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/arm-linux-gnueabihf-clang b/bin/arm-linux-gnueabihf-clang index f2aca80..2af96e9 100755 --- a/bin/arm-linux-gnueabihf-clang +++ b/bin/arm-linux-gnueabihf-clang @@ -14,12 +14,16 @@ D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) ) if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then T=${HOST_DIR}/opt/ext-toolchain + if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then + export LD_LIBRARY_PATH="${T}/lib" + else + export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" + fi else + 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" diff --git a/bin/arm-linux-gnueabihf-clang++ b/bin/arm-linux-gnueabihf-clang++ index c2b6c99..371d2ae 100755 --- a/bin/arm-linux-gnueabihf-clang++ +++ b/bin/arm-linux-gnueabihf-clang++ @@ -14,7 +14,13 @@ D=$( (cd `dirname $0`/../.. >/dev/null; pwd -P) ) if [[ -z "${BR2_TOOLCHAIN_PATH:-}" ]]; then T=${HOST_DIR}/opt/ext-toolchain + if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then + export LD_LIBRARY_PATH="${T}/lib" + else + export LD_LIBRARY_PATH="${T}/lib:$LD_LIBRARY_PATH" + fi else + export LD_LIBRARY_PATH=${BR2_TOOLCHAIN_LD_LIBRARY_PATH} T=${BR2_TOOLCHAIN_PATH} fi diff --git a/build_example.bash b/build_example.bash index 450a072..dcaea62 100755 --- a/build_example.bash +++ b/build_example.bash @@ -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 @@ -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" diff --git a/run_build_shell.bash b/run_build_shell.bash index 43e118f..acd6f67 100755 --- a/run_build_shell.bash +++ b/run_build_shell.bash @@ -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 @@ -29,4 +30,6 @@ docker run -i -t --rm \ /bin/bash -c "export PATH=/opt/llvm-obfuscator/bin:/opt/llvm-obfuscator/wrappers/bin:\$PATH; \ cp -v /this_dir/cpp_wrapper.c /work/cpp_wrapper.c \ && gcc -std=c99 -O3 -Wall /work/cpp_wrapper.c -o /bin/cpp_wrapper; \ + export BR2_TOOLCHAIN_PATH=/toolchain/arm; \ + export BR2_TOOLCHAIN_LD_LIBRARY_PATH=$BR2_TOOLCHAIN_LD_LIBRARY_PATH; \ exec /bin/bash"