From 9196d0b3db197187c45c87e191f39e2e1d3a6cd3 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Tue, 1 Apr 2025 22:03:11 +0300 Subject: [PATCH 01/14] build: Use musl-based compiler by default --- src/compilation/build.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compilation/build.sh b/src/compilation/build.sh index d08d3a7..e812e32 100755 --- a/src/compilation/build.sh +++ b/src/compilation/build.sh @@ -28,23 +28,23 @@ function set_compliation_variables() { >&2 fancy_title "Setting compilation variables for $target_arch" if [[ "$target_arch" == "arm" ]]; then - CROSS=arm-linux-gnueabi- - export HOST=arm-linux-gnueabi + CROSS=arm-linux-musleabi- + export HOST=arm-linux-musleabi elif [[ "$target_arch" == "aarch64" ]]; then - CROSS=aarch64-linux-gnu- - export HOST=aarch64-linux-gnu + CROSS=aarch64-linux-musl- + export HOST=aarch64-linux-musl elif [[ "$target_arch" == "powerpc" ]]; then - CROSS=powerpc-linux-gnu- - export HOST=powerpc-linux-gnu + CROSS=powerpc-linux-musl- + export HOST=powerpc-linux-musl elif [[ "$target_arch" == "mips" ]]; then - CROSS=mips-linux-gnu- - export HOST=mips-linux-gnu + CROSS=mips-linux-musl- + export HOST=mips-linux-musl elif [[ "$target_arch" == "mipsel" ]]; then - CROSS=mipsel-linux-gnu- - export HOST=mipsel-linux-gnu + CROSS=mipsel-linux-musl- + export HOST=mipsel-linux-musl elif [[ "$target_arch" == "x86_64" ]]; then - CROSS=x86_64-linux-gnu- - export HOST=x86_64-linux-gnu + CROSS=x86_64-linux-musl- + export HOST=x86_64-linux-musl fi export CC="${CROSS}gcc" From 281316d53e75701f5c9e099efbc26f5a8066328b Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Wed, 2 Apr 2025 00:07:26 +0300 Subject: [PATCH 02/14] build: Add -j to make install to speed compilation --- src/compilation/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compilation/build.sh b/src/compilation/build.sh index e812e32..165b1ab 100755 --- a/src/compilation/build.sh +++ b/src/compilation/build.sh @@ -552,7 +552,7 @@ function install_gdb() { mkdir -p "$artifacts_location" - make -C "$gdb_build_dir" install "DESTDIR=$temp_artifacts_dir" 1>&2 + make -j$(nproc) -C "$gdb_build_dir" install "DESTDIR=$temp_artifacts_dir" 1>&2 if [[ $? -ne 0 ]]; then rm -rf "$temp_artifacts_dir" return 1 From b9a362881a42b0098d5be4c5eb7a35f6ec605a23 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Thu, 17 Apr 2025 12:43:05 +0300 Subject: [PATCH 03/14] build: Build inside docker in terminal attached mode Now builds are cancellable via ctrl+c :) --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5791380..8e2a8d4 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ build-docker-image: build/build-docker-image.stamp build/download-packages.stamp: build/build-docker-image.stamp src/compilation/download_packages.sh mkdir -p $(BUILD_PACKAGES_DIR) - docker run --user $(shell id -u):$(shell id -g) \ + docker run -it --user $(shell id -u):$(shell id -g) \ --rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \ /app/gdb/src/compilation/download_packages.sh /app/gdb/$(BUILD_PACKAGES_DIR)/ touch build/download-packages.stamp @@ -59,7 +59,7 @@ $(PYTHON_TARGETS): build-with-python-%: _build-%: symlink-git-packages download-packages build-docker-image mkdir -p build - docker run --user $(shell id -u):$(shell id -g) \ + docker run -it --user $(shell id -u):$(shell id -g) \ --rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \ /app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON) From 017c360da414419d50f459958902a06efd5674cc Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Thu, 17 Apr 2025 13:11:31 +0300 Subject: [PATCH 04/14] build: Disable cached configuration for gdb --- src/compilation/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compilation/build.sh b/src/compilation/build.sh index 165b1ab..0ba14f8 100755 --- a/src/compilation/build.sh +++ b/src/compilation/build.sh @@ -493,7 +493,7 @@ function build_gdb() { >&2 fancy_title "Building gdb for $target_arch" - ../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \ + ../configure --enable-static --with-static-standard-libraries --disable-inprocess-agent \ --enable-tui "$python_flag" \ --with-expat --with-libexpat-type="static" \ --with-gdb-datadir="/usr/share/gdb" --with-separate-debug-dir="/usr/lib/debug" \ From 7acb93723a68ab951129952819c4d70a45e7c558 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 16:24:43 +0300 Subject: [PATCH 05/14] build: Install gmp,mpfr,ncurses,expat We now invoke make install for all of these packages. We later on add their include paths so that the compiler is aware of any needed headers. This allows us to not be reliant on *-dev libaries, which are often libc-based, and are not installed in our custom musl toolchains. --- src/compilation/build.sh | 95 ++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/src/compilation/build.sh b/src/compilation/build.sh index 0ba14f8..4e189cf 100755 --- a/src/compilation/build.sh +++ b/src/compilation/build.sh @@ -61,14 +61,25 @@ function set_up_lib_search_paths() { # Set up library-related linker search paths. # # Parameters: - # $1: ncursesw build dir - # $2: libexpat build dir - local ncursesw_build_dir="$1" - local libexpat_build_dir="$2" + # $1: iconv build dir + # $2: gmp build dir + # $3: mpfr build dir + # $4: ncursesw build dir + # $5: libexpat build dir + local iconv_build_dir="$1" + local gmp_build_dir="$2" + local mpfr_build_dir="$3" + local ncursesw_build_dir="$4" + local libexpat_build_dir="$5" # I) Allow tui mode by adding our custom built static ncursesw library to the linker search path. # II) Allow parsing xml files by adding libexpat library to the linker search path. - export LDFLAGS="-L$ncursesw_build_dir/lib -L$libexpat_build_dir/lib/.libs $LDFLAGS" + export LDFLAGS="-L$ncursesw_build_dir/lib -L$libexpat_build_dir/lib/ $LDFLAGS" + + # Add library standard headers to the CC / CXX flags. + export INCLUDE_PATHS="-I$iconv_build_dir/include -I$gmp_build_dir/include -I$mpfr_build_dir/include -I$ncursesw_build_dir/include -I$libexpat_build_dir/include" + export CC="$CC $INCLUDE_PATHS" + export CXX="$CXX $INCLUDE_PATHS" } function build_iconv() { @@ -92,7 +103,7 @@ function build_iconv() { echo "$iconv_build_dir" mkdir -p "$iconv_build_dir" - if [[ -f "$iconv_build_dir/lib/.libs/libiconv.a" ]]; then + if [[ -f "$iconv_build_dir/lib/libiconv.a" ]]; then >&2 echo "Skipping build: iconv already built for $target_arch" return 0 fi @@ -102,7 +113,7 @@ function build_iconv() { >&2 fancy_title "Building libiconv for $target_arch" ../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \ - "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2 + "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" --prefix="$(realpath .)" 1>&2 if [[ $? -ne 0 ]]; then return 1 fi @@ -112,9 +123,10 @@ function build_iconv() { return 1 fi - cp -r ./include ./lib/.libs/ - mkdir -p ./lib/.libs/lib/ - cp ./lib/.libs/libiconv.a ./lib/.libs/lib/ + make -j$(nproc) install 1>&2 + if [[ $? -ne 0 ]]; then + return 1 + fi >&2 fancy_title "Finished building libiconv for $target_arch" @@ -194,7 +206,7 @@ function build_libgmp() { echo "$gmp_build_dir" mkdir -p "$gmp_build_dir" - if [[ -f "$gmp_build_dir/.libs/lib/libgmp.a" ]]; then + if [[ -f "$gmp_build_dir/lib/libgmp.a" ]]; then >&2 echo "Skipping build: libgmp already built for $target_arch" return 0 fi @@ -204,7 +216,7 @@ function build_libgmp() { >&2 fancy_title "Building libgmp for $target_arch" ../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \ - "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2 + "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" --prefix="$(realpath .)" 1>&2 if [[ $? -ne 0 ]]; then return 1 fi @@ -214,10 +226,10 @@ function build_libgmp() { return 1 fi - mkdir -p ./.libs/include/ - cp gmp.h ./.libs/include/ - mkdir -p ./.libs/lib/ - cp ./.libs/libgmp.a ./.libs/lib/ + make -j$(nproc) install 1>&2 + if [[ $? -ne 0 ]]; then + return 1 + fi >&2 fancy_title "Finished building libgmp for $target_arch" @@ -241,10 +253,13 @@ function build_ncurses() { local target_arch="$2" local ncurses_build_dir="$(realpath "$ncurses_dir/build-$target_arch")" - echo "$ncurses_build_dir" - mkdir -p "$ncurses_build_dir" + # ncurses needs a custom install dir due to it's non-standard compilation directories. + local ncurses_install_dir="$ncurses_build_dir/output" - if [[ -f "$ncurses_build_dir/lib/libncursesw.a" ]]; then + echo "$ncurses_install_dir" + mkdir -p "$ncurses_install_dir" + + if [[ -f "$ncurses_install_dir/lib/libncursesw.a" ]]; then >&2 echo "Skipping build: libncursesw already built for $target_arch" return 0 fi @@ -254,7 +269,7 @@ function build_ncurses() { >&2 fancy_title "Building libncursesw for $target_arch" ../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \ - "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" "--enable-widec" 1>&2 + "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" --prefix="$ncurses_install_dir" "--enable-widec" 1>&2 if [[ $? -ne 0 ]]; then return 1 fi @@ -264,6 +279,11 @@ function build_ncurses() { return 1 fi + make -j$(nproc) install 1>&2 + if [[ $? -ne 0 ]]; then + return 1 + fi + >&2 fancy_title "Finished building libncursesw for $target_arch" popd > /dev/null @@ -289,7 +309,7 @@ function build_libexpat() { echo "$libexpat_build_dir" mkdir -p "$libexpat_build_dir" - if [[ -f "$libexpat_build_dir/lib/.libs/libexpat.a" ]]; then + if [[ -f "$libexpat_build_dir/lib/libexpat.a" ]]; then >&2 echo "Skipping build: libexpat already built for $target_arch" return 0 fi @@ -304,7 +324,7 @@ function build_libexpat() { fi ../expat/configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \ - "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2 + "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" --prefix="$(realpath .)" 1>&2 if [[ $? -ne 0 ]]; then return 1 fi @@ -314,6 +334,11 @@ function build_libexpat() { return 1 fi + make -j$(nproc) install 1>&2 + if [[ $? -ne 0 ]]; then + return 1 + fi + >&2 fancy_title "Finished building libexpat for $target_arch" popd > /dev/null @@ -356,7 +381,7 @@ function build_python() { export MODULE_BUILDTYPE="static" export CONFIG_SITE="$python_dir/config.site-static" >&2 CFLAGS="-static" LDFLAGS="-static" ../configure \ - --prefix=$(realpath .) \ + --prefix="$(realpath .)" \ --disable-test-modules \ --with-ensurepip=no \ --without-decimal-contextvar \ @@ -415,7 +440,7 @@ function build_libmpfr() { mkdir -p "$mpfr_build_dir" echo "$mpfr_build_dir" - if [[ -f "$mpfr_build_dir/src/.libs/lib/libmpfr.a" ]]; then + if [[ -f "$mpfr_build_dir/lib/libmpfr.a" ]]; then >&2 echo "Skipping build: libmpfr already built for $target_arch" return 0 fi @@ -424,7 +449,7 @@ function build_libmpfr() { >&2 fancy_title "Building libmpfr for $target_arch" - ../configure --enable-static "--with-gmp-build=$libgmp_build_dir" \ + ../configure --enable-static --prefix="$(realpath .)" "--with-gmp=$libgmp_build_dir" \ "CC=$CC" "CXX=$CXX" "--host=$HOST" \ "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2 if [[ $? -ne 0 ]]; then @@ -436,10 +461,10 @@ function build_libmpfr() { return 1 fi - mkdir -p ./src/.libs/include - cp ../src/mpfr.h ./src/.libs/include/ - mkdir -p ./src/.libs/lib - cp ./src/.libs/libmpfr.a ./src/.libs/lib/ + make -j$(nproc) install 1>&2 + if [[ $? -ne 0 ]]; then + return 1 + fi >&2 fancy_title "Finished building libmpfr for $target_arch" @@ -655,7 +680,11 @@ function build_gdb_with_dependencies() { return 1 fi - set_up_lib_search_paths "$ncursesw_build_dir" "$libexpat_build_dir" + set_up_lib_search_paths "$iconv_build_dir" \ + "$gmp_build_dir" \ + "$mpfr_build_dir" \ + "$ncursesw_build_dir" \ + "$libexpat_build_dir" if [[ "$with_python" == "yes" ]]; then local gdb_python_dir="$packages_dir/binutils-gdb/gdb/python/lib/" @@ -667,10 +696,10 @@ function build_gdb_with_dependencies() { fi build_and_install_gdb "$packages_dir/binutils-gdb" \ - "$iconv_build_dir/lib/.libs/" \ + "$iconv_build_dir" \ "$lzma_build_dir/usr/local/" \ - "$gmp_build_dir/.libs/" \ - "$mpfr_build_dir/src/.libs/" \ + "$gmp_build_dir" \ + "$mpfr_build_dir" \ "$with_python" \ "$artifacts_dir" \ "$target_arch" From ebaaa216d986aad52e2406922f92c296a722dea2 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 16:27:29 +0300 Subject: [PATCH 06/14] build: Install musl-based toolchains in the docker. --- Dockerfile | 17 ++++- Makefile | 2 +- src/docker_utils/download_musl_toolchains.py | 80 ++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100755 src/docker_utils/download_musl_toolchains.py diff --git a/Dockerfile b/Dockerfile index 43f8daa..6f6f050 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM ubuntu:24.04 -# Install dependencies -RUN apt update && apt install -y \ +RUN apt update + +RUN apt install -y \ bison \ file \ flex \ @@ -18,16 +19,26 @@ RUN apt update && apt install -y \ gcc-mipsel-linux-gnu \ gcc-powerpc-linux-gnu \ git \ - libncurses-dev \ libtool \ m4 \ make \ patch \ pkg-config \ python3.12 \ + python3-pip \ libpython3-dev \ texinfo \ wget \ xz-utils +# Remove externally-managed constrainsts since we run inside a docker... +RUN rm -f /usr/lib/python3.*/EXTERNALLY-MANAGED +RUN python3.12 -m pip install requests + +COPY src/docker_utils/download_musl_toolchains.py . +RUN python3.12 -u download_musl_toolchains.py + WORKDIR /app/gdb + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["bash"] diff --git a/Makefile b/Makefile index 8e2a8d4..10d4432 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ help: @echo "" @echo " make clean" -build/build-docker-image.stamp: Dockerfile +build/build-docker-image.stamp: Dockerfile src/docker_utils/download_musl_toolchains.py mkdir -p build docker buildx build --tag gdb-static . touch build/build-docker-image.stamp diff --git a/src/docker_utils/download_musl_toolchains.py b/src/docker_utils/download_musl_toolchains.py new file mode 100755 index 0000000..8f0d88a --- /dev/null +++ b/src/docker_utils/download_musl_toolchains.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3.12 + +import requests +import tarfile +import os +import shutil + +from pathlib import Path + +ARCHS = { + "x86_64" : "https://musl.cc/x86_64-linux-musl-cross.tgz", + "arm" : "https://musl.cc/arm-linux-musleabi-cross.tgz", + "aarch64" : "https://musl.cc/aarch64-linux-musl-cross.tgz", + "powerpc" : "https://musl.cc/powerpc-linux-musl-cross.tgz", + "mips" : "https://musl.cc/mips-linux-musl-cross.tgz", + "mipsel" : "https://musl.cc/mipsel-linux-musl-cross.tgz", +} +CHUNK_SIZE = 65536 +MUSL_TOOLCHAINS_DIR = Path("/musl-toolchains") +ENTRYPOINT = "/entrypoint.sh" + +def download_file(url: str, filename: str): + print(f"Downloading {filename}") + with requests.get(url, stream=True) as r: + r.raise_for_status() + with open(filename, "wb") as f: + for chunk in r.iter_content(chunk_size=CHUNK_SIZE): + f.write(chunk) + print(f"{filename} downloaded.") + +def extract_tarball(filename: str, dst: Path): + print(f"Extracting {filename}") + with tarfile.open(filename, "r:gz") as tar: + tar.extractall(path=dst) + print(f"{filename} extracted") + +def add_to_path(curr_path: str, package_path: Path): + return curr_path + ":" + str((package_path / "bin").resolve()) + + +def main(): + os.mkdir(MUSL_TOOLCHAINS_DIR) + + updated_path = "$PATH" + for arch, url in ARCHS.items(): + filename = url.split("/")[-1] + download_file(url, filename) + extract_tarball(filename, MUSL_TOOLCHAINS_DIR) + updated_path = add_to_path(updated_path, MUSL_TOOLCHAINS_DIR / filename.removesuffix(".tgz")) + + # Fix the x86_64 dynamic loader if needed: + # Unfortunately, the internal gdb build scripts builds some binaries (that generate documentation) + # in a dynamic manner. + # + # Because we may use a musl-based toolchain, this means that we need to set-up the dynamic loader. + # The fix may seem a little hacky, but it is simple, and is the best we can do. + if "x86_64" in ARCHS: + x86_toolchain_name = ARCHS["x86_64"].split("/")[-1].removesuffix(".tgz") + x86_toolchain_path = MUSL_TOOLCHAINS_DIR / x86_toolchain_name + x86_loader_path = x86_toolchain_path / "x86_64-linux-musl" / "lib" / "libc.so" + shutil.copy2(x86_loader_path, "/lib/ld-musl-x86_64.so.1") + + # Create the entrypoint with the updated path. + with open(ENTRYPOINT, mode="w") as f: + f.write( +f"""#!/usr/bin/env bash +export PATH="{updated_path}" +exec "$@" +""") + + # Make sure we can execute the entrypoint. + os.chmod(ENTRYPOINT, 0o755) + + # Append the path to bash.bashrc so that other users will have these paths. + with open("/etc/bash.bashrc", mode="a") as f: + f.write(f"\nexport PATH=\"{updated_path}\"") + + +if __name__ == "__main__": + main() From b76a21929156293cd5476330f5805a421aa1ebf4 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 16:45:50 +0300 Subject: [PATCH 07/14] build: run docker in interactive tty mode only when avaliable cicd does not have a tty device, but when a user is compiling, we would like to offer him a tty interface (so that he could cancel builds, for example). --- .github/workflows/pr-pipeline.yaml | 3 +++ .github/workflows/release-pipeline.yaml | 5 ++++- Makefile | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-pipeline.yaml b/.github/workflows/pr-pipeline.yaml index 44bdf61..6dbc0f8 100644 --- a/.github/workflows/pr-pipeline.yaml +++ b/.github/workflows/pr-pipeline.yaml @@ -7,6 +7,9 @@ on: jobs: build: + env: + TTY_ARG: "" # Disable interactive build mode in cicd since it does not contain a tty device. + strategy: matrix: build_type: ["build", "build-with-python"] diff --git a/.github/workflows/release-pipeline.yaml b/.github/workflows/release-pipeline.yaml index 671b05a..0219596 100644 --- a/.github/workflows/release-pipeline.yaml +++ b/.github/workflows/release-pipeline.yaml @@ -9,6 +9,9 @@ on: # simply build the files in the same job they are released. jobs: build_and_publish: + env: + TTY_ARG: "" # Disable interactive build mode in cicd since it does not contain a tty device. + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -27,4 +30,4 @@ jobs: - name: Publish release uses: softprops/action-gh-release@v2 with: - files: build/artifacts/gdb-static*.tar.gz \ No newline at end of file + files: build/artifacts/gdb-static*.tar.gz diff --git a/Makefile b/Makefile index 10d4432..4efc9e1 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ ALL_PACK_TARGETS := $(PACK_TARGETS) $(PYTHON_PACK_TARGETS) SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*) BUILD_PACKAGES_DIR := "build/packages" +# We would like to run in interactive mode when avaliable (non-ci usually). +# This is disabled by the ci automation manually. +TTY_ARG ?= -it + .PHONY: clean help download_packages build build-docker-image $(ALL_TARGETS) $(ALL_PACK_TARGETS) .NOTPARALLEL: build pack @@ -36,7 +40,7 @@ build-docker-image: build/build-docker-image.stamp build/download-packages.stamp: build/build-docker-image.stamp src/compilation/download_packages.sh mkdir -p $(BUILD_PACKAGES_DIR) - docker run -it --user $(shell id -u):$(shell id -g) \ + docker run $(TTY_ARG) --user $(shell id -u):$(shell id -g) \ --rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \ /app/gdb/src/compilation/download_packages.sh /app/gdb/$(BUILD_PACKAGES_DIR)/ touch build/download-packages.stamp @@ -59,7 +63,7 @@ $(PYTHON_TARGETS): build-with-python-%: _build-%: symlink-git-packages download-packages build-docker-image mkdir -p build - docker run -it --user $(shell id -u):$(shell id -g) \ + docker run $(TTY_ARG) --user $(shell id -u):$(shell id -g) \ --rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \ /app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON) From dc290acd7463c7aa81ef1db9233fd143ab5ef184 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 17:07:12 +0300 Subject: [PATCH 08/14] build: Install binutils-multiarch in the dockerfile We needed it for cross-installation of ncrusesw --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 6f6f050..d7d2f6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM ubuntu:24.04 RUN apt update RUN apt install -y \ + binutils-multiarch \ bison \ file \ flex \ From 48ebbda3267935cbb684e40cd6684b7e648031e7 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 21:05:37 +0300 Subject: [PATCH 09/14] build: Use different varients of musl compilers The generic musl arm compiler in the musl.cc website is bugged - so i downgraded the arm compiler to gcc-10, which seems to work. --- src/docker_utils/download_musl_toolchains.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/docker_utils/download_musl_toolchains.py b/src/docker_utils/download_musl_toolchains.py index 8f0d88a..4fa015b 100755 --- a/src/docker_utils/download_musl_toolchains.py +++ b/src/docker_utils/download_musl_toolchains.py @@ -8,12 +8,12 @@ from pathlib import Path ARCHS = { - "x86_64" : "https://musl.cc/x86_64-linux-musl-cross.tgz", - "arm" : "https://musl.cc/arm-linux-musleabi-cross.tgz", - "aarch64" : "https://musl.cc/aarch64-linux-musl-cross.tgz", - "powerpc" : "https://musl.cc/powerpc-linux-musl-cross.tgz", - "mips" : "https://musl.cc/mips-linux-musl-cross.tgz", - "mipsel" : "https://musl.cc/mipsel-linux-musl-cross.tgz", + "x86_64" : "https://more.musl.cc/11/x86_64-linux-musl/x86_64-linux-musl-cross.tgz", + "arm" : "https://more.musl.cc/10/x86_64-linux-musl/arm-linux-musleabi-cross.tgz", + "aarch64" : "https://more.musl.cc/11/x86_64-linux-musl/aarch64-linux-musl-cross.tgz", + "powerpc" : "https://more.musl.cc/11/x86_64-linux-musl/powerpc-linux-musl-cross.tgz", + "mips" : "https://more.musl.cc/11/x86_64-linux-musl/mips-linux-musl-cross.tgz", + "mipsel" : "https://more.musl.cc/11/x86_64-linux-musl/mipsel-linux-musl-cross.tgz", } CHUNK_SIZE = 65536 MUSL_TOOLCHAINS_DIR = Path("/musl-toolchains") From 90f2f42b10f2cd55a733e7e623d65c158458a4dc Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 18 Apr 2025 21:40:21 +0300 Subject: [PATCH 10/14] Update the gdb-submodule with a fix to mips compilation on musl --- src/submodule_packages/binutils-gdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/submodule_packages/binutils-gdb b/src/submodule_packages/binutils-gdb index 25f97cc..6103f49 160000 --- a/src/submodule_packages/binutils-gdb +++ b/src/submodule_packages/binutils-gdb @@ -1 +1 @@ -Subproject commit 25f97ccb7ff1a9d7bd0e25535d749acf6e1a87be +Subproject commit 6103f4984ba5824d340dd6801ab8244785fb8c53 From 19a1a55876fc787e35765ed9383bd3a9a6d8f8b5 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 25 Apr 2025 12:27:49 +0300 Subject: [PATCH 11/14] build: Install the requests system-package instead of pip --- Dockerfile | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index d7d2f6f..6a5e703 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM ubuntu:24.04 -RUN apt update - -RUN apt install -y \ +RUN apt update && apt install -y \ binutils-multiarch \ bison \ file \ @@ -27,15 +25,12 @@ RUN apt install -y \ pkg-config \ python3.12 \ python3-pip \ + python3-requests \ libpython3-dev \ texinfo \ wget \ xz-utils -# Remove externally-managed constrainsts since we run inside a docker... -RUN rm -f /usr/lib/python3.*/EXTERNALLY-MANAGED -RUN python3.12 -m pip install requests - COPY src/docker_utils/download_musl_toolchains.py . RUN python3.12 -u download_musl_toolchains.py From 9ca41da80bfa751d3e5103ba37bb976d354c91b3 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 25 Apr 2025 12:28:33 +0300 Subject: [PATCH 12/14] build: cleaner path variable update --- src/docker_utils/download_musl_toolchains.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/docker_utils/download_musl_toolchains.py b/src/docker_utils/download_musl_toolchains.py index 4fa015b..b7b3376 100755 --- a/src/docker_utils/download_musl_toolchains.py +++ b/src/docker_utils/download_musl_toolchains.py @@ -35,13 +35,16 @@ def extract_tarball(filename: str, dst: Path): print(f"{filename} extracted") def add_to_path(curr_path: str, package_path: Path): - return curr_path + ":" + str((package_path / "bin").resolve()) + new_path = str((package_path / "bin").resolve()) + if curr_path != "": + return new_path + ":" + curr_path + return new_path def main(): os.mkdir(MUSL_TOOLCHAINS_DIR) - updated_path = "$PATH" + updated_path = "" for arch, url in ARCHS.items(): filename = url.split("/")[-1] download_file(url, filename) @@ -64,7 +67,7 @@ def main(): with open(ENTRYPOINT, mode="w") as f: f.write( f"""#!/usr/bin/env bash -export PATH="{updated_path}" +export PATH="$PATH:{updated_path}" exec "$@" """) @@ -73,7 +76,7 @@ def main(): # Append the path to bash.bashrc so that other users will have these paths. with open("/etc/bash.bashrc", mode="a") as f: - f.write(f"\nexport PATH=\"{updated_path}\"") + f.write(f"\nexport PATH=\"$PATH:{updated_path}\"") if __name__ == "__main__": From 90ef1dd1e3cc34a09a1e6f27f1eba08fb42e060e Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 25 Apr 2025 13:28:01 +0300 Subject: [PATCH 13/14] build: build xz from a submodule We also install xz to the build directory, for a cleaner setup. --- .gitmodules | 3 +++ Dockerfile | 2 +- src/compilation/build.sh | 14 +++++++++++--- src/compilation/download_packages.sh | 1 - src/submodule_packages/xz | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) create mode 160000 src/submodule_packages/xz diff --git a/.gitmodules b/.gitmodules index cb981e5..1e29ea0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,3 +12,6 @@ [submodule "src/submodule_packages/libexpat"] path = src/submodule_packages/libexpat url = git@github.com:guyush1/libexpat.git +[submodule "xz"] + path = src/submodule_packages/xz + url = https://github.com/tukaani-project/xz.git diff --git a/Dockerfile b/Dockerfile index 6a5e703..a84d3c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:24.04 RUN apt update && apt install -y \ + autopoint \ binutils-multiarch \ bison \ file \ @@ -24,7 +25,6 @@ RUN apt update && apt install -y \ patch \ pkg-config \ python3.12 \ - python3-pip \ python3-requests \ libpython3-dev \ texinfo \ diff --git a/src/compilation/build.sh b/src/compilation/build.sh index 4e189cf..dcc6d13 100755 --- a/src/compilation/build.sh +++ b/src/compilation/build.sh @@ -154,7 +154,7 @@ function build_lzma() { echo "$lzma_build_dir" mkdir -p "$lzma_build_dir" - if [[ -f "$lzma_build_dir/usr/local/lib/liblzma.a" ]]; then + if [[ -f "$lzma_build_dir/lib/liblzma.a" ]]; then >&2 echo "Skipping build: lzma already built for $target_arch" return 0 fi @@ -163,8 +163,16 @@ function build_lzma() { >&2 fancy_title "Building liblzma for $target_arch" + # Make sure configure exists by running autogen.sh + ( + cd .. && ./autogen.sh 1>&2 + ) + + # lzma's autoconf contains a bug, it's instal prefix is relative + # to the current build directory. + # Hence, we set the prefix here to "/" instead of realpath . . ../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \ - "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2 + "CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" --prefix="/" 1>&2 if [[ $? -ne 0 ]]; then return 1 fi @@ -697,7 +705,7 @@ function build_gdb_with_dependencies() { build_and_install_gdb "$packages_dir/binutils-gdb" \ "$iconv_build_dir" \ - "$lzma_build_dir/usr/local/" \ + "$lzma_build_dir" \ "$gmp_build_dir" \ "$mpfr_build_dir" \ "$with_python" \ diff --git a/src/compilation/download_packages.sh b/src/compilation/download_packages.sh index a212710..ff630cb 100755 --- a/src/compilation/download_packages.sh +++ b/src/compilation/download_packages.sh @@ -10,7 +10,6 @@ SOURCE_URLS=( "https://ftp.gnu.org/pub/gnu/gmp/gmp-6.3.0.tar.xz" "https://ftp.gnu.org/pub/gnu/mpfr/mpfr-4.2.1.tar.xz" "https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz" - "https://github.com/tukaani-project/xz/releases/download/v5.8.1/xz-5.8.1.tar.xz" ) function unpack_tarball() { diff --git a/src/submodule_packages/xz b/src/submodule_packages/xz new file mode 160000 index 0000000..56aa9a0 --- /dev/null +++ b/src/submodule_packages/xz @@ -0,0 +1 @@ +Subproject commit 56aa9a07968a6a73fada6f9b96122c5165829f3b From b59e10d22aff4c8d067ba4bf32df2ab085c31f37 Mon Sep 17 00:00:00 2001 From: Guy Shimko Date: Fri, 25 Apr 2025 13:38:12 +0300 Subject: [PATCH 14/14] docs: Update README and compilation documentation --- README.md | 1 + compilation.md | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4579082..bdd63cd 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ This is where `gdb-static` comes in! We provide static builds of `gdb` (and `gdb
- **Static Builds**: No dependencies, no installation, just download and run! +- **Musl Based**: We use Musl in order to create distribution-independant binaries that can work anywhere. - **Latest Versions**: We keep our builds up-to-date with the latest versions of GDB. - **Builtin Python (Optional)**: We provide builds with Python support built-in. - **XML Support**: Our builds come with XML support built-in, which is useful for some GDB commands. diff --git a/compilation.md b/compilation.md index 6a39dc2..dbbcaf3 100644 --- a/compilation.md +++ b/compilation.md @@ -14,13 +14,15 @@ Please note that when specifying a compilation dir throughout the compilation pr Instead, always use absolute paths. Examples to the throughout the script: -- - arm-linux-gnueabi-gcc -- - arm-linux-gnueabi-g++ -- - arm-linux-gnueabi +- - arm-linux-musleabi-gcc +- - arm-linux-musleabi-g++ +- - arm-linux-musleabi - - /home/username/projects/libgmp-x.y.z/build-arm/ -Environment info: -- glibc version: 2.39-0ubuntu8.3 (NOTE: When i compiled gdb using an older glibc, such as the one i had in my ubuntu-20.04 machine, i received a segfault in gdb, so the libc version is important!). +## Choosing the right compiler + +It is recommended to use a musl-based compiler. Unlike glibc, musl is not dependant on your distribution. +Using regular gcc that is glibc based should work most of the time, but we had some people reporting crashes mainly in gdbserver, so we switched to musl-based toolchains. # Compiling gdb statically to the host platform