Skip to content

Commit 6a10006

Browse files
authored
feat: further improve toolchain sizes (#191)
1 parent ac47d72 commit 6a10006

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

sysroot/Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ RUN --mount=source=configure.sh,target=/usr/bin/configure.sh configure.sh \
167167
--with-headers=/var/install/kernel/usr/include \
168168
--with-tls \
169169
libc_cv_slibdir=/lib \
170-
CFLAGS="-O2 -falign-functions=32" \
171-
LDFLAGS="-Wl,-z,max-page-size=0x1000" \
172170
|| (cat config.log && exit 1)
173171
RUN make all --jobs $(nproc)
174172
RUN make DESTDIR=/var/install/glibc install
@@ -179,6 +177,7 @@ WORKDIR /build/gcc/build
179177
COPY --from=kernel /var/install/kernel /var/install/gcc/sysroot
180178
COPY --from=glibc /var/install/glibc /var/install/gcc/sysroot
181179
RUN --mount=source=configure.sh,target=/usr/bin/configure.sh IS_GCC_BUILD=1 configure.sh \
180+
--disable-bootstrap \
182181
--enable-default-pie \
183182
--enable-languages=c,c++,fortran,lto \
184183
--disable-multilib \
@@ -187,14 +186,10 @@ RUN --mount=source=configure.sh,target=/usr/bin/configure.sh IS_GCC_BUILD=1 conf
187186
--with-linker-hash-style=gnu \
188187
--with-build-sysroot=/var/install/gcc/sysroot \
189188
--with-sysroot=/RELOCATABLE_SYSROOT \
190-
CFLAGS="-O2 -falign-functions=32" \
191-
CXXFLAGS="-O2 -falign-functions=32" \
192-
LDFLAGS="-Wl,-z,max-page-size=0x1000" \
193189
|| (cat config.log && exit 1)
194190
RUN grep -rl '/RELOCATABLE_SYSROOT' . | xargs sed -i 's|/RELOCATABLE_SYSROOT|$(exec_prefix)/sysroot|g'
195191
RUN make --jobs $(nproc) all-gcc
196192
RUN make install-gcc
197-
RUN rm -v "/opt/gcc/${ARCH}/bin/"*{gcc,g++,cpp}
198193
ENV PATH="/var/install/gcc/bin:${PATH}"
199194
RUN make --jobs $(nproc)
200195
RUN make install
@@ -216,8 +211,6 @@ RUN --mount=source=configure.sh,target=/usr/bin/configure.sh IS_GCC_BUILD=1 conf
216211
--prefix=/var/install/binutils \
217212
--with-build-sysroot=/var/install/gcc/sysroot \
218213
--with-lib-path=/var/install/glibc/usr/lib \
219-
CFLAGS="-O2 -falign-functions=32" \
220-
LDFLAGS="-Wl,-z,max-page-size=0x1000" \
221214
|| (cat config.log && exit 1)
222215
RUN make --jobs $(nproc)
223216
RUN make install
@@ -344,6 +337,15 @@ RUN --mount=source=dedup,target=/usr/bin/dedup dedup /var/builds/toolchain
344337
# We patch the shared libraries to set the rpath to $ORIGIN, so that during runtime the
345338
# libraries are found in the same directory as the executable.
346339
COPY --from=patchelf_download /downloads/patchelf /var/install/patchelf
347-
RUN find /var \
340+
RUN find /var/builds/toolchain \
348341
-name '*.so*' \
349342
-exec /var/install/patchelf/bin/patchelf --set-rpath '$ORIGIN/' {} \;
343+
344+
RUN find /var/builds/toolchain/bin -type f \
345+
-exec strip \
346+
--strip-all \
347+
--remove-section=.comment \
348+
--remove-section=.note \
349+
--remove-section=.eh_frame \
350+
--remove-section=.eh_frame_hdr \
351+
{} \;

sysroot/configure.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ export STRIP="${toolchain_prefix}-strip"
8383

8484
args+=("${@}")
8585

86+
readonly common_flags=(
87+
-O2
88+
-falign-functions=32
89+
-ffunction-sections
90+
-fdata-sections
91+
)
92+
93+
args+=(
94+
CFLAGS="${common_flags[*]}"
95+
CXXFLAGS="${common_flags[*]}"
96+
LDFLAGS="-Wl,-z,max-page-size=0x1000 -Wl,--strip-all -Wl,--as-needed"
97+
)
98+
8699
../configure "${args[@]}" 1> >(tee configure.stdout) 2> >(>&2 tee configure.stderr)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ba19e9a6cc7cc64930263a9a1126c3dbdad6bdc8b0f2e8e2d38377d84e8d52fe
3-
size 146755452
2+
oid sha256:1ee2734713ab3329e4c416ecf55aa6177d9d33dc654659ef612f5e2956f6c01d
3+
size 118165348

sysroot/gcc-toolchain-armv7.tar.xz

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:975212e47be7bd979a2c98abd2c25361eb8cc482175accb2bf936ad7b044b068
3-
size 109767980
2+
oid sha256:b04b10d5ae97796a0e06abf59c05de96a13134f0d7d45cd193148de5aa009c82
3+
size 97197372
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e07a63499c0c608d765e653cecf816f30920d57f824cc8549890f8b444ef309e
3-
size 479900468
2+
oid sha256:a2e95cb78cdcef2989231497d1eb28fdc924d4bf9859c76e7509dfdd37aa9131
3+
size 133241152

0 commit comments

Comments
 (0)