Skip to content

Commit b75a59a

Browse files
committed
Try compiling things with -O2 and -flto
1 parent 1b2ebbc commit b75a59a

File tree

3 files changed

+118
-60
lines changed

3 files changed

+118
-60
lines changed

build.sh

+116-58
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,25 @@ declare -r gcc_directory='/tmp/gcc-master'
2626

2727
declare -r sysroot_tarball='/tmp/sysroot.tar.xz'
2828

29-
declare -r optflags='-w -Os'
29+
declare -r max_jobs='40'
30+
31+
declare -r optlto="-flto=${max_jobs} -fno-fat-lto-objects"
32+
declare -r optfatlto="-flto=${max_jobs} -ffat-lto-objects"
33+
34+
declare -r optflags='-w -O2'
3035
declare -r linkflags='-Wl,-s'
3136

32-
declare -r max_jobs="$(($(nproc) * 10))"
37+
declare -ra targets=(
38+
'powerpc64le-unknown-linux-musl'
39+
's390x-unknown-linux-musl'
40+
'arm-unknown-linux-musleabihf'
41+
'armv7l-unknown-linux-musleabihf'
42+
'mips64-unknown-linux-musl'
43+
'x86_64-unknown-linux-musl'
44+
'aarch64-unknown-linux-musl'
45+
'riscv64-unknown-linux-musl'
46+
'i386-unknown-linux-musl'
47+
)
3348

3449
declare build_type="${1}"
3550

@@ -43,64 +58,124 @@ if [ "${build_type}" == 'native' ]; then
4358
is_native='1'
4459
fi
4560

46-
declare OBGGCC_TOOLCHAIN='/tmp/obggcc-toolchain'
4761
declare CROSS_COMPILE_TRIPLET=''
4862

49-
declare cross_compile_flags=''
50-
5163
if ! (( is_native )); then
5264
source "./submodules/obggcc/toolchains/${build_type}.sh"
53-
cross_compile_flags+="--host=${CROSS_COMPILE_TRIPLET}"
5465
fi
5566

67+
declare -r \
68+
build_type \
69+
is_native
70+
5671
if ! [ -f "${gmp_tarball}" ]; then
57-
wget --no-verbose 'https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz' --output-document="${gmp_tarball}"
58-
tar --directory="$(dirname "${gmp_directory}")" --extract --file="${gmp_tarball}"
72+
curl \
73+
--url 'https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz' \
74+
--retry '30' \
75+
--retry-all-errors \
76+
--retry-delay '0' \
77+
--retry-max-time '0' \
78+
--location \
79+
--silent \
80+
--output "${gmp_tarball}"
81+
82+
tar \
83+
--directory="$(dirname "${gmp_directory}")" \
84+
--extract \
85+
--file="${gmp_tarball}"
5986
fi
6087

6188
if ! [ -f "${mpfr_tarball}" ]; then
62-
wget --no-verbose 'https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz' --output-document="${mpfr_tarball}"
63-
tar --directory="$(dirname "${mpfr_directory}")" --extract --file="${mpfr_tarball}"
89+
curl \
90+
--url 'https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz' \
91+
--retry '30' \
92+
--retry-all-errors \
93+
--retry-delay '0' \
94+
--retry-max-time '0' \
95+
--location \
96+
--silent \
97+
--output "${mpfr_tarball}"
98+
99+
tar \
100+
--directory="$(dirname "${mpfr_directory}")" \
101+
--extract \
102+
--file="${mpfr_tarball}"
64103
fi
65104

66105
if ! [ -f "${mpc_tarball}" ]; then
67-
wget --no-verbose 'https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz' --output-document="${mpc_tarball}"
68-
tar --directory="$(dirname "${mpc_directory}")" --extract --file="${mpc_tarball}"
106+
curl \
107+
--url 'https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz' \
108+
--retry '30' \
109+
--retry-all-errors \
110+
--retry-delay '0' \
111+
--retry-max-time '0' \
112+
--location \
113+
--silent \
114+
--output "${mpc_tarball}"
115+
116+
tar \
117+
--directory="$(dirname "${mpc_directory}")" \
118+
--extract \
119+
--file="${mpc_tarball}"
69120
fi
70121

