N1064编译链编译

环境ubuntu20.04

Arm官网有源码和编译链。但是没有编译手册。
从安装版本中拿到10.3-2021.07-x86_64-aarch64-none-linux-gnu-manifest.txt
根据里面的记录,去进行配置和编译。
官网下载: https://developer.arm.com/downloads/-/gnu-a

下载文件,存放到download中
$cd toolchain_build;
$mkdir build output src
解压文件
$cd download/
$for f in *.tar*; do tar -xf $f -C ../src; done
$cd ../
这里export TARGET PROJECT SYSROOT
$export TARGET=aarch64-none-linux-gnu
$export PROJECT=$PWD
$export SYSROOT=$PROJECT/output/$TARGET/libc
做准备工作,编译安装gmp mpc mpfr isl 到build/host-libs目录
$chmod u+x build_prerequisites.sh; ./build_prerequisites.sh$cd build/; mkdir build-binutils build_gcc1 build_gcc2 build_gcc3 build_gcc4 build_glibc
编译binutils
$cd build-binutils
$../../src/binutils/configure --enable-64-bit-bfd   --enable-targets=arm-none-eabi,aarch64_be-none-linux-gnu,aarch64_be-none-elf,aarch64-none-linux-gnu,aarch64-none-linux-gnu_ilp32,aarch64-none-elf --target=aarch64-none-linux-gnu --with-bugurl="https://bugs.linaro.org/" --enable-gold --enable-initfini-array --enable-plugins --disable-doc --disable-gdb --disable-gdbtk --disable-nls --disable-tui --disable-werror --without-gdb --without-python --without-x --prefix=$PROJECT/output  --with-build-sysroot=$SYSROOT --with-sysroot=/aarch64-none-linux-gnu/libc --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)'
$make -j8; make install  
编译gcc1
$cd ../build_gcc1
$../../src/gcc/configure --target=aarch64-none-linux-gnu --prefix=$PROJECT/output --with-sysroot=/aarch64-none-linux-gnu/libc --with-build-sysroot=$SYSROOT --without-headers --with-newlib --with-bugurl="https://bugs.linaro.org/" --without-cloog --without-isl --disable-shared --disable-threads --disable-libatomic --disable-libsanitizer --disable-libssp --disable-libgomp --disable-libmudflap --disable-libquadmath --enable-checking=yes -disable-libstdcxx --disable-libvtv --enable-languages=c,c++ --with-gmp=$PROJECT/build/host-libs/  --with-mpfr=$PROJECT/build/host-libs/ --with-mpc=$PROJECT/build/host-libs/ --enable-fix-cortex-a53-843419 --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)'
$make -j8; make install  

1.gcc1主要生成aarch64-none-linux-gnu-gcc供后续使用。所以下一步需要export PATH。
2.在官方文档上没有-disable-libstdcxx --disable-libvtv和c++,是因为glibc编译时出错
build_glibc/support/links-dso-program.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
经查links-dso-program.cc,是用g++编译成links-dso-program.o,而我们此时--enable-languages=c还没有编译出g++, 所以此处冒险在gcc1中把c++给添加上来。

此时在环境变量中添加上刚刚编译出来的aarch64-none-linux-gnu-gcc的路径,后面的编译中会使用到
$export PATH=$PATH:$PROJECT/output/bin

解压linux,并安装,后续编译会使用
$cd ../../src/linux-4.20.13
$make ARCH=arm64 headers_check
$make ARCH=arm64 headers_install INSTALL_HDR_PATH=$PROJECT/output/aarch64-none-linux-gnu/libc/usr/
第一次glibc编译,为gcc2的编译提供一些头文件和库文件
$cd ../../build/build_glibc/
$../../src/glibc_v2.33/configure --enable-shared --with-tls --disable-profile --disable-omitfp --disable-bounded --disable-sanity-checks --prefix=$SYSROOT/usr  --with-headers=$SYSROOT/usr/include --includedir=$SYSROOT/usr/include --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)' --build=x86_64-unknown-linux-gnu --host=aarch64-none-linux-gnu --disable-werror --enable-obsolete-rpc --disable-profile --without-gd --without-cvs --without-selinux
$make install-bootstrap-headers=yes install-headers
$make -j8 csu/subdir_lib;
$install csu/crt1.o csu/crti.o csu/crtn.o $PROJECT/output/$TARGET/lib
$$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $PROJECT/output/$TARGET/lib/libc.so
$touch $SYSROOT/usr/include/gnu/stubs.h

