File tree Expand file tree Collapse file tree 8 files changed +187
-0
lines changed
Expand file tree Collapse file tree 8 files changed +187
-0
lines changed Original file line number Diff line number Diff line change 1+ /.idea
2+ /build
Original file line number Diff line number Diff line change 1+ # GCC Toolchain
2+
3+ GCC toolchain targeting ** older glibc versions** , designed for building Linux binaries that run across a wide range of
4+ distributions. This toolchain is intended for use inside a Docker container running ** Ubuntu 24.04 or later** .
5+
6+ ## Why?
7+
8+ The usual method for producing portable Linux binaries is to compile them on an outdated distribution (e.g., CentOS 7).
9+
10+ This repository provides a ** modern alternative** : a GCC toolchain configured to target an older glibc, ensuring
11+ compatibility and preventing errors like:
12+
13+ ``` text
14+ /lib64/libc.so.6: version `GLIBC_2.XX' not found
15+ ```
16+
17+ ## Supported Toolchains
18+
19+ * x86_64-linux-gnu:
20+
21+ | Component | Version |
22+ | :-----------| :---------|
23+ | GCC | 15.2.0 |
24+ | glibc | 2.17 |
25+ | Binutils | 2.45 |
26+ | GDB | 16.3 |
27+
28+ * aarch64-linux-gnu:
29+
30+ | Component | Version |
31+ | :-----------| :---------|
32+ | GCC | 15.2.0 |
33+ | glibc | 2.17 |
34+ | Binutils | 2.29.1 |
35+ | GDB | 16.3 |
36+
37+ ## Compilation
38+
39+ * Clone the repository:
40+
41+ ``` shell
42+ git clone https://github.com/prepkg/gcc-toolchain.git && cd gcc-toolchain
43+ ```
44+
45+ * Build the Docker image:
46+
47+ ``` shell
48+ ./setup.sh build-image
49+ ```
50+
51+ * Build the GCC toolchain:
52+
53+ ``` shell
54+ ./setup.sh build-toolchain
55+ ```
56+
57+ * (Optional) Check the toolchain component versions:
58+
59+ ``` shell
60+ ./setup.sh version
61+ ```
62+
63+ After compilation, the toolchains for each architecture will be available in the ` build ` directory.
Original file line number Diff line number Diff line change 1+ CT_CONFIG_VERSION="4"
2+ CT_OBSOLETE=y
3+ CT_EXPERIMENTAL=y
4+ CT_ALLOW_BUILD_AS_ROOT=y
5+ CT_ALLOW_BUILD_AS_ROOT_SURE=y
6+ CT_ARCH_ARM=y
7+ CT_OMIT_TARGET_VENDOR=y
8+ CT_ARCH_64=y
9+ CT_KERNEL_LINUX=y
10+ CT_LINUX_V_3_10=y
11+ CT_BINUTILS_V_2_29=y
12+ CT_GLIBC_V_2_17=y
13+ CT_GCC_V_15=y
14+ CT_CC_GCC_LIBSANITIZER=y
15+ CT_CC_LANG_CXX=y
16+ CT_DEBUG_GDB=y
17+ CT_GLIBC_EXTRA_CFLAGS="-Wno-missing-attributes -Wno-array-bounds -Wno-array-parameter -Wno-stringop-overflow -Wno-maybe-uninitialized -Wno-implicit-int -gdwarf-4"
Original file line number Diff line number Diff line change 1+ CT_CONFIG_VERSION="4"
2+ CT_OBSOLETE=y
3+ CT_EXPERIMENTAL=y
4+ CT_ALLOW_BUILD_AS_ROOT=y
5+ CT_ALLOW_BUILD_AS_ROOT_SURE=y
6+ CT_ARCH_X86=y
7+ CT_OMIT_TARGET_VENDOR=y
8+ CT_ARCH_64=y
9+ CT_KERNEL_LINUX=y
10+ CT_LINUX_V_3_10=y
11+ CT_BINUTILS_V_2_45=y
12+ CT_GLIBC_V_2_17=y
13+ CT_GCC_V_15=y
14+ CT_CC_GCC_LIBSANITIZER=y
15+ CT_CC_LANG_CXX=y
16+ CT_DEBUG_GDB=y
Original file line number Diff line number Diff line change 1+ FROM ubuntu:24.04
2+
3+ WORKDIR /app
4+
5+ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
6+ wget ca-certificates git gcc g++ make automake libtool-bin flex bison texinfo bzip2 xz-utils unzip help2man \
7+ file patch gawk libncurses-dev python3-dev \
8+ && rm -rf /var/lib/apt/lists/*
9+
10+ ENTRYPOINT ["/bin/bash" ]
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ cd /tmp
4+ git clone https://github.com/crosstool-ng/crosstool-ng
5+ cd crosstool-ng
6+ git checkout 7f9d704
7+
8+ ./bootstrap
9+ ./configure --enable-local
10+ make -j$( nproc)
11+
12+ mkdir -p /app/build
13+
14+ TOOLCHAINS=(
15+ ' x86_64-linux-gnu'
16+ ' aarch64-linux-gnu'
17+ )
18+
19+ for toolchain in " ${TOOLCHAINS[@]} " ; do
20+ cd /tmp/crosstool-ng
21+ mkdir samples/$toolchain
22+ cp /app/config/$toolchain .config samples/$toolchain /crosstool.config
23+ ./ct-ng $toolchain
24+
25+ CT_PREFIX=/opt ./ct-ng build.$( nproc)
26+ cd /opt && tar czf /app/build/gcc-$toolchain .tar.gz $toolchain
27+ done
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ cd build
4+
5+ TOOLCHAINS=(
6+ ' x86_64-linux-gnu'
7+ ' aarch64-linux-gnu'
8+ )
9+
10+ for toolchain in " ${TOOLCHAINS[@]} " ; do
11+ tar xf gcc-$toolchain .tar.gz
12+
13+ GCC_VERSION=$( $toolchain /bin/$toolchain -gcc -dumpversion)
14+ GLIBC_VERSION=$( strings $toolchain /$toolchain /sysroot/lib/libc.so.6 | grep GLIBC | sed ' s/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -Vu | tail -n1)
15+ BINUTILS_VERSION=$( $toolchain /bin/$toolchain -ld --version | head -n1 | grep -Po ' [0-9.]+$' )
16+ GDB_VERSION=$( $toolchain /bin/$toolchain -gdb --version | head -n1 | grep -Po ' [0-9.]+$' )
17+
18+ printf ' * %s:\n\n' $toolchain
19+ printf ' | %-10s | %-8s |\n' ' Component' ' Version'
20+ printf ' |:-----------|:---------|\n'
21+ printf ' | %-10s | %-8s |\n' ' GCC' $GCC_VERSION
22+ printf ' | %-10s | %-8s |\n' ' glibc' $GLIBC_VERSION
23+ printf ' | %-10s | %-8s |\n' ' Binutils' $BINUTILS_VERSION
24+ printf ' | %-10s | %-8s |\n\n' ' GDB' $GDB_VERSION
25+
26+ rm -rf $toolchain
27+ done
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ if [[ ! $1 =~ ^(build-image| build-toolchain| version)$ ]]; then
4+ echo ' Available arguments: build-image, build-toolchain, version'
5+ exit 1
6+ fi
7+
8+ if [[ $1 == build-image ]]; then
9+ docker build -t gcc-toolchain scripts
10+
11+ exit 0
12+ fi
13+
14+ if [[ $1 == build-toolchain ]]; then
15+ docker run -it --rm -v ./:/app gcc-toolchain scripts/compile.sh
16+ sudo chown -R $USER :$USER build
17+
18+ exit 0
19+ fi
20+
21+ if [[ $1 == version ]]; then
22+ docker run -it --rm -v ./:/app gcc-toolchain scripts/version.sh
23+
24+ exit 0
25+ fi
You can’t perform that action at this time.
0 commit comments