下面这个数字根据服务器的核数来,对应make程序最多运行的进程个数,如果运行的服务器核数非常多,完全可以配置更大,实际上编译过程中由于文件依赖关系,大多数时候运行不了这么多进程:
make -j20
make install
cd ../../
3.2 编译Linux Kernel Headers如果目标机的linux内核版本(软件和运行的硬件)和host完全一样的话,可以直接用apt命令下载,如果不是完全一样的话就需要重新编译一下头文件。
cd linux-4.15.1/
make ARCH=arm64 INSTALL_HDR_PATH=http://www.likecs.com/opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/ headers_install
cd ..
内核里面的硬件体系名和gcc不一样,例如这里的aarch64在linux内核里面还是叫arm64,另外一个参数指向要安装头文件的目录。
3.3 编译C/C++ Compilerscd gcc-9.4.0
mkdir xxx_aarch64_gcc9.4.0_glibc2.23linux_build
cd xxx_aarch64_gcc9.4.0_glibc2.23linux_build
../configure --prefix=http://www.likecs.com/opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux --target=aarch64-linux-gnu --with-glibc-version=2.23 --enable-languages=c,c++ --disable-multilib --with-protoc
make -j20 all-gcc
make install-gcc
cd ..
先把编译器编译出来。
3.4 编译Standard C Library Headers and Startup Filescd glibc-2.23
mkdir xxx_aarch64_gcc9.4.0_glibc2.23linux_build
cd xxx_aarch64_gcc9.4.0_glibc2.23linux_build
../configure --prefix=http://www.likecs.com/opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu --build=$MACHTYPE --host=aarch64-linux-gnu --target=aarch64-linux-gnu --disable-multilib
make install-bootstrap-headers=yes install-headers
make -j20 csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o /opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/lib
aarch64-linux-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/lib/libc.so
touch /opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/include/gnu/stubs.h
cd ..
csu/crt1.o csu/crti.o csu/crtn.o这几个库文件后面编译是需要的,但没有自动安装。libc.so和stubs.h后面第3.5步需要,但第3.6步会重新生成。
3.5 编译gcc所需要的库cd gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build
make -j20 all-target-libgcc
make install-target-libgcc
cd ../../
3.6 编译glibc库cd glibc-2.23/xxx_aarch64_gcc9.4.0_glibc2.23linux_build
make -j20
make install
cd ../../
3.6 编译c++库cd gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build
make -j20
make install
cd ../../
4 遇到的编译问题
9.4的gcc源代码有个错误,报PATH_MAX未定义,搜了一下头文件中的定义,最大是4096,手工改成4096之后编译通过:
libtool: compile: /home/ronghua.zhou/zrh/gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build/./gcc/xgcc -shared-libgcc -B/home/ronghua.zhou/zrh/gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build/./gcc -nostdinc++ -L/home/ronghua.zhou/zrh/gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build/aarch64-linux-gnu/libstdc++-v3/src -L/home/ronghua.zhou/zrh/gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build/aarch64-linux-gnu/libstdc++-v3/src/.libs -L/home/ronghua.zhou/zrh/gcc-9.4.0/xxx_aarch64_gcc9.4.0_glibc2.23linux_build/aarch64-linux-gnu/libstdc++-v3/libsupc++/.libs -B/opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/bin/ -B/opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/lib/ -isystem /opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/include -isystem /opt/xxx/xxx_aarch64_gcc9.4.0_glibc2.23linux/aarch64-linux-gnu/sys-include -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DASAN_HAS_EXCEPTIONS=1 -DASAN_NEEDS_SEGV=1 -DCAN_SANITIZE_UB=0 -I. -I../../../../libsanitizer/asan -I.. -I ../../../../libsanitizer/include -I ../../../../libsanitizer -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -fno-ipa-icf -I../../libstdc++-v3/include -I../../libstdc++-v3/include/aarch64-linux-gnu -I../../../../libsanitizer/../libstdc++-v3/libsupc++ -std=gnu++11 -g -O2 -D_GNU_SOURCE -MT asan_poisoning.lo -MD -MP -MF .deps/asan_poisoning.Tpo -c ../../../../libsanitizer/asan/asan_poisoning.cc -fPIC -DPIC -o .libs/asan_poisoning.o
../../../../libsanitizer/asan/asan_linux.cc: In function 'void __asan::AsanCheckIncompatibleRT()':
../../../../libsanitizer/asan/asan_linux.cc:216:21: error: 'PATH_MAX' was not declared in this scope
216 | char filename[PATH_MAX];
| ^~~~~~~~
../../../../libsanitizer/asan/asan_linux.cc:217:35: error: 'filename' was not declared in this scope; did you mean 'fileno'?
217 | MemoryMappedSegment segment(filename, sizeof(filename));
| ^~~~~~~~
| fileno
Makefile:599: recipe for target 'asan_linux.lo' failed
make[4]: *** [asan_linux.lo] Error 1
make[4]: *** Waiting for unfinished jobs....
vi gcc-9.4.0/libsanitizer/asan/asan_linux.cc
5 怎么用?