从源码编译GCC

Get Source

http://ftp.tsukuba.wide.ad.jp/software/gcc/releases下有所有gcc版本,以下我在编译gcc8.2的记录

Patch

gcc8.2在ubuntu2004下没有编过,有一个报错需要patch掉一行

命名为gcc8.2.patch

1
2
3
4
5
6
7
8
9
10
11
12
gcc-8.2.patch
--- gcc-8.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc 2018-05-31 09:58:32.000000000 +0000
+++ gcc-8.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc.new 2023-10-30 09:55:09.829355604 +0000
@@ -1149,7 +1149,7 @@
CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)
/* On aarch64 glibc 2.20 and earlier provided incorrect mode field. */
-CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
+//CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
#endif

CHECK_TYPE_SIZE(shmid_ds);

在下面makefile中会apply patch

Make

文件名gcc8.2.mak

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
SHELL := /bin/bash
PREFIX := /opt/gcc-8.2
MAX_JOBS := 128

.PHONY: all
all: install

.PHONY: configure
configure: third_party gcc-8.2.0
mkdir -p gcc-bulid && \
cd gcc-bulid && \
../gcc-8.2.0/configure CFLAGS="-g3 -gdwarf-2 -O0" CXXFLAGS="-g3 -gdwarf-2 -O0" CFLAGS_FOR_TARGET="-g3 -gdwarf-2 -O0" CXXFLAGS_FOR_TARGET="-g3 -gdwarf-2 -O0" --disable-multilib --enable-languages=c,c++ --prefix=${PREFIX}

.PHONY: install
install: configure patchgcc
cd gcc-bulid && \
make -j ${MAX_JOBS} && \
make install

.PHONY: patchgcc
patchgcc: gcc-8.2.0
patch -u -b gcc-8.2.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc gcc-8.2.patch

.PHONY: clean_deps
clean_deps: install
rm -rf gcc-build gcc-8.2.0/*.tar.bz2 gcc-8.2.0/*.tar.gz

.PHONY: clean
clean:
rm -rf gcc-build gcc-8.2.0 gcc-8.2.0.tar.gz

.PHONY: third_party
third_party: gcc-8.2.0/mpfr gcc-8.2.0/mpc gcc-8.2.0/gmp

gcc-8.2.0: gcc-8.2.0.tar.gz
tar xzvf gcc-8.2.0.tar.gz

gcc-8.2.0.tar.gz:
wget -O gcc-8.2.0.tar.gz http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz

gcc-8.2.0/gmp-6.1.0.tar.bz2: gcc-8.2.0
wget -qO gcc-8.2.0/gmp-6.1.0.tar.bz2 http://ftp.tsukuba.wide.ad.jp/software/gcc/infrastructure/gmp-6.1.0.tar.bz2

gcc-8.2.0/mpc-1.0.3.tar.gz: gcc-8.2.0
wget -qO gcc-8.2.0/mpc-1.0.3.tar.gz http://ftp.tsukuba.wide.ad.jp/software/gcc/infrastructure/mpc-1.0.3.tar.gz

gcc-8.2.0/mpfr-3.1.4.tar.bz2: gcc-8.2.0
wget -qO gcc-8.2.0/mpfr-3.1.4.tar.bz2 http://ftp.tsukuba.wide.ad.jp/software/gcc/infrastructure/mpfr-3.1.4.tar.bz2

gcc-8.2.0/gmp: gcc-8.2.0/gmp-6.1.0.tar.bz2
cd gcc-8.2.0 && \
tar -jxvf gmp-6.1.0.tar.bz2 && \
ln -s gmp-6.1.0 gmp

gcc-8.2.0/mpc: gcc-8.2.0/mpc-1.0.3.tar.gz
cd gcc-8.2.0 && \
tar -xzvf mpc-1.0.3.tar.gz && \
ln -s mpc-1.0.3/ mpc

gcc-8.2.0/mpfr: gcc-8.2.0/mpfr-3.1.4.tar.bz2
cd gcc-8.2.0 && \
tar -jxvf mpfr-3.1.4.tar.bz2 && \
ln -s mpfr-3.1.4/ mpfr

make -f gcc8.2.mak install -j4

产出install目录在/opt/gcc-8.2