19 Commits

Author SHA1 Message Date
6738cedefc automation: build python targets in pipeline ci-cd
done using a 2d matrix involving the build type (regular or with python)
2024-12-30 23:21:17 +02:00
5359ff1116 build: Allow building gdb with and without python 2024-12-30 23:21:17 +02:00
17346caf10 Merge pull request #23 from guyush1/reduce-static-python-size
reduce static gdb python size
2024-12-25 23:46:36 +02:00
aa49ade8d4 Strip the executables in order to reduce their size 2024-12-25 21:35:03 +02:00
1dfe3fa6ca Reduce static-gdb size by reducing python size
Updated the python submodule.
The newer submodule will create smaller static python libraries.
2024-12-25 21:35:03 +02:00
c44e67540a Added X64 build prefix
There's no real reason to assume the host machine is X64.
2024-12-21 13:50:39 +02:00
a0ceeff014 Added parallel build to PR workflow
Using a matrix and job separation we can make the architectures compile
parallel to eachother, hopefully reducing the time required for builds
and also simplifying the process of building a single architecture.

A problem that we encountered is that with Python the resulting packed
tars are very large. Each release is in the order of tens of megabytes.
Using artifacts in our pipeline can easily make us surpass the maximum
size limit for free GitHub accounts (500 MB).
Because of this, we use the regular non-parallel pipeline for release
build. Releasing the version from the same job the build was performed
in allows us to directly access the build files instead of using
artifacts.

Separated release and MR pipelines.
2024-12-21 13:50:39 +02:00
0a60aedf76 Added submodule checkout to automation 2024-12-21 13:26:37 +02:00
ff0d3ad28f Added -e flag to bash build.sh
We want audible fails
2024-12-21 13:26:37 +02:00
c86f506e90 Add submodules to build/packages
Using symlinks the submodules are added to appear just like any
downloaded unpacked tar.

Also added a Makefile clean rule to clean the submodules, which
includes Reseting the submodules to the origin branch state,
including ignored files.
2024-12-21 13:26:37 +02:00
46e8eb22a8 Added static-python and static gdb submodules 2024-12-21 13:26:37 +02:00
fa04d3a7a2 gdb with python support integration
This commits enables gdb's python support. In order to make it work, we
had to create a python fork with some patches to the buildsystem, and
also had to patch gdb as well.
2024-12-21 13:26:37 +02:00
dc882d9598 Merge pull request #14 from guyush1/enable-tui-statically
add tui to gdb
2024-11-11 08:18:37 +02:00
d55a31bb5e build: build gdb with tui mode enabled
This was acheived by forcing gdb to use our own static libncurses
2024-11-10 23:22:56 +02:00
a962fbb441 build: download the ncurses package 2024-11-10 23:22:56 +02:00
d5e1dbb011 Merge pull request #13 from guyush1/add-mips-mipsel
build: add mips & mipsel targets
2024-11-10 23:22:32 +02:00
8dc07deb66 build: add mips & mipsel targets 2024-11-10 22:26:05 +02:00
3738fc8629 Merge pull request #11 from guyush1/improve-documentation
documentation: improve the readme file
2024-11-10 22:21:41 +02:00
fe4c0763e8 documentation: split & improve the readme file
This commit splits the readme file into 2 files - the readme which
contains instructions on how to download our latest release, and on how
to use our build scripts in order to quickly build gdb statically. The
second file is a compilation guide that contains explanations on how to
manually compile gdb statically.
2024-11-08 13:02:19 +02:00
14 changed files with 395 additions and 289 deletions

25
.github/workflows/pr-pipeline.yaml vendored Normal file
View File