报错:
check_fds.c: Assembler messages:
check_fds.c:81: Error: no such instruction: 'brk '
make[2]: *** [../o-iterator.mk:9: /home/test/toolchain_build/build/build_glibc/csu/check_fds.o] Error 1
make[2]: *** Waiting for unfinished jobs....
../sysdeps/unix/sysv/linux/aarch64/__read_tp.S: Assembler messages:
../sysdeps/unix/sysv/linux/aarch64/__read_tp.S:22: Error: no such instruction: 'hint 34'
../sysdeps/unix/sysv/linux/aarch64/__read_tp.S:23: Error: no such instruction: 'mrs x0,tpidr_el0'
../sysdeps/aarch64/nptl/tls.h:95:21: error: ‘__builtin_thread_pointer’ is not supported on this target
95 | ((struct pthread *)__builtin_thread_pointer () - 1)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../csu/libc-start.c:322:30: note: in expansion of macro ‘THREAD_SELF’
322 | struct pthread *self = THREAD_SELF;

解决:在linux安装时执行make ARCH=arm64 headers_check

第二次gcc编译,gcc2
$cd ../build_gcc2
$../../src/gcc/configure --target=aarch64-none-linux-gnu --prefix=$PROJECT/output --with-sysroot=/aarch64-none-linux-gnu/libc --with-build-sysroot=$SYSROOT --with-bugurl="https://bugs.linaro.org/" --enable-shared --disable-libatomic --without-cloog --without-isl --disable-libssp --disable-libgomp --disable-libmudflap --disable-libquadmath --enable-checking=yes --enable-languages=c --with-gmp=$PROJECT/build/host-libs/ --with-mpfr=$PROJECT/build/host-libs/  --with-mpc=$PROJECT/build/host-libs/ --enable-fix-cortex-a53-843419 --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)'
make -j8
make install

注意:必须先执行glibc1并成功,否则会有如下这些错误:
aarch64-none-linux-gnu/libc/usr/include/features.h:497:10: fatal error: gnu/stubs.h: No such file or directory
: cannot find crti.o: No such file or directory
/home/test/toolchain_build/output/aarch64-none-linux-gnu/bin/ld: cannot find -lc
make[2]: *** [Makefile:994: libgcc_s.so] Error 1
make[2]: Leaving directory '/home/test/toolchain_build/build/build_gcc2/aarch64-none-linux-gnu/libgcc'
make[1]: *** [Makefile:11990: all-target-libgcc] Error 2
make[1]: Leaving directory '/home/test/toolchain_build/build/build_gcc2'