71122
if ! [ -f "${binutils_tarball}" ]; then
72-
wget --no-verbose 'https://ftp.gnu.org/gnu/binutils/binutils-with-gold-2.44.tar.xz' --output-document="${binutils_tarball}"
73-
tar --directory="$(dirname "${binutils_directory}")" --extract --file="${binutils_tarball}"
123+
curl \
124+
--url 'https://ftp.gnu.org/gnu/binutils/binutils-with-gold-2.44.tar.xz' \
125+
--retry '30' \
126+
--retry-all-errors \
127+
--retry-delay '0' \
128+
--retry-max-time '0' \
129+
--location \
130+
--silent \
131+
--output "${binutils_tarball}"
132+
133+
tar \
134+
--directory="$(dirname "${binutils_directory}")" \
135+
--extract \
136+
--file="${binutils_tarball}"
74137

75138
patch --directory="${binutils_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Revert-gold-Use-char16_t-char32_t-instead-of-uint16_.patch"
76139
patch --directory="${binutils_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Disable-annoying-linker-warnings.patch"
77140
fi
78141

79142
if ! [ -f "${gcc_tarball}" ]; then
80-
wget --no-verbose 'https://github.com/gcc-mirror/gcc/archive/refs/heads/master.tar.gz' --output-document="${gcc_tarball}"
81-
tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}"
143+
curl \
144+
--url 'https://github.com/gcc-mirror/gcc/archive/refs/heads/master.tar.gz' \
145+
--retry '30' \
146+
--retry-all-errors \
147+
--retry-delay '0' \
148+
--retry-max-time '0' \
149+
--location \
150+
--silent \
151+
--output "${gcc_tarball}"
152+
153+
tar \
154+
--directory="$(dirname "${gcc_directory}")" \
155+
--extract \
156+
--file="${gcc_tarball}"
157+
158+
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Fix-libgcc-build-on-musl.patch"
82159

83160
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Fix-libgcc-build-on-arm.patch"
84161
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Change-the-default-language-version-for-C-compilatio.patch"
85162
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Turn-Wimplicit-int-back-into-an-warning.patch"
86163
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Turn-Wint-conversion-back-into-an-warning.patch"
87164
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/submodules/obggcc/patches/0001-Revert-GCC-change-about-turning-Wimplicit-function-d.patch"
88-
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Fix-libgcc-build-on-musl.patch"
89-
patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Fix-libquadmath-build-on-musl.patch"
90165
fi
91166

92167
[ -d "${gmp_directory}/build" ] || mkdir "${gmp_directory}/build"
93168

94169
cd "${gmp_directory}/build"
95170

96171
../configure \
172+
--host="${CROSS_COMPILE_TRIPLET}" \
97173
--prefix="${toolchain_directory}" \
98174
--enable-shared \
99175
--enable-static \
100-
${cross_compile_flags} \
101-
CFLAGS="${optflags}" \
102-
CXXFLAGS="${optflags}" \
103-
LDFLAGS="${linkflags}"
176+
CFLAGS="${optflags} ${optlto}" \
177+
CXXFLAGS="${optflags} ${optlto}" \
178+
LDFLAGS="${linkflags} ${optlto}"
104179

105180
make all --jobs
106181
make install
@@ -110,14 +185,14 @@ make install
110185
cd "${mpfr_directory}/build"
111186

112187
../configure \
188+
--host="${CROSS_COMPILE_TRIPLET}" \
113189
--prefix="${toolchain_directory}" \
114190
--with-gmp="${toolchain_directory}" \
115191
--enable-shared \
116192
--enable-static \
117-
${cross_compile_flags} \
118-
CFLAGS="${optflags}" \
119-
CXXFLAGS="${optflags}" \
120-
LDFLAGS="${linkflags}"
193+
CFLAGS="${optflags} ${optlto}" \
194+
CXXFLAGS="${optflags} ${optlto}" \
195+
LDFLAGS="${linkflags} ${optlto}"
121196

122197
make all --jobs
123198
make install
@@ -127,30 +202,18 @@ make install
127202
cd "${mpc_directory}/build"
128203

129204
../configure \
205+
--host="${CROSS_COMPILE_TRIPLET}" \
130206
--prefix="${toolchain_directory}" \
131207
--with-gmp="${toolchain_directory}" \
132208
--enable-shared \
133209
--enable-static \
134-
${cross_compile_flags} \
135-
CFLAGS="${optflags}" \
136-
CXXFLAGS="${optflags}" \
137-
LDFLAGS="${linkflags}"
210+
CFLAGS="${optflags} ${optlto}" \
211+
CXXFLAGS="${optflags} ${optlto}" \
212+
LDFLAGS="${linkflags} ${optlto}"
138213

139214
make all --jobs
140215
make install
141216