@ -0,0 +1,25 @@
name: gdb-static-pr-pipeline
on:
pull_request:
branches:
- '*'
jobs:
build:
strategy:
matrix:
build_type: ["build", "build-with-python"]
architecture: ["x86_64", "arm", "aarch64", "powerpc", "mips", "mipsel"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: sudo apt-get install -y wget
- name: Build
run: make ${{ matrix.build_type }}-${{ matrix.architecture }} -j$((`nproc`+1))

View File

@ -1,19 +1,19 @@
name: gdb-static-pipeline
name: gdb-static-release-pipeline
on:
pull_request:
branches:
- '*'
push:
tags:
- 'v*'
# Use a non-parallel single job pipeline because artifacts weigh too much. Instead,
# simply build the files in the same job they are released.
jobs:
build:
build_and_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: sudo apt-get install -y wget
@ -24,14 +24,7 @@ jobs:
- name: Pack
run: make pack
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: gdb-static
path: build/artifacts/gdb-static*.tar.gz
- name: Publish release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
files: build/artifacts/gdb-static*.tar.gz
files: build/artifacts/gdb-static*.tar.gz

8
.gitmodules vendored Normal file
View File

@ -0,0 +1,8 @@
[submodule "cpython-static"]
path = src/submodule_packages/cpython-static
url = git@github.com:guyush1/cpython-static.git
branch = python3.12-static
[submodule "binutils-gdb-static"]
path = src/submodule_packages/binutils-gdb
url = git@github.com:guyush1/binutils-gdb.git
branch = gdb-static

View File

@ -2,17 +2,29 @@ FROM ubuntu:24.04
# Install dependencies
RUN apt update && apt install -y \
bison \
file \
flex \
g++ \
g++-aarch64-linux-gnu \
g++-arm-linux-gnueabi \
g++-mips-linux-gnu \
g++-mipsel-linux-gnu \
g++-powerpc-linux-gnu \
gcc \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-mips-linux-gnu \
gcc-mipsel-linux-gnu \
gcc-powerpc-linux-gnu \
git \
libncurses-dev \
m4 \
make \
patch \
pkg-config \
python3.12 \
libpython3-dev \
texinfo \
wget \
xz-utils

View File

@ -1,15 +1,24 @@
ARCHS := x86_64 arm aarch64 powerpc
TARGETS := $(addprefix build-, $(ARCHS))
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
.PHONY: clean help download_packages build patch-gdb build-docker-image $(TARGETS) $(PACK_TARGETS)
TARGETS := $(addprefix build-, $(ARCHS))
PYTHON_TARGETS := $(addprefix build-with-python-, $(ARCHS))
ALL_TARGETS := $(TARGETS) $(PYTHON_TARGETS)
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
PYTHON_PACK_TARGETS := $(addprefix pack-with-python-, $(ARCHS))
ALL_PACK_TARGETS := $(PACK_TARGETS) $(PYTHON_PACK_TARGETS)
SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*)
BUILD_PACKAGES_DIR := "build/packages"
.PHONY: clean help download_packages build build-docker-image $(ALL_TARGETS) $(ALL_PACK_TARGETS)
help:
@echo "Usage:"
@echo " make build"
@echo ""
@for target in $(TARGETS); do \
@for target in $(ALL_TARGETS); do \
echo " $$target"; \
done
@ -18,44 +27,57 @@ help:
build/build-docker-image.stamp: Dockerfile
mkdir -p build
docker build -t gdb-static .
docker buildx build --tag gdb-static .
touch build/build-docker-image.stamp
build-docker-image: build/build-docker-image.stamp
build/download-packages.stamp: build/build-docker-image.stamp src/download_packages.sh
mkdir -p build/packages
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) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/download_packages.sh /app/gdb/build/packages
/app/gdb/src/compilation/download_packages.sh /app/gdb/$(BUILD_PACKAGES_DIR)/
touch build/download-packages.stamp
build/symlink-git-packages.stamp: $(SUBMODULE_PACKAGES)
mkdir -p $(BUILD_PACKAGES_DIR)
ln -sf $(addprefix /app/gdb/, $(SUBMODULE_PACKAGES)) $(BUILD_PACKAGES_DIR)/
symlink-git-packages: build/symlink-git-packages.stamp
download-packages: build/download-packages.stamp
build/patch-gdb.stamp: build/build-docker-image.stamp src/gdb_static.patch build/download-packages.stamp
docker run --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/patch_gdb.sh /app/gdb/build/packages/gdb /app/gdb/src/gdb_static.patch
touch build/patch-gdb.stamp
build: $(ALL_TARGETS)
patch-gdb: build/patch-gdb.stamp
$(TARGETS): build-%:
@$(MAKE) _build-$*
build: $(TARGETS)
$(PYTHON_TARGETS): build-with-python-%:
@WITH_PYTHON="--with-python" $(MAKE) _build-$*
$(TARGETS): build-%: download-packages patch-gdb build-docker-image
_build-%: symlink-git-packages download-packages build-docker-image
mkdir -p build
docker run --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src/gdb_static.patch
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON)
pack: $(PACK_TARGETS)
pack: $(ALL_PACK_TARGETS)
$(PACK_TARGETS): pack-%: build-%
if [ ! -f "build/artifacts/gdb-static-$*.tar.gz" ]; then \
tar -czf "build/artifacts/gdb-static-$*.tar.gz" -C "build/artifacts/$*" .; \
$(PACK_TARGETS): pack-%:
@$(MAKE) _pack-$*
$(PYTHON_PACK_TARGETS): pack-with-python-%:
@TAR_EXT="with-python-" ARTIFACT_EXT="_with_python" $(MAKE) _pack-$*
_pack-%: build-%
if [ ! -f "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" ]; then \
tar -czf "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" -C "build/artifacts/$*$(ARTIFACT_EXT)" .; \
fi
clean:
clean-git-packages:
git submodule foreach '[[ ! "$$sm_path" == src/submodule_packages/* ]] || git clean -xffd'
clean: clean-git-packages
rm -rf build
# Kill and remove all containers of image gdb-static
docker ps -a | grep -P "^[a-f0-9]+\s+gdb-static\s+" | awk '{print $$1}' | xargs docker rm -f 2>/dev/null || true

