Build GCC For HiSilicon Hikey 970

By following our previous blog Build GCC, we should be able to CROSS-BUILD GCC for various ARM architectures. Today, we are building GCC 9.1.0 for Hikey 970, which is of aarch64 architecture. (More details about aarch64 can be found on ARM architecture )

Start Building

Binutils

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
➜  aarch64 mkdir build-binutils
➜ aarch64 cd build-binutils
lvision@hikey970:~/Downloads/Programming/GCC/build-binutils$ ../binutils-2.32/configure --prefix=/opt/aarch64 --enable-shared --enable-vtable-verify
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking target system type... aarch64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... yes
checking for gnatbind... gnatbind
checking for gnatmake... gnatmake
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for isl 0.15 or later... yes
checking for default BUILD_CONFIG...
checking for --enable-vtable-verify... yes
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... flex
checking for flex... flex
checking for makeinfo... makeinfo
checking for expect... expect
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for readelf... readelf
checking for cc... cc
checking for c++... c++
checking for gcc... gcc
checking for gfortran... gfortran
checking for gccgo... gccgo
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for objcopy... objcopy
checking for objdump... objdump
checking for ranlib... ranlib
checking for readelf... readelf
checking for strip... strip
checking for windres... no
checking for windmc... no
checking where to find the target ar... just compiled
checking where to find the target as... just compiled
checking where to find the target cc... host tool
checking where to find the target c++... host tool
checking where to find the target c++ for libstdc++... host tool
checking where to find the target dlltool... just compiled
checking where to find the target gcc... host tool
checking where to find the target gfortran... host tool
checking where to find the target gccgo... host tool
checking where to find the target ld... just compiled
checking where to find the target lipo... host tool
checking where to find the target nm... just compiled
checking where to find the target objcopy... just compiled
checking where to find the target objdump... just compiled
checking where to find the target ranlib... just compiled
checking where to find the target readelf... just compiled
checking where to find the target strip... just compiled
checking where to find the target windres... just compiled
checking where to find the target windmc... just compiled
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
➜ build-binutils make -j4
......
➜ build-binutils make install
➜ build-binutils cd ..

Linux Kernel Headers

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
➜  aarch64 cd linux-5.1.12
➜ linux-5.1.12 make ARCH=arm64 INSTALL_HDR_PATH=/opt/aarch64/aarch64-linux headers_install
INSTALL include/asm-generic (36 files)
INSTALL include/drm (26 files)
INSTALL include/linux/android (2 files)
INSTALL include/linux/byteorder (2 files)
INSTALL include/linux/caif (2 files)
INSTALL include/linux/can (6 files)
INSTALL include/linux/cifs (1 file)
INSTALL include/linux/dvb (8 files)
INSTALL include/linux/genwqe (1 file)
INSTALL include/linux/hdlc (1 file)
INSTALL include/linux/hsi (2 files)
INSTALL include/linux/iio (2 files)
INSTALL include/linux/isdn (1 file)
INSTALL include/linux/mmc (1 file)
INSTALL include/linux/netfilter/ipset (4 files)
INSTALL include/linux/netfilter (88 files)
INSTALL include/linux/netfilter_arp (2 files)
INSTALL include/linux/netfilter_bridge (17 files)
INSTALL include/linux/netfilter_ipv4 (9 files)
INSTALL include/linux/netfilter_ipv6 (13 files)
INSTALL include/linux/nfsd (5 files)
INSTALL include/linux/raid (2 files)
INSTALL include/linux/sched (1 file)
INSTALL include/linux/spi (1 file)
INSTALL include/linux/sunrpc (1 file)
INSTALL include/linux/tc_act (15 files)
INSTALL include/linux/tc_ematch (5 files)
INSTALL include/linux/usb (13 files)
INSTALL include/linux/wimax (1 file)
INSTALL include/linux (505 files)
INSTALL include/misc (4 files)
INSTALL include/mtd (5 files)
INSTALL include/rdma/hfi (2 files)
INSTALL include/rdma (25 files)
INSTALL include/scsi/fc (4 files)
INSTALL include/scsi (5 files)
INSTALL include/sound (16 files)
INSTALL include/video (3 files)
INSTALL include/xen (4 files)
INSTALL include/asm (37 files)
➜ linux-5.1.12 cd ..

