From 377ef9f028c7853b70e21fdecf5f6d376d9031b5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Aug 2026 23:52:29 +0200 Subject: [PATCH 1/9] Build newer binutils before building gcc --- src/ci/docker/scripts/build-gcc.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 6a96b82d3f924..bef169fafe38c 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -4,6 +4,13 @@ set -eux source shared.sh +BINUTILS="2.47" +curl https://ci-mirrors.rust-lang.org/rustc/gcc/binutils-$BINUTILS.tar.xz | xzcat | tar xf - +cd binutils-$BINUTILS +hide_output ./configure +hide_output make +hide_output make install + # Note: in the future when bumping to version 10.1.0, also take care of the sed block below. # This version is specified in the Dockerfile GCC=$GCC_VERSION From 748a319ee14347ddb87aa7be35a51c3fcc3bbb0a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Aug 2026 15:05:15 +0200 Subject: [PATCH 2/9] Add extra checks to ensure GCC and binutils have needed support for the `retain` attribute --- src/ci/docker/scripts/build-gcc.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index bef169fafe38c..41bc3495e0b2e 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -11,6 +11,15 @@ hide_output ./configure hide_output make hide_output make install +if echo '.section .test,"awR",@progbits' | as - -o /dev/null 2>/dev/null; then + echo "binutils assembler supports SHF_GNU_RETAIN" +else + echo "binutils assembler DOES NOT support SHF_GNU_RETAIN" + exit 1 +fi + +cd .. + # Note: in the future when bumping to version 10.1.0, also take care of the sed block below. # This version is specified in the Dockerfile GCC=$GCC_VERSION @@ -54,6 +63,12 @@ hide_output ../gcc-$GCC/configure \ hide_output make -j$(nproc) hide_output make install ln -s gcc /rustroot/bin/cc +if echo 'int x __attribute__((used, retain));' | gcc -S -x c -o - - | grep -i '"a.*R"'; then + echo "retain attribute is supported" +else + echo "retain attribute is not supported" + exit 1 +fi cd .. rm -rf gcc-build From 487e0e0b00837f573c076cd238db9fa819b5309d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Aug 2026 17:47:16 +0200 Subject: [PATCH 3/9] Display generated asm in case it failed --- src/ci/docker/scripts/build-gcc.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 41bc3495e0b2e..6ac0514b6569f 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -67,6 +67,8 @@ if echo 'int x __attribute__((used, retain));' | gcc -S -x c -o - - | grep -i '" echo "retain attribute is supported" else echo "retain attribute is not supported" + # We display the generated asm just in case... + echo 'int x __attribute__((used, retain));' | gcc -S -x c -o - - exit 1 fi From 4c097cfeda80dd0fc8307f804f946106330cb18a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Aug 2026 21:56:22 +0200 Subject: [PATCH 4/9] Use `--prefix` to generate binaries in the right location --- src/ci/docker/scripts/build-gcc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 6ac0514b6569f..bb2c97b475ece 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -7,8 +7,8 @@ source shared.sh BINUTILS="2.47" curl https://ci-mirrors.rust-lang.org/rustc/gcc/binutils-$BINUTILS.tar.xz | xzcat | tar xf - cd binutils-$BINUTILS -hide_output ./configure -hide_output make +hide_output ./configure --prefix=/rustroot +hide_output make -j$(nproc) hide_output make install if echo '.section .test,"awR",@progbits' | as - -o /dev/null 2>/dev/null; then From 88cfd2278aac08e6f0a6098d3c3a0acd5ef4be08 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 14 Aug 2026 01:58:50 +0200 Subject: [PATCH 5/9] Use `--with-as` and `--with-ld` options for `gcc` configure --- src/ci/docker/scripts/build-gcc.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index bb2c97b475ece..24598f62e05e2 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -11,13 +11,16 @@ hide_output ./configure --prefix=/rustroot hide_output make -j$(nproc) hide_output make install -if echo '.section .test,"awR",@progbits' | as - -o /dev/null 2>/dev/null; then +if echo '.section .test,"awR",@progbits' | /rustroot/bin/as - -o /dev/null 2>/dev/null; then echo "binutils assembler supports SHF_GNU_RETAIN" else echo "binutils assembler DOES NOT support SHF_GNU_RETAIN" exit 1 fi +AS_PATH="/rustroot/bin/as" +LD_PATH="/rustroot/bin/ld" + cd .. # Note: in the future when bumping to version 10.1.0, also take care of the sed block below. @@ -57,6 +60,8 @@ cd ../gcc-build # which is included in librustc_driver.so hide_output ../gcc-$GCC/configure \ --prefix=/rustroot \ + --with-as=$AS_PATH \ + --with-ld=$LD_PATH \ --enable-languages=c,c++ \ --disable-gnu-unique-object \ --enable-cxx-flags='-fno-reorder-blocks-and-partition' From bcc35a8e30a0061d07df3973fffbd7d8ffa85d2f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 14 Aug 2026 14:22:38 +0200 Subject: [PATCH 6/9] More settings targetting binutils --- src/ci/docker/scripts/build-gcc.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 24598f62e05e2..9a70071242d83 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -55,11 +55,13 @@ sed -i'' 's|ftp://gcc\.gnu\.org/pub/gcc/infrastructure|https://ci-mirrors.rust-l mkdir ../gcc-build cd ../gcc-build +export PATH=/rustroot/bin:$PATH # '-fno-reorder-blocks-and-partition' is required to # enable BOLT optimization of the C++ standard library, # which is included in librustc_driver.so hide_output ../gcc-$GCC/configure \ --prefix=/rustroot \ + --with-bintuils=/rustroot/bin \ --with-as=$AS_PATH \ --with-ld=$LD_PATH \ --enable-languages=c,c++ \ @@ -68,12 +70,13 @@ hide_output ../gcc-$GCC/configure \ hide_output make -j$(nproc) hide_output make install ln -s gcc /rustroot/bin/cc -if echo 'int x __attribute__((used, retain));' | gcc -S -x c -o - - | grep -i '"a.*R"'; then + +if echo 'int x __attribute__((used, retain));' | /rustroot/bin/gcc -S -x c -o - - | grep -i '"a.*R"'; then echo "retain attribute is supported" else echo "retain attribute is not supported" # We display the generated asm just in case... - echo 'int x __attribute__((used, retain));' | gcc -S -x c -o - - + echo 'int x __attribute__((used, retain));' | /rustroot/bin/gcc -S -x c -o - - exit 1 fi From 80cc60a7ea59a2edf33c7cbbc3c6cfa2a0bcb78b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 14 Aug 2026 21:26:24 +0200 Subject: [PATCH 7/9] Correctly test the custom GCC built in CI --- .../host-x86_64/dist-x86_64-linux/dist.sh | 11 ++++++++ src/ci/docker/scripts/build-gcc.sh | 26 +++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh index 46d34cd001a95..0ccfd0d765946 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh @@ -18,4 +18,15 @@ if [ "${DIST_TRY_BUILD:-0}" == "0" ]; then CC=/rustroot/bin/cc CXX=/rustroot/bin/c++ python3 ../x.py dist \ gcc-dev \ gcc + # We confirm that the built GCC has support for the `retain` attribute. + # FIXME: Maybe get the path from `.x.py` instead? + gcc_path="./build/$HOSTS/gcc/$HOSTS/install/bin/gcc" + if echo 'int x __attribute__((used, retain));' | "$gcc_path" -S -x c -o - - | grep -i '"a.*R"'; then + echo "retain attribute is supported" + else + echo "retain attribute is not supported" + # We display the generated asm just in case... + echo 'int x __attribute__((used, retain));' | "$gcc_path" -S -x c -o - - + exit 1 + fi fi diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 9a70071242d83..29502ec56a767 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -6,22 +6,22 @@ source shared.sh BINUTILS="2.47" curl https://ci-mirrors.rust-lang.org/rustc/gcc/binutils-$BINUTILS.tar.xz | xzcat | tar xf - -cd binutils-$BINUTILS -hide_output ./configure --prefix=/rustroot +mkdir binutils-build +cd binutils-build +hide_output ../binutils-$BINUTILS/configure --prefix=/rustroot hide_output make -j$(nproc) hide_output make install -if echo '.section .test,"awR",@progbits' | /rustroot/bin/as - -o /dev/null 2>/dev/null; then +cd .. +rm -rf binutils-build binutils-$BINUTILS + +if echo '.section .test,"awR",@progbits' | as - -o /dev/null 2>/dev/null; then echo "binutils assembler supports SHF_GNU_RETAIN" else echo "binutils assembler DOES NOT support SHF_GNU_RETAIN" exit 1 fi -AS_PATH="/rustroot/bin/as" -LD_PATH="/rustroot/bin/ld" - -cd .. # Note: in the future when bumping to version 10.1.0, also take care of the sed block below. # This version is specified in the Dockerfile @@ -61,9 +61,6 @@ export PATH=/rustroot/bin:$PATH # which is included in librustc_driver.so hide_output ../gcc-$GCC/configure \ --prefix=/rustroot \ - --with-bintuils=/rustroot/bin \ - --with-as=$AS_PATH \ - --with-ld=$LD_PATH \ --enable-languages=c,c++ \ --disable-gnu-unique-object \ --enable-cxx-flags='-fno-reorder-blocks-and-partition' @@ -71,15 +68,6 @@ hide_output make -j$(nproc) hide_output make install ln -s gcc /rustroot/bin/cc -if echo 'int x __attribute__((used, retain));' | /rustroot/bin/gcc -S -x c -o - - | grep -i '"a.*R"'; then - echo "retain attribute is supported" -else - echo "retain attribute is not supported" - # We display the generated asm just in case... - echo 'int x __attribute__((used, retain));' | /rustroot/bin/gcc -S -x c -o - - - exit 1 -fi - cd .. rm -rf gcc-build rm -rf gcc-$GCC From 942fe31efedf5fee6f3d5dfdf21be2296704abab Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 14 Aug 2026 21:34:37 +0200 Subject: [PATCH 8/9] Fix tidy error --- src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh index 0ccfd0d765946..835fb6ee5e724 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh @@ -21,12 +21,13 @@ if [ "${DIST_TRY_BUILD:-0}" == "0" ]; then # We confirm that the built GCC has support for the `retain` attribute. # FIXME: Maybe get the path from `.x.py` instead? gcc_path="./build/$HOSTS/gcc/$HOSTS/install/bin/gcc" - if echo 'int x __attribute__((used, retain));' | "$gcc_path" -S -x c -o - - | grep -i '"a.*R"'; then + c_code='int x __attribute__((used, retain));' + if echo "$c_code" | "$gcc_path" -S -x c -o - - | grep -i '"a.*R"'; then echo "retain attribute is supported" else echo "retain attribute is not supported" # We display the generated asm just in case... - echo 'int x __attribute__((used, retain));' | "$gcc_path" -S -x c -o - - + echo "$c_code" | "$gcc_path" -S -x c -o - - exit 1 fi fi From d7bd2df6bbd84aca8ffe53cd2e06cef892b64ca8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 16 Aug 2026 12:20:03 +0200 Subject: [PATCH 9/9] Add code comment explaining why we need this binutils version --- src/ci/docker/scripts/build-gcc.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ci/docker/scripts/build-gcc.sh b/src/ci/docker/scripts/build-gcc.sh index 29502ec56a767..c1c94a89d17e7 100755 --- a/src/ci/docker/scripts/build-gcc.sh +++ b/src/ci/docker/scripts/build-gcc.sh @@ -4,6 +4,8 @@ set -eux source shared.sh +# We have to build our own binutils for the GCC build, because the default CentOS 7 binutils are +# too old, and they do not support `SHF_GNU_RETAIN`. BINUTILS="2.47" curl https://ci-mirrors.rust-lang.org/rustc/gcc/binutils-$BINUTILS.tar.xz | xzcat | tar xf - mkdir binutils-build