106
README.md
View File

@ -1,8 +1,12 @@
# Repository of static gdb and gdbserver
The statically compiled gdb / gdbserver binaries are avaliable to download under github releases!
## **The statically compiled gdb / gdbserver binaries are avaliable to download under github releases!**
# Compiling gdb using docker
link: [gdb-static github releases](https://github.com/guyush1/gdb-static/releases)
## For manual gdb/gdbserver compilation instructions, have a look at the compilation.md file
## Compiling gdb using docker
This repository contains a dockerfile and build scripts to compile gdb and gdbserver statically for multiple architectures.
Currently, the supported architectures are:
@ -14,7 +18,7 @@ You can easily expand it to support more architectures by adding the appropriate
NOTE: You don't need to interact with the dockerfile directly, as the Makefile will take care of everything for you.
## Building for a specific architecture
### Building for a specific architecture
To build for a specific architecture, you can use the following command:
```bash
@ -35,108 +39,16 @@ build/
...
```
## Building for all architectures
### Building for all architectures
To build for all architectures, you can use the following command:
```bash
make build
```
## Cleaning the build
### Cleaning the build
To clean the build, you can use the following command:
```bash
make clean
```
# Notes about this file - read before proceeding!
While i already provided the gdb/gdbserver-15 statically compiled binaries handed out to you, some people might want to compile it to a different architecture, or compile a newer version of gdb in the future :). This rest of the file contains my compilation documentation so that you could save yourself some time and do it yourself, if you wish.
## <VARAIBLES> in the script
When specifying the compilation dir throughout the compilation process (specified as <COMPILATION_DIR_PATH> in this file), DO NOT use relative pathing, or bash characters such as `~`. They will not get parsed correctly! Instead, use absolute paths only.
Examples to the <VARIABLES> throughout the script:
<CROSS_COMPILER_C> - arm-linux-gnueabi-gcc
<CROSS_COMPILER_CPP> - arm-linux-gnueabi-g++
<HOST_NAME> - arm-linux-gnueabi
<COMPILATION_DIR_PATH> - /home/username/projects/libgmp-x.y.z/build-arm/
Environment info:
- glibc version: 2.39-0ubuntu8.3 (NOTE: When i compiled gdb-15 using an older glibc, such as the one i had in my ubuntu-20.04 machine, i received a segfault in gdb...).
# Compiling gdb statically to the host platform
## 1) Compiling iconv
While compiling iconv is not a must, the libc-provided iconv (a utility to convert between encodings) may fail on different architectures,
at least in my experiance. Thus, I recommended using a custom libiconv and compiling it into gdb.
Download the source from https://github.com/roboticslibrary/libiconv.git
Make sure to check out to a stable tag (in my case - v1.17).
Work according to the following steps:
I) run `./gitsub.sh pull`
II) run `./autogen.sh` to create the configure script from configure.sh.
III) create a build dir (e.g build), and then cd into it.
IV) run `../configure --enable-static`
V) run `cp -r ./include ./lib/.libs/`
VI) run `mkdir ./lib/.libs/lib/`
VII) run `cp ./lib/.libs/libiconv.a ./lib/.libs/lib/`
## 2) Compiling gdb
Clone gdb from sourceware - https://sourceware.org/git/binutils-gdb.git.
I checked out to the 15.2 tag.
Work according to the following steps:
I) Apply my patches (gdb_static.patch). If you are not on the exact tag i used (15.2) - you might need to apply them manually, and change some stuff.
II) create a build dir.
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static`
IV) run `make all-gdb -j$(nproc)` - for gdbserver, run `make all-gdbserver -j$(nproc)`.
gdb will sit under gdb/gdb.
gdbserver will sit under gdbserver/gdbserver.
# Cross compiling gdb statically to other architectures.
Cross compiling gdb statically is a bit more complicated then regular static compilation. In order to cross compile gdb statically, we will need to compile libgmp and libmpfr as well as iconv.
## 1) Compiling iconv
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
IV) run `../configure --enable-static CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
## 2) Compiling libgmp
Download and extract the latest edition from https://gmplib.org/.
I used the 6.3.0 edition.
Work according to the following steps:
I) Create a build dir and cd into it.
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --host=<HOST_NAME>`
III) run `make -j$(nproc)`
IV) run `mkdir ./.libs/include/`
V) run `cp gmp.h ./.libs/include/`
VI) run `mkdir ./.libs/lib`
VII) run `cp ./.libs/libgmp.a ./.libs/lib`
## 3) Compiling libmpfr
Download and extract the latest edition from https://www.mpfr.org/.
I used the 4.2.1 edition.
Work according to the following steps:
I) Create a build dir and cd into it.
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --with-gmp-build=<COMPILATION_DIR_PATH> --host=<HOST_NAME>`
III) run `make -j$(nproc)`
IV) run `mkdir ./src/.libs/lib`
V) run `cp ./src/.libs/libmpfr.a ./src/.libs/lib`
VI) run `mkdir ./src/.libs/include`
VII) run `cp ../src/mpfr.h ./src/.libs/include/`
## 4) Compiling gdb
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static --with-gmp=<COMPILATION_DIR_PATH>/.libs/ --with-mpfr=<COMPILATION_DIR_PATH>/src/.libs/ CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`

91
compilation.md Normal file
View File

@ -0,0 +1,91 @@
# Notes about this file - read before proceeding!
While i have already provided the gdb/gdbserver-15 statically compiled binaries for you, some people might want to compile it to a different architecture (without our build scripts), or compile a newer version of gdb in the future :). The rest of the file contains a documentation of the compilation process, in order to help you out.
## <VARAIBLES> in the script
When specifying the compilation dir throughout the compilation process (specified as <COMPILATION_DIR_PATH> in this file), DO NOT use relative pathing, or bash characters such as `~`. They will not get parsed correctly! Instead, use absolute paths only.
Examples to the <VARIABLES> throughout the script:
<CROSS_COMPILER_C> - arm-linux-gnueabi-gcc
<CROSS_COMPILER_CPP> - arm-linux-gnueabi-g++
<HOST_NAME> - arm-linux-gnueabi
<COMPILATION_DIR_PATH> - /home/username/projects/libgmp-x.y.z/build-arm/
Environment info:
- glibc version: 2.39-0ubuntu8.3 (NOTE: When i compiled gdb-15 using an older glibc, such as the one i had in my ubuntu-20.04 machine, i received a segfault in gdb...).
# Compiling gdb statically to the host platform
## 1) Compiling iconv
While compiling iconv is not a must, the libc-provided iconv (a utility to convert between encodings) may fail on different architectures,
at least in my experiance. Thus, I recommended using a custom libiconv and compiling it into gdb.
Download the source from https://github.com/roboticslibrary/libiconv.git
Make sure to check out to a stable tag (in my case - v1.17).
Work according to the following steps:
I) run `./gitsub.sh pull`
II) run `./autogen.sh` to create the configure script from configure.sh.
III) create a build dir (e.g build), and then cd into it.
IV) run `../configure --enable-static`
V) run `cp -r ./include ./lib/.libs/`
VI) run `mkdir ./lib/.libs/lib/`
VII) run `cp ./lib/.libs/libiconv.a ./lib/.libs/lib/`
## 2) Compiling gdb
Clone gdb from sourceware - https://sourceware.org/git/binutils-gdb.git.
I checked out to the 15.2 tag.
Work according to the following steps:
I) Apply my patches (gdb_static.patch). If you are not on the exact tag i used (15.2) - you might need to apply them manually, and change some stuff.
II) create a build dir.
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static`
IV) run `make all-gdb -j$(nproc)` - for gdbserver, run `make all-gdbserver -j$(nproc)`.
gdb will sit under gdb/gdb.
gdbserver will sit under gdbserver/gdbserver.
# Cross compiling gdb statically to other architectures.
Cross compiling gdb statically is a bit more complicated then regular static compilation. In order to cross compile gdb statically, we will need to compile libgmp and libmpfr as well as iconv.
## 1) Compiling iconv
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
IV) run `../configure --enable-static CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
## 2) Compiling libgmp
Download and extract the latest edition from https://gmplib.org/.
I used the 6.3.0 edition.
Work according to the following steps:
I) Create a build dir and cd into it.
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --host=<HOST_NAME>`
III) run `make -j$(nproc)`
IV) run `mkdir ./.libs/include/`
V) run `cp gmp.h ./.libs/include/`
VI) run `mkdir ./.libs/lib`
VII) run `cp ./.libs/libgmp.a ./.libs/lib`
## 3) Compiling libmpfr
Download and extract the latest edition from https://www.mpfr.org/.
I used the 4.2.1 edition.
Work according to the following steps:
I) Create a build dir and cd into it.
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --with-gmp-build=<COMPILATION_DIR_PATH> --host=<HOST_NAME>`
III) run `make -j$(nproc)`
IV) run `mkdir ./src/.libs/lib`
V) run `cp ./src/.libs/libmpfr.a ./src/.libs/lib`
VI) run `mkdir ./src/.libs/include`
VII) run `cp ../src/mpfr.h ./src/.libs/include/`
## 4) Compiling gdb
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static --with-gmp=<COMPILATION_DIR_PATH>/.libs/ --with-mpfr=<COMPILATION_DIR_PATH>/src/.libs/ CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`