C/C++ Compilers

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
➜  aarch64 mkdir -p build-gcc
➜ aarch64 cd build-gcc
$ ../gcc-9.1.0/configure --prefix=/opt/aarch64 --enable-multiarch --enable-languages=c,c++,fortran,go --disable-multilib --disable-libvtv --enable-vtable-verify
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking target system type... aarch64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libhsail-rt support... no
checking for libphobos support... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... yes
checking for gnatbind... gnatbind
checking for gnatmake... gnatmake
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... yes
checking for the correct version of the gmp/mpfr/mpc libraries... yes
checking for isl 0.15 or later... yes
*** This configuration is not supported in the following subdirectories:
gnattools target-libada target-libhsail-rt target-libphobos target-zlib target-libobjc target-liboffloadmic target-libvtv
(Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... yes
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... flex
checking for flex... flex
checking for makeinfo... makeinfo
checking for expect... expect
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for otool... no
checking for readelf... readelf
checking for cc... cc
checking for c++... c++
checking for gcc... gcc
checking for gfortran... gfortran
checking for gccgo... gccgo
checking for gdc... no
checking for ar... /opt/aarch64/aarch64-unknown-linux-gnu/bin/ar
checking for as... /opt/aarch64/aarch64-unknown-linux-gnu/bin/as
checking for dlltool... no
checking for dlltool... no
checking for ld... /opt/aarch64/aarch64-unknown-linux-gnu/bin/ld
checking for lipo... no
checking for lipo... no
checking for nm... /opt/aarch64/aarch64-unknown-linux-gnu/bin/nm
checking for objcopy... /opt/aarch64/aarch64-unknown-linux-gnu/bin/objcopy
checking for objdump... /opt/aarch64/aarch64-unknown-linux-gnu/bin/objdump
checking for otool... no
checking for otool... no
checking for ranlib... /opt/aarch64/aarch64-unknown-linux-gnu/bin/ranlib
checking for readelf... /opt/aarch64/aarch64-unknown-linux-gnu/bin/readelf
checking for strip... /opt/aarch64/aarch64-unknown-linux-gnu/bin/strip
checking for windres... no
checking for windres... no
checking for windmc... no
checking for windmc... no
checking where to find the target ar... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target as... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target cc... just compiled
checking where to find the target c++... just compiled
checking where to find the target c++ for libstdc++... just compiled
checking where to find the target dlltool... host tool
checking where to find the target gcc... just compiled
checking where to find the target gfortran... just compiled
checking where to find the target gccgo... just compiled
checking where to find the target gdc... host tool
checking where to find the target ld... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target lipo... host tool
checking where to find the target nm... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target objcopy... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target objdump... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target otool... host tool
checking where to find the target ranlib... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target readelf... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target strip... pre-installed in /opt/aarch64/aarch64-unknown-linux-gnu/bin
checking where to find the target windres... host tool
checking where to find the target windmc... host tool
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
➜ build-gcc make -j4 all-gcc
➜ build-gcc make install-gcc
➜ build-gcc cd ..

GLibc

1
2
3
4
5
6
7
8
9
➜  aarch64 mkdir -p build-glibc
➜ aarch64 cd build-glibc
➜ build-glibc ../glibc-2.29/configure --prefix=/opt/aarch64/aarch64-linux --build=$MACHTYPE --host=aarch64-linux --target=aarch64-linux --with-headers=/opt/aarch64/aarch64-linux/include --enable-multiarch --disable-multilib --disable-libvtv --with-selinux=no --enable-vtable-verify libc_cv_forced_unwind=yes
➜ build-glibc make install-bootstrap-headers=yes install-headers
➜ build-glibc make -j4 csu/subdir_lib
➜ build-glibc install csu/crt1.o csu/crti.o csu/crtn.o /opt/aarch64/aarch64-linux/lib
➜ build-glibc /opt/aarch64/bin/aarch64-linux-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/aarch64/aarch64-linux/lib/libc.so
➜ build-glibc touch /opt/aarch64/aarch64-linux/include/gnu/stubs.h
➜ build-glibc cd ..

Compiler Support Library

1
2
3
4
➜  aarch64 cd build-gcc
➜ build-gcc make -j4 all-target-libgcc
➜ build-gcc make install-target-libgcc
➜ build-gcc cd ..

Build Standard C Library

1
2
3
4
➜  aarch64 cd build-glibc
➜ build-glibc make -j4
➜ build-glibc make install
➜ build-glibc cd ..

Build Standard C++ Library

1
2
3
4
➜  aarch64 cd build-gcc
➜ build-gcc make -j4
➜ build-gcc make install
➜ build-gcc cd ..

Finishing and Test

Check GCC Version

1
2
3
4
5
6
7
8
➜  /opt/aarch64/bin/aarch64-linux-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/aarch64/bin/aarch64-linux-gcc
COLLECT_LTO_WRAPPER=/opt/aarch64/libexec/gcc/aarch64-linux/9.1.0/lto-wrapper
Target: aarch64-linux
Configured with: ../gcc-9.1.0/configure --prefix=/opt/aarch64 --target=aarch64-linux --enable-languages=c,c++,fortran,go --disable-multilib --enable-vtable-verify : (reconfigured) ../gcc-9.1.0/configure --prefix=/opt/aarch64 --target=aarch64-linux --enable-multiarch --enable-languages=c,c++,fortran,go --disable-multilib --enable-vtable-verify : (reconfigured) ../gcc-9.1.0/configure --prefix=/opt/aarch64 --target=aarch64-linux --enable-multiarch --enable-languages=c,c++,fortran,go --disable-multilib --disable-libvtv --enable-vtable-verify
Thread model: posix
gcc version 9.1.0 (GCC)

Copy Built GCC 9.1.0 Onto Hikey 970

I actually copied some of the built folder under https://www.longervision.cc/arm/aarch64/gcc-9.1.0/. You are welcome to go try the toolchain.

Run Hello World on Hikey970

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜  GCC cat test.cpp 
#include <iostream>

int main(int argc, char** argv)
{
std::cout << "Hello World!" << std::endl;
return EXIT_SUCCESS;
}
➜ GCC x86_64-linux-gnu-c++ -std=c++17 test.cpp
➜ GCC x86_64-linux-gnu-c++ -std=c++17 test.cpp -o test
➜ GCC ls
a.out test test.cpp
➜ GCC ./test
Hello World!
➜ GCC