第二次glibc的编译,glibc2
$cd ../build_glibc
$make clean
$make -j8; make install
第三次gcc的编译,gcc3
$cd ../build_gcc3
$../../src/gcc/configure --target=aarch64-none-linux-gnu --prefix=$PROJECT/output --with-sysroot=/aarch64-none-linux-gnu/libc --with-build-sysroot=$SYSROOT --with-bugurl="https://bugs.linaro.org/" --enable-gnu-indirect-function --enable-shared --disable-libssp --disable-libmudflap --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=$PROJECT/build/host-libs/ --with-mpfr=$PROJECT/build/host-libs/  --with-mpc=$PROJECT/build/host-libs/  --with-isl=$PROJECT/build/host-libs/ --enable-fix-cortex-a53-843419 --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)'
$cp $SYSROOT/usr/lib/* $PROJECT/output/$TARGET/lib/
$make -j8; make install

报错:cc1: error: no include path in which to search for stdc-predef.h
The directory that should contain system headers does not exist:
解决:这个时候不要怀疑别的,先检查报错的这个路径。
报错:C compiler cannot create executables.
查找对应的config.log。发现如下打印
/../sysdeps/aarch64/start.S:83: undefined reference to '__libc_csu_init', 这个是glibc编出来的库,但是现在找不到。
解决:找不到库,但是实际上已经编译出来了,我们做一下拷贝
cp $SYSROOT/usr/lib* $SYSROOT/../lib/

第四次gcc的编译,gcc4
$cd ../build_gcc4
$../../src/gcc/configure --target=aarch64-none-linux-gnu --prefix=$PROJECT/output  --with-sysroot=$SYSROOT --with-bugurl="https://bugs.linaro.org/" --enable-shared --disable-libssp --disable-libmudflap --enable-checking=yes --enable-languages=c,c++,fortran --with-gmp=$PROJECT/build/host-libs/ --with-mpfr=$PROJECT/build/host-libs/ --with-mpc=$PROJECT/build/host-libs/ --with-isl=$PROJECT/build/host-libs/ --enable-fix-cortex-a53-843419 --with-pkgversion='GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29)'
$make -j8; make install
参考文档:

https://docs.slackware.com/howtos:hardware:arm:gcc-10.x_aarch64_cross-compiler
https://jasonblog.github.io/note/raspberry_pi/how_to_build_a_gcc_cross-compiler.html
https://blog.csdn.net/birencs/article/details/124615193
https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
https://github.com/apritzel/cross/blob/master/README.md
https://github.com/novelinux/compiler-gcc/blob/master/MakeCrossGcc.md
https://www.cnblogs.com/summitzhou/p/12503647.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/783919.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【OpenCV教程】滤波和边缘检测的过程

@目录1.均值滤波1.1 卷积核形状1.2 API1.3 效果2.高斯滤波2.1 卷积核形状2.2 API2.3 效果3.中值滤波3.1 原理3.2 API3.3 效果4.高斯双边滤波4.1 原理4.2 API4.3 效果5.获取用来形态学操作的滤波器6.腐蚀和膨胀(对二值图)6.1 原理6.2 腐蚀API6.3 效果6.4 膨胀API6.5 效果7.形态…

Excel公式和基本函数

输入完公式,点击回车,即可显示出值,<>是不等号

03-Matlab数组与矩阵

数组的建立和操作数组算术运算数组信息获取矩阵的建立矩阵的扩展矩阵的块操作矩阵中元素的删除赋值为一对方括号 矩阵的转置加点不转置为共轭复数 没点的转置为共轭复数 矩阵的旋转矩阵的翻转矩阵尺寸的改变矩阵加减法矩阵乘法矩阵除法矩阵中元素查找矩阵元素排序矩阵元素求和矩…

云音乐贵州机房迁移总体方案回顾

一、背景 2023年确定要将云音乐整体服务搬迁至贵州机房,项目需要在各种限制条件下,保障2000+应用、100w+QPS的服务稳定迁移,是云音乐历史上规模最大、人员最多、难度最高的技术项目。在此过程中,解决了大量历史技术债务,同时化解了大量新增系统性风险。以下为总体方案回顾…

湿式复合机剥离涂布机切纸机高静电横切机PLC数据采集系统车间联网方案

序号 设备名称 品牌/厂家 型号 数量 "系统类型" 品牌/厂家 "其他型号补充说明" "可用通讯接 口" 数采需求内容1 "复合机组(1#)" "松德机械股份有限公司" FTB1600 1 PLC "西门子PLC(SIEMENS)" S7-300 R…

关于SEGGER Embedded Studio的一些设置,自己摸索的

1. 删除Embedded Studio最近的项目 如下图所示,File->Recent Projects->Manage Recent Projects,就可以打开 Recent Projects 视图窗口,在此窗口中右键点击项目,进行删除,或者其他操作。2. Embedded Studio的启动文件问题 我原来的疑惑是Embedded Studio有自己的启动…

[开源分享]一个用于单片机IAP自动发送的串口助手,上位机,使用Python+tkinter制作

使用Python + tkinter制作。 这是个给单片机通过串口进行IAP的上位机,与单片机中的BOOT程序配合使用,完成对单片机APP程序的升级。可以完成bin文件的切片,CRC校验(使用Crc32Mpeg2),打包自动发送。使用Python + tkinter制作。 功能: 这是个给单片机通过串口进行IAP的上位…

go语言学习过程报错处理-哇哈哈哈

用学习来麻痹自己蠢蠢欲动的心。题记无聊学习ing,思考了下还是学下go语言写免杀木马吧,毕竟在我的学习计划里放了小半年了,上班的时候还没多少自己的时间学习。为什么无聊大家都懂吧,应该会懂的吧。主要还是需要分散下注意力,近期脑子整天都是奇奇怪怪的幻想,太影响人了。…

来了!2024 云栖大会正式启动

来了!2024 云栖大会正式启动

[开源分享]一个用于单片机IAP自动升级的串口助手,上位机,使用Python+tkinter制作

使用Python + tkinter制作。 这是个给单片机通过串口进行IAP的上位机,与单片机中的BOOT程序配合使用,完成对单片机APP程序的升级。可以完成bin文件的切片,CRC校验(使用Crc32Mpeg2),打包自动发送。使用Python + tkinter制作。 功能: 这是个给单片机通过串口进行IAP的上位…

资产负债率、净资产收益率如何解读?教你弄懂财务报表的关键

财务报表中包含大量的信息,如果我们在解读财务报表时没有思路,不分重点,就很容易被繁杂的数据弄得头晕眼花。本文就财务报表中的关键指标、资产负债率解读、净资产收益率分析、计算销售复合增长率等几个方面进行介绍,大家可以根据自己的需要进行选择性的学习。 一、这些指标…

程序运行异常: Modulo by zero

用户在使用PbootCMS系统时遇到一个问题,即在网站描述或栏目描述中添加百分号(%)会导致错误。其实, 解决并不复杂。 将模板中标题、描述、关键词用下面的标签替换就可以解决<title>{pboot:pagetitle}</title><meta name="keywords" content="…