142-
declare -ra targets=(
143-
'arm-unknown-linux-musleabihf'
144-
'armv7l-unknown-linux-musleabihf'
145-
'powerpc64le-unknown-linux-musl'
146-
's390x-unknown-linux-musl'
147-
'mips64-unknown-linux-musl'
148-
'x86_64-unknown-linux-musl'
149-
'aarch64-unknown-linux-musl'
150-
'riscv64-unknown-linux-musl'
151-
'i386-unknown-linux-musl'
152-
)
153-
154217
for target in "${targets[@]}"; do
155218
source "${workdir}/${target}.sh"
156219

@@ -163,10 +226,12 @@ for target in "${targets[@]}"; do
163226
--retry-delay '0' \
164227
--retry-max-time '0' \
165228
--location \
166-
--continue-at '-' \
167229
--output "${sysroot_tarball}"
168230

169-
tar --directory="${toolchain_directory}" --extract --file="${sysroot_tarball}"
231+
tar \
232+
--directory="${toolchain_directory}" \
233+
--extract \
234+
--file="${sysroot_tarball}"
170235

171236
unlink "${sysroot_tarball}"
172237

@@ -176,6 +241,7 @@ for target in "${targets[@]}"; do
176241
rm --force --recursive ./*
177242

178243
../configure \
244+
--host="${CROSS_COMPILE_TRIPLET}" \
179245
--target="${triplet}" \
180246
--prefix="${toolchain_directory}" \
181247
--enable-gold \
@@ -184,10 +250,9 @@ for target in "${targets[@]}"; do
184250
--disable-gprofng \
185251
--with-static-standard-libraries \
186252
--with-sysroot="${toolchain_directory}/${triplet}" \
187-
${cross_compile_flags} \
188-
CFLAGS="${optflags}" \
189-
CXXFLAGS="${optflags}" \
190-
LDFLAGS="${linkflags}"
253+
CFLAGS="${optflags} ${optlto}" \
254+
CXXFLAGS="${optflags} ${optlto}" \
255+
LDFLAGS="${linkflags} ${optlto}"
191256

192257
make all --jobs
193258
make install
@@ -199,14 +264,15 @@ for target in "${targets[@]}"; do
199264
rm --force --recursive ./*
200265

201266
../configure \
267+
--host="${CROSS_COMPILE_TRIPLET}" \
202268
--target="${triplet}" \
203269
--prefix="${toolchain_directory}" \
204270
--with-linker-hash-style='gnu' \
205271
--with-gmp="${toolchain_directory}" \
206272
--with-mpc="${toolchain_directory}" \
207273
--with-mpfr="${toolchain_directory}" \
208274
--with-bugurl='https://github.com/AmanoTeam/Raiden/issues' \
209-
--with-pkgversion="Raiden v0.7-${revision}" \
275+
--with-pkgversion="Raiden v0.8-${revision}" \
210276
--with-sysroot="${toolchain_directory}/${triplet}" \
211277
--with-gcc-major-version-only \
212278
--with-native-system-header-dir='/include' \
@@ -226,7 +292,7 @@ for target in "${targets[@]}"; do
226292
--enable-ld \
227293
--enable-gold \
228294
--enable-languages='c,c++' \
229-
--disable-plugin \
295+
--enable-plugin \
230296
--disable-libsanitizer \
231297
--disable-fixincludes \
232298
--disable-gnu-unique-object \
@@ -241,7 +307,6 @@ for target in "${targets[@]}"; do
241307
--disable-nls \
242308
--without-headers \
243309
${extra_configure_flags} \
244-
${cross_compile_flags} \
245310
libat_cv_have_ifunc=no \
246311
CFLAGS="${optflags}" \
247312
CXXFLAGS="${optflags}" \
@@ -253,13 +318,6 @@ for target in "${targets[@]}"; do
253318
all --jobs="${max_jobs}"
254319
make install
255320

256-
cd "${toolchain_directory}/${triplet}/bin"
257-
258-
for name in *; do
259-
rm "${name}"
260-
ln --symbolic "../../bin/${triplet}-${name}" "${name}"
261-
done
262-
263321
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1"
264322
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1plus"
265323
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/lto1"

powerpc64le-unknown-linux-musl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
declare extra_configure_flags='--with-abi=elfv2'
3+
declare extra_configure_flags='--with-abi=elfv2 --without-long-double-128'
44

55
declare triplet='powerpc64le-unknown-linux-musl'
66

s390x-unknown-linux-musl.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
declare extra_configure_flags='--with-arch=z196 --with-tune=zEC12 --with-zarch'
3+
declare extra_configure_flags='--with-arch=z196 --with-tune=zEC12 --with-zarch --without-long-double-128'
44

55
declare triplet='s390x-unknown-linux-musl'
66

0 commit comments

Comments
 (0)