From bfc93fd919b489126a5ca1e16dd6f639a735a889 Mon Sep 17 00:00:00 2001 From: takeshix Date: Thu, 19 Apr 2018 23:32:21 +0200 Subject: [PATCH] Added gdb and gdbserver recipes --- README.md | 9 ++ recipes/gdb/README.md | 13 ++ recipes/gdb/linux_aarch64/Dockerfile | 25 ++++ recipes/gdb/linux_aarch64/build_aarch64.sh | 146 ++++++++++++++++++++ recipes/gdb/linux_armhf/Dockerfile | 25 ++++ recipes/gdb/linux_armhf/build_armhf.sh | 148 +++++++++++++++++++++ recipes/gdb/linux_x86/build_x86.sh | 13 +- recipes/gdb/linux_x86_64/build_x86_64.sh | 13 +- 8 files changed, 378 insertions(+), 14 deletions(-) create mode 100644 recipes/gdb/linux_aarch64/Dockerfile create mode 100644 recipes/gdb/linux_aarch64/build_aarch64.sh create mode 100644 recipes/gdb/linux_armhf/Dockerfile create mode 100644 recipes/gdb/linux_armhf/build_armhf.sh diff --git a/README.md b/README.md index c45c136..d503648 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ Precompiled versions of socat are available for the following operating systems/ * [Linux x86](bin/linux/x86) * [Linux x86_64](bin/linux/x86_64) +## GDB + +Precompiled versions of `gdb` and `gdbserver` are available for the following operating systems/architecturs: + +* [Linux x86](bin/linux/x86) +* [Linux x86_64](bin/linux/x86_64) +* [Linux armhf](bin/linux/armhf) +* [Linux aarch64](bin/linux/aarch64) + # Building with Vagrant The recipes are supposed to be built in Docker containers. In case Docker is not available, it is recommended to use Vagrant to built everything in a VM, e.g. Nmap for Linux x86: diff --git a/recipes/gdb/README.md b/recipes/gdb/README.md index 179d2d5..88a5803 100644 --- a/recipes/gdb/README.md +++ b/recipes/gdb/README.md @@ -13,3 +13,16 @@ sudo docker run -v $(pwd)/output:/output static-toolbox-gdb-x86 sudo docker build -t static-toolbox-gdb-x86-64 . sudo docker run -v $(pwd)/output:/output static-toolbox-gdb-x86-64 ``` + +## Build Linux armhf + +``` +sudo docker build -t static-toolbox-gdb-armhf . +sudo docker run -v $(pwd)/output:/output static-toolbox-gdb-armhf +``` + +## Build Linux aarch64 + +``` +sudo docker build -t static-toolbox-gdb-aarch64 . +sudo docker run -v $(pwd)/output:/output static-toolbox-gdb-aarch64 diff --git a/recipes/gdb/linux_aarch64/Dockerfile b/recipes/gdb/linux_aarch64/Dockerfile new file mode 100644 index 0000000..a1151b8 --- /dev/null +++ b/recipes/gdb/linux_aarch64/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:xenial +RUN apt-get update && \ + apt upgrade -yy && \ + apt install -yy \ + automake \ + cmake \ + build-essential \ + checkinstall \ + libgmp-dev \ + libmpfr-dev \ + libmpc-dev \ + wget \ + git \ + pkg-config \ + python \ + binutils-dev \ + lib32z1-dev \ + byacc \ + flex \ + texinfo \ + qemu +RUN mkdir /build +ADD . /build +RUN chmod +x /build/build_aarch64.sh +CMD /build/build_aarch64.sh diff --git a/recipes/gdb/linux_aarch64/build_aarch64.sh b/recipes/gdb/linux_aarch64/build_aarch64.sh new file mode 100644 index 0000000..47e61d3 --- /dev/null +++ b/recipes/gdb/linux_aarch64/build_aarch64.sh @@ -0,0 +1,146 @@ +#!/bin/bash +#set -e +set -o pipefail +set -x +NMAP_COMMIT= + +fetch(){ + if [ ! -d "/build/musl" ];then + #git clone https://github.com/GregorR/musl-cross.git /build/musl + git clone https://github.com/takeshixx/musl-cross.git /build/musl + fi + if [ ! -d "/build/binutils-gdb" ];then + git clone https://github.com/bminor/binutils-gdb.git /build/binutils-gdb + fi + cd /build/binutils-gdb + git checkout binutils-2_30 + cd - +} + +build_musl_aarch64() { + cd /build/musl + git clean -fdx + echo "ARCH=arm64" >> config.sh + echo "GCC_BUILTIN_PREREQS=yes" >> config.sh + echo "TRIPLE=aarch64-linux-musleabi" >> config.sh + ./build.sh + echo "[+] Finished building musl-cross aarch64" +} + +build_gdb_aarch64() { + cd /build/binutils-gdb + git clean -fdx + make clean || true + + cd /build/binutils-gdb/bfd + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi + make -j4 + + cd /build/binutils-gdb/readline + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/opcodes + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/libiberty + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/libdecnumber + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/zlib + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_LINKER=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld . + make zlibstatic + + cd /build/binutils-gdb/gdb + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + LDFLAGS='-static' \ + ./configure \ + --enable-static=yes \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-interprocess-agent + make -j4 + + cd /build/binutils-gdb/gdb/gdbserver/ + CC='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-gcc -static -fPIC' \ + CXX='/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-ld \ + LDFLAGS='-static' \ + ./configure \ + --enable-static=yes \ + --host=x86_64-linux-gnu \ + --target=aarch64-none-linux-gnueabi \ + --disable-interprocess-agent + make -j4 + + /opt/cross/aarch64-linux-musleabi/bin/aarch64-linux-musleabi-strip /build/binutils-gdb/gdb/gdb /build/binutils-gdb/gdb/gdbserver/gdbserver +} + +build_aarch64(){ + OUT_DIR=/output/`uname | tr 'A-Z' 'a-z'`/aarch64 + mkdir -p $OUT_DIR + build_musl_aarch64 + build_gdb_aarch64 + GDB_VERSION= + GDBSERVER_VERSION= + if which qemu-aarch64 >/dev/null;then + GDB_VERSION="-$(qemu-aarch64 /build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}')" + GDBSERVER_VERSION="-$(qemu-aarch64 /build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}')" + fi + cp /build/binutils-gdb/gdb/gdb "${OUT_DIR}/gdb-aarch64${GDB_VERSION}" + cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR}/gdbserver-aarch64${GDBSERVER_VERSION}" + echo "[+] Finished building aarch64" +} + +main() { + if [ ! -d "/output" ];then + echo "[-] /output does not exist, creating it" + mkdir /output + fi + fetch + build_aarch64 +} + +main diff --git a/recipes/gdb/linux_armhf/Dockerfile b/recipes/gdb/linux_armhf/Dockerfile new file mode 100644 index 0000000..c0f9b40 --- /dev/null +++ b/recipes/gdb/linux_armhf/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:xenial +RUN apt-get update && \ + apt upgrade -yy && \ + apt install -yy \ + automake \ + cmake \ + build-essential \ + checkinstall \ + libgmp-dev \ + libmpfr-dev \ + libmpc-dev \ + wget \ + git \ + pkg-config \ + python \ + binutils-dev \ + lib32z1-dev \ + byacc \ + flex \ + texinfo \ + qemu +RUN mkdir /build +ADD . /build +RUN chmod +x /build/build_armhf.sh +CMD /build/build_armhf.sh diff --git a/recipes/gdb/linux_armhf/build_armhf.sh b/recipes/gdb/linux_armhf/build_armhf.sh new file mode 100644 index 0000000..1c08c7b --- /dev/null +++ b/recipes/gdb/linux_armhf/build_armhf.sh @@ -0,0 +1,148 @@ +#!/bin/bash +#set -e +set -o pipefail +set -x +NMAP_COMMIT= + +fetch(){ + if [ ! -d "/build/musl" ];then + #git clone https://github.com/GregorR/musl-cross.git /build/musl + git clone https://github.com/takeshixx/musl-cross.git /build/musl + fi + if [ ! -d "/build/binutils-gdb" ];then + git clone https://github.com/bminor/binutils-gdb.git /build/binutils-gdb + fi + cd /build/binutils-gdb + git checkout binutils-2_30 + cd - +} + +build_musl_armhf() { + cd /build/musl + git clean -fdx + echo "ARCH=arm" >> config.sh + echo "GCC_BUILTIN_PREREQS=yes" >> config.sh + echo "TRIPLE=arm-linux-musleabihf" >> config.sh + echo "GCC_BOOTSTRAP_CONFFLAGS='--with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16'" >> config.sh + echo "GCC_CONFFLAGS='--with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16'" >> config.sh + ./build.sh + echo "[+] Finished building musl-cross armhf" +} + +build_gdb_armhf() { + cd /build/binutils-gdb + git clean -fdx + make clean || true + + cd /build/binutils-gdb/bfd + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi + make -j4 + + cd /build/binutils-gdb/readline + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/opcodes + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/libiberty + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/libdecnumber + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --disable-shared \ + --enable-static + make -j4 + + cd /build/binutils-gdb/zlib + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_LINKER=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld . + make zlibstatic + + cd /build/binutils-gdb/gdb + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + LDFLAGS='-static' \ + ./configure \ + --enable-static=yes \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --disable-interprocess-agent + make -j4 + + cd /build/binutils-gdb/gdb/gdbserver/ + CC='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-gcc -static -fPIC' \ + CXX='/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-g++ -static -static-libstdc++ -fPIC' \ + LD=/opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-ld \ + LDFLAGS='-static' \ + ./configure \ + --host=x86_64-linux-gnu \ + --target=arm-none-linux-gnueabi \ + --enable-static=yes \ + --disable-interprocess-agent + make -j4 + + /opt/cross/arm-linux-musleabihf/bin/arm-linux-musleabihf-strip /build/binutils-gdb/gdb/gdb /build/binutils-gdb/gdb/gdbserver/gdbserver +} + +build_armhf(){ + OUT_DIR=/output/`uname | tr 'A-Z' 'a-z'`/armhf + mkdir -p $OUT_DIR + build_musl_armhf + build_gdb_armhf + GDB_VERSION= + GDBSERVER_VERSION= + if which qemu-arm >/dev/null;then + GDB_VERSION="-$(qemu-arm /build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}')" + GDBSERVER_VERSION="-$(qemu-arm /build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}')" + fi + cp /build/binutils-gdb/gdb/gdb "${OUT_DIR}/gdb-armhf${GDB_VERSION}" + cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR}/gdbserver-armhf${GDBSERVER_VERSION}" + echo "[+] Finished building armhf" +} + +main() { + if [ ! -d "/output" ];then + echo "[-] /output does not exist, creating it" + mkdir /output + fi + fetch + build_armhf +} + +main diff --git a/recipes/gdb/linux_x86/build_x86.sh b/recipes/gdb/linux_x86/build_x86.sh index 56b4e4f..8efe9af 100644 --- a/recipes/gdb/linux_x86/build_x86.sh +++ b/recipes/gdb/linux_x86/build_x86.sh @@ -15,7 +15,6 @@ fetch(){ cd /build/binutils-gdb git checkout binutils-2_30 cd - - GDB_COMMIT=$(cd /build/binutils-gdb/ && git rev-parse --short HEAD) } build_musl_x86() { @@ -112,14 +111,14 @@ build_gdb_x86() { } build_x86(){ - OUT_DIR_x86=/output/`uname | tr 'A-Z' 'a-z'`/x86 - mkdir -p $OUT_DIR_x86 + OUT_DIR=/output/`uname | tr 'A-Z' 'a-z'`/x86 + mkdir -p $OUT_DIR build_musl_x86 build_gdb_x86 - GDB_VERSION=$(/build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}') - GDBSERVER_VERSION=$(/build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}') - cp /build/binutils-gdb/gdb/gdb "${OUT_DIR_x86}/gdb-${GDB_VERSION}-${GDB_COMMIT}" - cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR_x86}/gdbserver-${GDBSERVER_VERSION}-${GDB_COMMIT}" + GDB_VERSION="-$(/build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}')" + GDBSERVER_VERSION="-$(/build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}')" + cp /build/binutils-gdb/gdb/gdb "${OUT_DIR}/gdb-x86${GDB_VERSION}" + cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR}/gdbserver-x86${GDBSERVER_VERSION}" echo "[+] Finished building x86" } diff --git a/recipes/gdb/linux_x86_64/build_x86_64.sh b/recipes/gdb/linux_x86_64/build_x86_64.sh index 746bf66..9ebf25f 100644 --- a/recipes/gdb/linux_x86_64/build_x86_64.sh +++ b/recipes/gdb/linux_x86_64/build_x86_64.sh @@ -15,7 +15,6 @@ fetch(){ cd /build/binutils-gdb git checkout binutils-2_30 cd - - GDB_COMMIT=$(cd /build/binutils-gdb/ && git rev-parse --short HEAD) } build_musl_x86_64() { @@ -110,14 +109,14 @@ build_gdb_x86_64() { } build_x86_64(){ - OUT_DIR_x86_64=/output/`uname | tr 'A-Z' 'a-z'`/x86_64 - mkdir -p $OUT_DIR_x86_64 + OUT_DIR_x86=/output/`uname | tr 'A-Z' 'a-z'`/x86_64 + mkdir -p $OUT_DIR_x86 build_musl_x86_64 build_gdb_x86_64 - GDB_VERSION=$(/build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}') - GDBSERVER_VERSION=$(/build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}') - cp /build/binutils-gdb/gdb/gdb "${OUT_DIR_x86_64}/gdb-${GDB_VERSION}-${GDB_COMMIT}" - cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR_x86_64}/gdbserver-${GDBSERVER_VERSION}-${GDB_COMMIT}" + GDB_VERSION="-$(/build/binutils-gdb/gdb/gdb --version |head -n1 |awk '{print $4}')" + GDBSERVER_VERSION="-$(/build/binutils-gdb/gdb/gdbserver/gdbserver --version |head -n1 |awk '{print $4}')" + cp /build/binutils-gdb/gdb/gdb "${OUT_DIR}/gdb-x86_64${GDB_VERSION}" + cp /build/binutils-gdb/gdb/gdbserver/gdbserver "${OUT_DIR}/gdbserver-x86_64${GDBSERVER_VERSION}" echo "[+] Finished building x86_64" }