View File

@ -2,7 +2,10 @@
# Include utils library
script_dir=$(dirname "$0")
. "$script_dir/utils.sh"
source "$script_dir/utils.sh"
# Don't want random unknown things to fail in the build procecss!
set -e
function set_compliation_variables() {
# Set compilation variables such as which compiler to use.
@ -13,7 +16,7 @@ function set_compliation_variables() {
# Returns:
# 0: success
# 1: failure
supported_archs=("arm" "aarch64" "powerpc" "x86_64")
supported_archs=("arm" "aarch64" "powerpc" "x86_64" "mips" "mipsel")
local target_arch="$1"
@ -33,8 +36,14 @@ function set_compliation_variables() {
elif [[ "$target_arch" == "powerpc" ]]; then
CROSS=powerpc-linux-gnu-
export HOST=powerpc-linux-gnu
elif [[ "$target_arch" == "mips" ]]; then
CROSS=mips-linux-gnu-
export HOST=mips-linux-gnu
elif [[ "$target_arch" == "mipsel" ]]; then
CROSS=mipsel-linux-gnu-
export HOST=mipsel-linux-gnu
elif [[ "$target_arch" == "x86_64" ]]; then
CROSS=""
CROSS=x86_64-linux-gnu-
export HOST=x86_64-linux-gnu
fi
@ -43,6 +52,20 @@ function set_compliation_variables() {
export CFLAGS="-O2"
export CXXFLAGS="-O2"
# Strip the binary to reduce it's size.
export LDFLAGS="-s"
}
function set_ncurses_link_variables() {
# Set up ncurses library link variables
#
# Parameters:
# $1: ncursesw build dir
local ncursesw_build_dir="$1"
# Allow tui mode by adding our custom built static ncursesw library to the linker search path.
export LDFLAGS="-L$ncursesw_build_dir/lib $LDFLAGS"
}
function build_iconv() {
@ -146,6 +169,109 @@ function build_libgmp() {
popd > /dev/null
}
function build_ncurses() {
# Build libncursesw.
#
# Parameters:
# $1: libncursesw package directory
# $2: target architecture
#
# Echoes:
# The libncursesw build directory
#
# Returns:
# 0: success
# 1: failure
local ncurses_dir="$1"
local target_arch="$2"
local ncurses_build_dir="$(realpath "$ncurses_dir/build-$target_arch")"
echo "$ncurses_build_dir"
mkdir -p "$ncurses_build_dir"
if [[ -f "$ncurses_build_dir/lib/libncursesw.a" ]]; then
>&2 echo "Skipping build: libncursesw already built for $target_arch"
return 0
fi
pushd "$ncurses_build_dir" > /dev/null
>&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
if [[ $? -ne 0 ]]; then
return 1
fi
make -j$(nproc) 1>&2
if [[ $? -ne 0 ]]; then
return 1
fi
>&2 fancy_title "Finished building libncursesw for $target_arch"
popd > /dev/null
}
function build_python() {
# Build python.
#
# Parameters:
# $1: python package directory
# $2: target architecture
#
# Echoes:
# The python build directory
#
# Returns:
# 0: success
# 1: failure
local python_dir="$1"
local target_arch="$2"
local python_lib_dir="$(realpath "$python_dir/build-$target_arch")"
echo "$python_lib_dir"
mkdir -p "$python_lib_dir"
# Having a python-config file is an indication that we successfully built python.
if [[ -f "$python_lib_dir/python-config" ]]; then
>&2 echo "Skipping build: libpython already built for $target_arch"
return 0
fi
pushd "$python_lib_dir" > /dev/null
>&2 fancy_title "Building python for $target_arch"
export LINKFORSHARED=" "
export MODULE_BUILDTYPE="static"
export CONFIG_SITE="$python_dir/config.site-static"
>&2 CFLAGS="-static" LDFLAGS="-static" ../configure \
--prefix=$(realpath .) \
--disable-test-modules \
--with-ensurepip=no \
--without-decimal-contextvar \
--build=x86_64-pc-linux-gnu \
--host=$HOST \
--with-build-python=/usr/bin/python3.12 \
--disable-ipv6 \
--disable-shared
>&2 make -j $(nproc)
if [[ $? -ne 0 ]]; then
return 1
fi
# Install python (in build dir using the prefix set above), in order to have a bash (for cross-compilation) python3-config that works.
>&2 make install
if [[ $? -ne 0 ]]; then
return 1
fi
>&2 fancy_title "Finished building python for $target_arch"
popd > /dev/null
}
function build_libmpfr() {
# Build libmpfr.
#
@ -209,6 +335,7 @@ function build_gdb() {
# $3: libiconv prefix
# $4: libgmp prefix
# $5: libmpfr prefix
# $6: whether to build with python or not
#
# Echoes:
# The gdb build directory
@ -222,7 +349,15 @@ function build_gdb() {
local libiconv_prefix="$3"
local libgmp_prefix="$4"
local libmpfr_prefix="$5"
local gdb_build_dir="$(realpath "$gdb_dir/build-$target_arch")"
local with_python="$6"
if [[ "$with_python" == "yes" ]]; then
local python_flag="--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config"
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_with_python")"
else
local python_flag="--without-python"
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}")"
fi
echo "$gdb_build_dir"
mkdir -p "$gdb_build_dir"
@ -236,7 +371,8 @@ function build_gdb() {
>&2 fancy_title "Building gdb for $target_arch"
../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent \
../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \
--enable-tui "$python_flag" \
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
"--with-gmp=$libgmp_prefix" \
"--with-mpfr=$libmpfr_prefix" \
@ -263,6 +399,7 @@ function install_gdb() {
# $1: gdb build directory
# $2: artifacts directory
# $3: target architecture
# $4: whether gdb was built with or without python
#
# Returns:
# 0: success
@ -271,15 +408,22 @@ function install_gdb() {
local gdb_build_dir="$1"
local artifacts_dir="$2"
local target_arch="$3"
local with_python="$4"
if [[ -d "$artifacts_dir/$target_arch" && -n "$(ls -A "$artifacts_dir/$target_arch")" ]]; then
if [[ "$with_python" == "yes" ]]; then
local artifacts_location="$artifacts_dir/${target_arch}_with_python"
else
local artifacts_location="$artifacts_dir/${target_arch}"
fi
if [[ -d "$artifacts_location" && -n "$(ls -A "$artifacts_location")" ]]; then
>&2 echo "Skipping install: gdb already installed for $target_arch"
return 0
fi
temp_artifacts_dir="$(mktemp -d)"
mkdir -p "$artifacts_dir/$target_arch"
mkdir -p "$artifacts_location"
make -C "$gdb_build_dir" install "DESTDIR=$temp_artifacts_dir" 1>&2
if [[ $? -ne 0 ]]; then
@ -288,7 +432,7 @@ function install_gdb() {
fi
while read file; do
cp "$file" "$artifacts_dir/$target_arch/"
cp "$file" "$artifacts_location/"
done < <(find "$temp_artifacts_dir/usr/local/bin" -type f -executable)
rm -rf "$temp_artifacts_dir"
@ -302,8 +446,9 @@ function build_and_install_gdb() {
# $2: libiconv prefix
# $3: libgmp prefix
# $4: libmpfr prefix
# $5: install directory
# $6: target architecture
# $5: whether to build with python or not
# $6: install directory
# $7: target architecture
#
# Returns:
# 0: success
@ -313,15 +458,16 @@ function build_and_install_gdb() {
local libiconv_prefix="$2"
local libgmp_prefix="$3"
local libmpfr_prefix="$4"
local artifacts_dir="$5"
local target_arch="$6"
local with_python="$5"
local artifacts_dir="$6"
local target_arch="$7"
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix")"
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$with_python")"
if [[ $? -ne 0 ]]; then
return 1
fi
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch"
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$with_python"
if [[ $? -ne 0 ]]; then
return 1
fi
@ -333,9 +479,13 @@ function build_gdb_with_dependencies() {
# Parameters:
# $1: target architecture
# $2: build directory
# $3: src directory
# $4: whether to build gdb with python or not
local target_arch="$1"
local build_dir="$2"
local source_dir="$3"
local with_python="$4"
local packages_dir="$build_dir/packages"
local artifacts_dir="$build_dir/artifacts"
@ -361,24 +511,43 @@ function build_gdb_with_dependencies() {
return 1
fi
build_and_install_gdb "$packages_dir/gdb" \
"$iconv_build_dir/lib/.libs/" \
"$gmp_build_dir/.libs/" \
"$mpfr_build_dir/src/.libs/" \
"$artifacts_dir" \
"$target_arch"
ncursesw_build_dir="$(build_ncurses "$packages_dir/ncurses" "$target_arch")"
if [[ $? -ne 0 ]]; then
return 1
fi
set_ncurses_link_variables "$ncursesw_build_dir"
if [[ "$with_python" == "yes" ]]; then
build_python "$packages_dir/cpython-static" "$target_arch"
if [[ $? -ne 0 ]]; then
return 1
fi
fi
build_and_install_gdb "$packages_dir/binutils-gdb" \
"$iconv_build_dir/lib/.libs/" \
"$gmp_build_dir/.libs/" \
"$mpfr_build_dir/src/.libs/" \
"$with_python" \
"$artifacts_dir" \
"$target_arch"
if [[ $? -ne 0 ]]; then
return 1
fi
}
function main() {
if [[ $# -ne 3 ]]; then
>&2 echo "Usage: $0 <target_arch> <build_dir>"
if [[ $# -lt 3 ]]; then
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir> [--with-python]"
exit 1
fi
build_gdb_with_dependencies "$1" "$2"
local with_python="no"
if [[ "$4" == "--with-python" ]]; then
with_python="yes"
fi
build_gdb_with_dependencies "$1" "$2" "$3" "$with_python"
if [[ $? -ne 0 ]]; then
>&2 echo "Error: failed to build gdb with dependencies"
exit 1

View File

@ -2,14 +2,14 @@
# Include utils library
script_dir=$(dirname "$0")
. "$script_dir/utils.sh"
source "$script_dir/utils.sh"
# List of package URLs to download
PACKAGE_URLS=(
SOURCE_URLS=(
"https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"
"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/gnu/gdb/gdb-15.2.tar.xz"
"https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz"
)
function unpack_tarball() {
@ -187,7 +187,7 @@ function download_gdb_packages() {
fancy_title "Starting download of GDB packages"
for url in "${PACKAGE_URLS[@]}"; do
for url in "${SOURCE_URLS[@]}"; do
package_dir=$(package_url_to_dir "$url")
download_and_extract_package "$url" "$package_dir" &
download_pids+=($!)
@ -202,7 +202,6 @@ function download_gdb_packages() {
done
fancy_title "Finished downloading GDB packages"
popd
}

View File

@ -1,70 +0,0 @@
diff --git a/Makefile.in b/Makefile.in
index f12c251f9c8..eed512b2d18 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -31593,7 +31593,7 @@ configure-readline:
$$s/$$module_srcdir/configure \
--srcdir=$${topdir}/$$module_srcdir \
$(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
- --target=${target_alias} \
+ --target=${target_alias} --enable-static \
|| exit 1
@endif readline
@@ -40793,7 +40793,7 @@ configure-libcc1:
$$s/$$module_srcdir/configure \
--srcdir=$${topdir}/$$module_srcdir \
$(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
- --target=${target_alias} --enable-shared \
+ --target=${target_alias} --enable-static --disable-shared \
|| exit 1
@endif libcc1
diff --git a/configure b/configure
index 6466b97f3ec..2ab23dcb81e 100755
--- a/configure
+++ b/configure
@@ -9398,7 +9398,7 @@ case " $configdirs " in
*" lto-plugin "* | *" libcc1 "* | *" gdbserver "*)
# When these are to be built as shared libraries, the same applies to
# libiberty.
- extra_host_libiberty_configure_flags=--enable-shared
+ extra_host_libiberty_configure_flags="--enable-static --disable-shared"
;;
esac
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 84bc54b303e..c81269ced78 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -148,7 +148,7 @@ LIBTOOL = @LIBTOOL@
# Set this up with gcc if you have gnu ld and the loader will print out
# line numbers for undefined references.
#CC_LD = g++ -static
-CC_LD = $(LIBTOOL) $(SILENT_FLAG) --mode=link $(CXX) $(CXX_DIALECT)
+CC_LD = $(LIBTOOL) $(SILENT_FLAG) --mode=link $(CXX) -all-static $(CXX_DIALECT)
# Where is our "include" directory? Typically $(srcdir)/../include.
# This is essentially the header file directory for the library
diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
index 6148ccf9121..2a9c9720d1a 100644
--- a/gdbserver/Makefile.in
+++ b/gdbserver/Makefile.in
@@ -83,7 +83,7 @@ COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(INCLUDE_SERVER_H) \
# Set this up with gcc if you have gnu ld and the loader will print out
# line numbers for undefinded refs.
#CC_LD = g++ -static
-CC_LD = $(CXX) $(CXX_DIALECT)
+CC_LD = $(CXX) -static $(CXX_DIALECT)
# Where is the "include" directory? Traditionally ../include or ./include
INCLUDE_DIR = ${srcdir}/../include
@@ -405,7 +405,7 @@ IPA_LIB = libinproctrace.so
$(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
$(SILENCE) rm -f $(IPA_LIB)
- $(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
+ $(ECHO_CXXLD) $(CC_LD) -static -fPIC -Wl,--soname=$(IPA_LIB) \
-Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
$(CXXFLAGS) \
-o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY_FOR_SHLIB) -ldl -pthread

View File

@ -1,57 +0,0 @@
#!/bin/bash
# Include utils library
script_dir=$(dirname "$0")
. "$script_dir/utils.sh"
function apply_patch() {
# Apply a patch to a directory.
#
# Parameters:
# $1: directory
# $2: path of patch
#
# Returns:
# 0: success
# 1: failure
local dir="$1"
local patch="$(realpath "$2")"
pushd "$dir" > /dev/null
if [[ $? -ne 0 ]]; then
return 1
fi
# Check if the patch was already applied
if ! patch -p1 --dry-run < "$patch" &>/dev/null; then
>&2 echo "Error: patch already applied"
popd > /dev/null
return 1
fi
patch -p1 < "$patch"
if [[ $? -ne 0 ]]; then
popd > /dev/null
return 1
fi
popd > /dev/null
}
function main() {
if [[ $# -ne 2 ]]; then
>&2 echo "Usage: $0 <gdb_dir> <gdb_patch>"
exit 1
fi
fancy_title "Applying GDB patch"
apply_patch "$1" "$2"
if [[ $? -ne 0 ]]; then
>&2 echo "Error: failed to apply GDB patch"
exit 1
fi
fancy_title "Finished applying GDB patch"
}
main "$@"