N1064編譯鏈編譯

来源:https://www.cnblogs.com/wangguangyu12217/p/18367897
-Advertisement-
Play Games

環境ubuntu20.04 Arm官網有源碼和編譯鏈。但是沒有編譯手冊。 從安裝版本中拿到10.3-2021.07-x86_64-aarch64-none-linux-gnu-manifest.txt 根據裡面的記錄,去進行配置和編譯。 官網下載: https://developer.arm.com ...


環境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


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Docker部署.netCore6 第一步:在項目添加Docker支持 第二步:選擇Windows(如果是linx系統就選擇linx)和Dockerfile 第三步:生成Docker預設文件 把預設代碼修改 第四步:修改Dockerfile文件屬性(如果不修改則會導致發佈的時候Docker文件沒有一 ...
  • 項目使用ABP框架,最近有需求數據量會持續變大,需要分表存儲。 發現ShardinfCore可以快速實現EF分表操作,並且作者@薛家明還特別為ABP集成寫了教程,完美的選擇。 ShardinfCore作者教程很齊全,這次以ABP 8.*的用戶視角進行集成記錄,希望幫到需要的人。 開發環境: ABP ...
  • IoTClient 是一個針對物聯網 (IoT) 領域的開源客戶端庫,它主要用於實現與各種工業設備之間的通信。這個庫是用 C# 編寫的,並且基於 .NET Standard 2.0,這意味著可以用於多個版本的.NET,包括 .NET Framework、.NET Core、.NET 5 及以上版本,... ...
  • WPFUI報錯 page does not have a parameterless constructor. If you are using Wpf.Ui.IPageService do not navigate initially and don't use Cache or Precache ...
  • 邁信達音視頻字幕軟體(MaixindaSubtitle)是一款專註於自動化視頻轉錄文本、字幕製作、字幕翻譯的AI自動化字幕軟體。通過AI一鍵生成本地音頻與視頻的字幕文件,及翻譯字幕內容。使用AI提取音視頻對話內容後翻譯、生成字幕文件,可以低成本並高效地將任意語言的視頻、音頻轉錄並翻譯為目標語言,適用 ...
  • 前言 在Web應用項目中許可權認證是個繞不開的話題,傳統方法複雜又耗時。MiniAuth推出專為.NET開發者設計的簡單、實用的許可權認證項目。 MiniAuth,作為ASP.NET Core的插件,讓我們快速輕鬆實現用戶登錄、許可權檢查等功能。它支持多種認證方式,如JWT、Cookie,且易於集成到現有 ...
  • 案例 案例一 server.c #include <stdio.h> // 標準輸入輸出 #include <stdlib.h> //提供通用的工具函數,例如記憶體分配和程式退出。 #include <string.h> //提供字元串處理函數。 #include <unistd.h> //提供對 P ...
  • @目錄1.前期準備1.1 製作啟動盤1.2關閉快速啟動、安全啟動、bitlocker1.2.1 原因1.2.2 進入BIOSshell命令行進入BIOSwindows設置中高級啟動在開機時狂按某個鍵進入BIOS1.2.3 關閉Fast boot和Secure boot1.3 劃分磁碟空間1.3.1 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 推薦一款基於.NET 8、WPF、Prism.DryIoc、MVVM設計模式、Blazor以及MySQL資料庫構建的企業級工作流系統的WPF客戶端框架-AIStudio.Wpf.AClient 6.0。 項目介紹 框架採用了 Prism 框架來實現 MVVM 模式,不僅簡化了 MVVM 的典型 ...
  • 先看一下效果吧: 我們直接通過改造一下原版的TreeView來實現上面這個效果 我們先創建一個普通的TreeView 代碼很簡單: <TreeView> <TreeViewItem Header="人事部"/> <TreeViewItem Header="技術部"> <TreeViewItem He ...
  • 1. 生成式 AI 簡介 https://imp.i384100.net/LXYmq3 2. Python 語言 https://imp.i384100.net/5gmXXo 3. 統計和 R https://youtu.be/ANMuuq502rE?si=hw9GT6JVzMhRvBbF 4. 數 ...
  • 本文為大家介紹下.NET解壓/壓縮zip文件。雖然解壓縮不是啥核心技術,但壓縮性能以及進度處理還是需要關註下,針對使用較多的zip開源組件驗證,給大家提供個技術選型參考 之前在《.NET WebSocket高併發通信阻塞問題 - 唐宋元明清2188 - 博客園 (cnblogs.com)》講過,團隊 ...
  • 之前寫過兩篇關於Roslyn源生成器生成源代碼的用例,今天使用Roslyn的代碼修複器CodeFixProvider實現一個cs文件頭部註釋的功能, 代碼修複器會同時涉及到CodeFixProvider和DiagnosticAnalyzer, 實現FileHeaderAnalyzer 首先我們知道修 ...
  • 在軟體行業,經常會聽到一句話“文不如表,表不如圖”說明瞭圖形在軟體應用中的重要性。同樣在WPF開發中,為了程式美觀或者業務需要,經常會用到各種個樣的圖形。今天以一些簡單的小例子,簡述WPF開發中幾何圖形(Geometry)相關內容,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 在 C# 中使用 RabbitMQ 通過簡訊發送重置後的密碼到用戶的手機號上,你可以按照以下步驟進行 1.安裝 RabbitMQ 客戶端庫 首先,確保你已經安裝了 RabbitMQ 客戶端庫。你可以通過 NuGet 包管理器來安裝: dotnet add package RabbitMQ.Clien ...
  • 1.下載 Protocol Buffers 編譯器(protoc) 前往 Protocol Buffers GitHub Releases 頁面。在 "Assets" 下找到適合您系統的壓縮文件,通常為 protoc-{version}-win32.zip 或 protoc-{version}-wi ...
  • 簡介 在現代微服務架構中,服務發現(Service Discovery)是一項關鍵功能。它允許微服務動態地找到彼此,而無需依賴硬編碼的地址。以前如果你搜 .NET Service Discovery,大概率會搜到一大堆 Eureka,Consul 等的文章。現在微軟為我們帶來了一個官方的包:Micr ...
  • ZY樹洞 前言 ZY樹洞是一個基於.NET Core開發的簡單的評論系統,主要用於大家分享自己心中的感悟、經驗、心得、想法等。 好了,不賣關子了,這個項目其實是上班無聊的時候寫的,為什麼要寫這個項目呢?因為我單純的想吐槽一下工作中的不滿而已。 項目介紹 項目很簡單,主要功能就是提供一個簡單的評論系統 ...