必備
在講解各編譯器之前,必須先了解一下以下文件。這些文件在編譯器目錄下或者編譯生成目標平臺的可執行程序時經常見到。此外,還需要注意區分 Windows 平臺 和 Linux 平臺的文件。
- .o 文件: 指的是 object 文件,俗稱目標文件。在 Linux 下擴展名縮寫爲 .o,在 windows 下通常爲 .obj 文件。
- .a 文件: 指的是 archive 文件,俗稱靜態庫文件。在 Linux 下擴展名縮寫爲 .a,在 windows 下通常爲 .lib 文件。
- .so 文件: 指的是 shared object 文件,用於動態連接的。在 Linux 下擴展名縮寫爲 .so,在 windows 下通常爲 .dll 文件。
.o 文件是鏈接文件,.a 是靜態庫文件,需要 .o 文件生成,作爲一個庫爲外部程序提供函數接口。詳細的可以看一下博文 ARM 之一 鏡像文件(Image)/可執行文件/ELF文件/對象文件 詳解。
在交叉編譯工具鏈目錄中,有大量的 .o 和 .a 文件。這些文件在我們編譯目標平臺時會被用到!爲什麼在Windows下面的編譯工具鏈中會有這麼多的 .o 和 .a 文件呢?這是因爲編譯工具鏈是在 Linux 系統 中編譯生成的! 。看下圖:
如果有親自編譯過交叉編譯工具鏈,那麼就一定會見到 build、host 和 target 這幾個參數:
- –build=編譯該軟件(就是指的交叉編譯工具鏈本身)所使用的平臺
- –host=該軟件(就是指的交叉編譯工具鏈本身)將運行的平臺
- –target=該軟件(就是指的交叉編譯工具鏈本身)所要處理的目標平臺。即交叉編譯工具鏈編譯出來的程序運行的平臺
比較
目前,針對於 ARM 平臺的主流編譯器主要有以下三者:
比較 | ARMCC | IAR | GCC for ARM |
---|---|---|---|
命令行工具 | 隨IDE發佈,也獨立提供 | 僅隨其IDE發佈,不獨立提供 | 獨立提供 |
開發商 | ARM | IAR | ARM、Linaro、Mentor |
支持的平臺 | Windows、Linux | Windows | Windows、Linux、Mac(部分) |
配套 IDE | Keil MDK、ARM Development Studio 5、ADS | IAR EMBEDDED WORKBENCH FOR ARM | 除以上兩者外的其他支持ARM的IDE,例如:eclipse、Visual Studio |
官網 | https://developer.arm.com/tools-and-software/embedded/arm-compiler/downloads | https://www.iar.com/iar-embedded-workbench/ | 1. https://launchpad.net/gcc-arm-embedded 2. https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads |
ARM
ARM 官網上除了提供了配套 IDE(參考博文《ARM 之 各集成開發環境(IDE)說明(Keil、RVDS、ADS、DS-5、MDK)》) 以外,每次都會提供編譯器的獨立下載。用戶可以單獨安裝編譯器,編譯器採用命令行形式使用。
也就是說,ARM 的 IDE 和編譯器是相互獨立的,使用者可以爲同一個IDE配置不同版本的編譯器!目前,ARM 官方提供兩個版本的編譯器,如下圖所示:
其中,Arm Compiler 6 是 Arm Compiler 5 的替代者!相比於 Arm Compiler 5 的 Edison Design Group 使用的編譯器前端,Arm Compiler 6 將編譯器前端換爲了基於 LLVM 的 Clang!
在 ARM 官網的介紹中,有如下一段話
General update releases on the last branch, version 5.06, ended in H2 2017 with 5.06u6. After this, further support and maintenance will be available through Arm Compiler Long Term Maintenance releases with maintenance continuing until at least summer 2020. Arm Compiler 5.06 for Certification and Arm Compiler 5.06 Long Term Maintenance releases will each be supported by an Arm Compiler Qualification Kit.
大意就是,Arm Compiler 5 以後就要退出舞臺了!在 ARM 內核的支持上,Arm Compiler 6 也要比 Arm Compiler 5 完善的多!
目前,ARM 官方的 IDE都會包含這兩個版本的編譯器。例如,在 Keil MDK 的安裝目錄下面會有如下兩個目錄,分別對應了 Arm Compiler 5 和 Arm Compiler 6
上面說了,以上編譯器 ARM 也提供獨立下載安裝,具體見上文的官網地址即可!我本身安裝了多個版本的 ARM編譯器,如下:
- Edison Design Group 是一家公司,靠賣產品給賣編譯器的公司生存,它賣的是前端,包括C++、Java和Fortran前端,全世界幾乎所有商用編譯器,都會用這家公司的前端。最重要的,這家公司只有5個人。
這五個人依次是:Mike Miller, Daveed Vandevoorde, Steve Adamczyk, John Spicer, Mike Herricl。Daveed Vandevoorde 寫過兩本書《C++ Templates》和《C++ Solutions》,Mike Miller是C++專家,實現部分C++的功能。Mike Herrick在Bell實驗室呆了19年。Steve Adamczyk和John Spicer是EDG的創建者。- 在最早期,ARM 的編譯器也是隨 IDE 發佈的,如 ADS 時代!
armcc.exe
The ARM and Thumb® compiler. This compiles your C and C++ code.It supports inline and embedded assemblers, and also includes the Advanced SIMD vectorizingcompiler. ARM和Thumb®編譯器。 這將編譯您的 C 和 C++代碼。它支持內聯和嵌入式彙編程序,還包括高級SIMD矢量化編譯器。
編譯器支持將以下不同標準的C和C ++源代碼編譯爲 ARM 和 Thumb® 代碼:
- ISO Standard C:1990 source.
- ISO Standard C:1999 source.
- ISO Standard C++:2003 source.
- ISO Standard C++:2011 source.
armcc
符合 Base Standard Application Binary Interface for the ARM Architectur(ARM體系結構的基本標準應用程序二進制接口,BSABI)。 特別是編譯器:
- 生成 ELF 格式的對象文件。 參考博文《ARM 之 鏡像文件(Image)/可執行文件/ELF文件/對象文件 詳解》。
- 生成基於 Debug With Arbitrary Record Format Debugging Standard Version 3 (DWARF 3) 的調試信息 並且包含對於 DWARF 2 debug tables的支持。
- 使用 Edison Design Group (EDG) 編譯器前端!
D:\ARM\ARM_Compiler_5.06u4>armcc
Product: ARM Compiler 5.06
Component: ARM Compiler 5.06 update 4 (build 422)
Tool: armcc [4d3604]
Usage: armcc [options] file1 file2 ... filen
Main options:
--arm Generate ARM code 創建 ARM 代碼
--thumb Generate Thumb code 創建 Thumb 代碼
--c90 Switch to C mode (default for .c files) 切換到C模式 (默認是 .c 文件)
--cpp Switch to C++ mode (default for .cpp files) 切換到C++模式 (默認 .cpp 文件)
-O0 Minimum optimization 最小優化級別
-O1 Restricted optimization for debugging 受限的調試級別優化
-O2 High optimization 高優化
-O3 Maximum optimization 最大優化
-Ospace Optimize for codesize 對代碼大小進行優化
-Otime Optimize for maximum performance 優化最大優化級別的運行時間
--cpu <cpu> Select CPU to generate code for 選擇CPU
--cpu list Output a list of all the selectable CPUs 輸出所有被選中的CPU列表
-o <file> Name the final output file of the compilation 最終輸出文件的名字
-c Compile only, do not link 只進行編譯,不鏈接
--asm Output assembly code as well as object code 輸出彙編以及obj文件
-S Output assembly code instead of object code 只輸出彙編文件
--interleave Interleave source with disassembly (use with --asm or -S) 交叉反彙編 (use with --asm or -S)
-E Preprocess the C source code only 僅僅預處理C代碼
-D<symbol> Define <symbol> on entry to the compiler 定義 <symbol> 符號並且傳入編譯過程
-g Generate tables for high-level debugging 爲高級別調試創建表
-I<directory> Include <directory> on the #include search path 在編譯的時候包含 <directory> 作爲頭文件搜索目錄
其默認的頭文件搜索路徑如下圖所示:
armasm.exe
The ARM and Thumb assembler. This assembles ARM and Thumb assembly language sources. ARM 和 Thumb 彙編器。這將彙編 ARM 和 Thumb 彙編語言源文件。
D:\ARM\ARM_Compiler_5.06u4>armasm
Product: ARM Compiler 5.06
Component: ARM Compiler 5.06 update 4 (build 422)
Tool: armasm [4d35cf]
For Educational purposes only
Software supplied by: ARM Limited
Usage: armasm [options] sourcefile
Options:
--list listingfile Write a listing file (see manual for options) 生成列表文件
-o outputfile Name the final output file 命名最終輸出文件名
--depend dependfile Save 'make' source file dependencies 保留 'make' 源文件依賴
--errors errorsfile Put stderr diagnostics to errorsfile 把標準錯誤判斷放入errorsfile
-I dir[,dir] Add dirs to source file search path 添加源文件的搜索目錄
--pd
--predefine directive Pre-execute a SET{L,A,S} directive 預執行 SET{L,A,S} 指令
--maxcache <n> Maximum cache size (default 8MB) 最大閃存空間 (default 8MB)
--no_esc Ignore C-style (\c) escape sequences 忽略C風格(\ c)轉義序列
--no_warn Turn off Warning messages 關閉警告信息
-g Output debugging tables 輸出調試表
--apcs /<quals> Make pre-definitions to match the
chosen procedure-call standard 進行預定義以匹配選擇的程序調用標準
--checkreglist Warn about out of order LDM/STM register lists 警告LDM/STM寄存器列表出現故障
--help Print this information 打印幫助信息
--li Little-endian ARM 小端模式的 ARM
--bi Big-endian ARM 大端模式的 ARM
-M Write source file dependency lists to stdout 將源文件依賴關係列表寫入stdout
--MD Write source file dependency lists to inputfile.d 將源文件依賴關係列表寫入inputfile.d
--keep Keep local labels in symbol table of object file 將本地標籤保存在目標文件的符號表中
--regnames none Do not predefine register names 不預定義寄存器名稱
--split_ldm Fault long LDM/STM
--unsafe Downgrade certain errors to warnings 將某些錯誤降級爲警告
--via <file> Read further arguments from <file> 從<file>中讀取更多參數
--cpu <target-cpu> Set the target ARM core type 設置目標ARM核心類型
--cpu list Output a list of all the selectable CPUs 輸出所有可選CPU的列表
--fpu <target-arch> Set target FP architecture version 設置目標FP架構版本
--fpu list Output a list of all selectable FP architectures 輸出所有可選FP架構的列表
--thumb Assemble Thumb instructions 彙編 Thumb 指令
--arm Assemble ARM instructions 彙編 ARM 指令
armlink.exe
The linker. This combines the contents of one or more object files with selected parts of one ormore object libraries to produce an executable program.A 64-bit version of armlink is also provided that can access the greater amount of memoryavailable on 64-bit machines. It supports all the features that are supported by the 32-bit versionof armlink in this release. 連接器。這將一個或多個目標文件的內容與一個或多個對象庫的選定部分組合在一起,以生成可執行程序。還提供了64位版本的armlink,可以訪問64位計算機上可用的更大內存量。它支持此版本中32位版本的armlink支持的所有功能。
If you are using ARM Compiler as a standalone product, then the 32-bit version is used bydefault. 如果您使用ARM編譯器作爲獨立產品,則默認使用32位版本。
For ARM Compiler in DS-5, the linker version depends on the host platform. 32-bit tools havethe 32-bit linker and 64-bit tools have the 64-bit linker. You do not get both versions.For the Microcontroller Developer Kit (MDK), only the 32-bit linker is provided. 對於DS-5中的ARM編譯器,鏈接器版本取決於主機平臺。 32位工具具有32位鏈接器,64位工具具有64位鏈接器。 您沒有獲得這兩個版本。對於微控制器開發工具包(MDK),僅提供32位鏈接器。
D:\ARM\ARM_Compiler_5.06u4>armlink
Product: ARM Compiler 5.06
Component: ARM Compiler 5.06 update 4 (build 422)
Tool: armlink [4d35d2]
For Educational purposes only
Software supplied by: ARM Limited
Usage: armlink option-list input-file-list
where
option-list is a list of case-insensitive options. 不區分大小寫的選項列表。
input-file-list is a list of input object and library files. 輸入對象或者庫文件列表。
General options (abbreviations shown capitalised):
--help Print this summary. 顯示幫助信息。
--output file Specify the name of the output file. 指定輸出文件名。
--via file Read further arguments from file.
Options for specifying memory map information:
--partial Generate a partially linked object. 創建一個被分散鏈接的對象文件。
--scatter file Create the memory map as described in file. 按文件(分散加載文件)中的描述創建內存映射。
--ro-base n Set exec addr of region containing RO sections. 設置執行地址空間域,包含RO段(只讀數據段)。
--rw-base n Set exec addr of region containing RW/ZI sections. 設置執行地址空間域,包含RW/ZI段。
Options for controlling image contents:
--bestdebug Add debug information giving best debug view to image. 添加調試信息,爲鏡像提供最佳調試視圖。
--datacompressor off
Do not compress RW data sections. 不要壓縮RW數據段。
--no_debug Do not add debug information to image. 不添加調試信息。
--entry Specify entry sections and entry point. 指定輸入段與輸入點。
--libpath Specify path to find system libraries from. 指定系統庫文件路徑。
--userlibpath Specify path to find user libraries from. 指定用戶庫文件路徑。
--no_locals Do not add local symbols to image symbol table. 不要添加局部標號到image的標號列表。
--no_remove Do not remove unused sections from image. 不要移除image的未使用段。
Options for controlling image related information:
--callgraph Create a static callgraph of functions. 創建一個函數靜態調用圖。
--feedback file Generate feedback that can be used by the compiler in file.
--info topic List misc. information about image.
Available topics: (separate multiple topics with comma)
common List common sections eliminated from the image.
debug List eliminated input debug sections.
sizes List code and data sizes for objects in image.
totals List total sizes of all objects in image.
veneers List veneers that have been generated.
unused List sections eliminated from the image.
--map Display memory map of image. 顯示image內存映射。
--symbols List symbols in image. 列出image符號。
--xref List all cross-references between input sections. 列出輸入的段之間所有的交叉引用.最終輸出會放在.map文件裏面。
armar.exe
The librarian. This enables sets of ELF object files to be collected together and maintained inarchives or libraries. You can pass such a library or archive to the linker in place of several ELFfiles. You can also use the archive for distribution to a third party for further applicationdevelopment. 庫文件管理工具。 這使得 ELF 對象文件集可以一起收集並維護在原始文件或庫中。 您可以將此類庫或存檔傳遞給鏈接器以代替多個ELF文件。 您還可以使用存檔分發給第三方以進行進一步的應用程序開發。
D:\ARM\ARM_Compiler_5.06u4>armar
Product: ARM Compiler 5.06
Component: ARM Compiler 5.06 update 4 (build 422)
Tool: armar [4d35c8]
Archive creation and maintenance tool
Command format:
armar options archive [ file_list ]
Wildcards '?' and '*' may be used in file_list
Options:-
-r Insert files in <file_list>, replace existing members of the same name. 在 <file_list> 中插入文件, 替換掉已經存在的同名成員。
-d Delete the members in <file_list>. 從 <file_list> 中刪除成員。
-x Extract members in <file_list> placing in files of the same name. 從 <file_list> 中提取同名的成員。
-m Move files in <file_list>. 在 <file_list> 中移動文件。
-p Print files to stdout. 打印文件到標準輸出設備。
-a pos Insert/move files after file named <pos>. 插入/刪除 <pos> 後面的文件。
-b pos Insert/move files before file named <pos>. 插入/刪除 <pos> 前面的文件。
-u Update older files only, used with -r. 只更新舊的文件, 與 -r 一起使用。
-n Do not add a symbol table to an object archive. 不要向 object 文件中添加符號表。
-s Force regeneration of archive symbol table. 強制重新生成文檔符號表。
-t Print table of contents of archive. 打印文檔的內容表。
--zs Show the symbol table. 顯示符號表。
--zt Summarize the archive contents (sizes + entries). 彙總文檔內容 (大小和輸入)。
-c Suppress warning when a new archive is created. 當一個新文檔被創建的時候不顯示警告。
-C Do not overwrite existing files when extracting. 提取的時候不要覆蓋一個已經存在的文件。
-T Truncate file names to system maximum length. 截取系統最大長度文件名。
-v Give verbose output. 提供詳細輸出。
--create Force creation of a new archive. 強制創建一個新文檔。
--via file Take additional arguments from via file. 從 via 文件中獲取額外參數。
--sizes List the size of each member and the library total. 列出所有成員大小與庫的總大小。
--entries List sections containing ENTRY points. 列出包括入口點的部分。
--vsn Print the current Armar Version. 打印最新的armar版本。
--help Print this message. 打印幫助信息。
Examples:-
armar -r mylib.a obj1 obj2 obj3...
armar -x mylib.a ?sort*
armar -d mylib.a hash.o
armar -tv ansilib.a
fromelf.exe
The image conversion utility. This can also generate textual information about the input image,such as its disassembly and its code and data size.鏡像轉換實用程序。 這還可以生成有關輸入圖像的文本信息,例如其反彙編及其代碼和數據大小。
D:\ARM\ARM_Compiler_5.06u4>fromelf
Product: ARM Compiler 5.06
Component: ARM Compiler 5.06 update 4 (build 422)
Tool: fromelf [4d35cb]
ARM image conversion utility. ARM 鏡像轉換工具
fromelf [options] input_file
Options:
--help display this help screen 顯示幫助信息
--vsn display version information 顯示版本信息
--output file the output file. (defaults to stdout for -text format) 輸出文件名. (默認輸出 -text 格式)
--nodebug do not put debug areas in the output image 不要輸出調試信息到映像文件中
--nolinkview do not put sections in the output image 不要輸出段信息到映像文件中
Binary Output Formats:
--bin Plain Binary 普通二進制
--m32 Motorola 32 bit Hex 摩托羅拉32位Hex碼
--i32 Intel 32 bit Hex 英特爾32位Hex碼
--vhx Byte Oriented Hex format 定向字節的 Hex 格式
--base addr Optionally set base address for m32,i32 爲 m32,i32設置基地址(可選的)
Output Formats Requiring Debug Information 輸出格式要求的調試信息
--fieldoffsets Assembly Language Description of Structures/Classes. Structures/Classes的彙編描述
--expandarrays Arrays inside and outside structures are expanded. 展開內部和外部結構的數組
Other Output Formats:
--elf ELF ELF格式
--text Text Information 文本信息
Flags for Text Information 文本信息的標誌
-v verbose 詳細信息
-a print data addresses (For images built with debug) 打印數據的地址信息 (得到的.axf映像文件)
-c disassemble code 彙編碼
-d print contents of data section 打印數據的段內容
-e print exception tables 打印異常表
-g print debug tables 打印調試表
-r print relocation information 打印重定位信息
-s print symbol table 打印符號表
-t print string table 打印字符表
-y print dynamic segment contents 打印動態段內容
-z print code and data size information 打印代碼與數據的大小信息
IAR
相比於 ARM 對於編譯器的靈活安裝,IAR 的編譯器則只跟隨其 IDE 發佈,編譯器不獨立提供。IAR 安裝後,目錄就是下面這個樣子了:
這裏我們重點關注一下arm
目錄下的相關內容。其中內容有很多,這裏主要介紹一下編譯器相關的那些,首先看下圖
我們可以手動提取其編譯器,來作爲命令行工具使用。但是對於 IAR 還是不建議這麼用,個人感覺 IAR 在設計時,估計沒考慮過讓用戶使用命令行模式來獨立使用編譯套件,因爲其編譯套件和其他好多東西都放在了一個目錄中,不像ARM 將編譯套件獨立存放。但是,IAR 的編譯套件是支持命令行使用的 ,在其介紹文檔中有這麼一句話:The compiler, assembler, and linker can also be run from a command line environment,if you want to use them as external tools in an already established project environment.
官方的介紹文檔主要就是《 IAR C/C++ Development Guide Compiling and Linking》。
- IAR 我用的比較少,主要內容來自於官方文檔。管方文檔更加詳細,如有疑問直接去官方文檔查看即可!官方文檔目錄爲
IAR安裝目錄\arm\doc
。具體如下:
- 《 IAR C/C++ Development Guide Compiling and Linking》,文檔名爲 EWARM_DevelopmentGuide.ENU.pdf
- 《IAR Assembler Reference Guide》,文檔名爲 EWARM_AssemblerReference.ENU.pdf
- 《C-STAT® Static Analysis Guide》,文檔名爲 EW_MisraC1998Reference.ENU.pdf
- 還可以直接從 IAR 的 IDE 的菜單進入:
菜單 -> help
iasmarm.exe
這個是 IAR 的彙編語言的編譯器。官方文檔是這麼介紹的:The IAR Assembler for Arm is a powerful relocating macro assembler with a versatile set of directives and expression operators. The assembler features a built-in C language preprocessor and supports conditional assembly.
大意就是: IAR Assembler for Arm是一個功能強大的重定位宏彙編程序,具有多種指令和表達式運算符。 彙編程序具有內置的C語言預處理程序,並支持條件彙編。該工具官方有個獨立的說明文檔《IAR Assembler Reference Guide》,裏面有該工具的詳細使用說明。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iasmarm
IAR Assembler V8.32.3.193/W32 for ARM
Copyright 1999-2019 IAR Systems AB.
Usage: iasmarm {<options>} <sourcefile> {<options>}
Sourcefile: source file with default extension: .msa, , .asm, or .s
Environment: IASMARM
Options (specified order is of no importance):
-B Print debug info for assembler macros
-c{DEAOM} Listing options
D: Disable listing, E: Disable macro expansion
A: List only assembled part O: List several lines of code
M: List Macro definition
-DSYMB Equivalent to: #define SYMB 1
-DSYMB=xx Equivalent to: #define SYMB xx
-e Use big-endian byte order
-Enumber Allow <number> errors
-f file Extend command line with <file> <.xcl>
-g No system include
-G Open standard input as source
-i List #included files
-Ipath Add #include search path
-j Enable alternative register names, operators and mnemonics
-l file Generate a list on: <file> <.lst>
-Lpath Generate a list on: <path> \ <source> <.lst>
-Mab Change asm.macro argument quote chars,
where a is start-of-quote and b is end-of-quote char.
default is a == < and b == >.
-N No header in listing
-o file Put object on: <file> <.o>
-Opath Put object on: <path> \ <source> <.o>
-pnn Page listing with 'nn' lines/page (10-150)
-r Enable debugger output in object
-S Silent operation of assembler
-s{+|-} Set case sensitivity for user symbols
-s and -s+ enables sensitivity, -s- disables it.
-tn Set tab spacing between 2 and 9 (default 8)
-USYMB Equivalent to: #undef SYMB
-ws To make warnings generate exit code 1
-wstring Disable warnings
string: <+|-,><+|-range><,+|-range>...
range: low_warning_nr<-high_warning_nr>
example: -w turns all warnings off
-w-,+10-12,+20 turns all but 10,11,12 and 20 off
-x{DI2} Generate cross-reference list
D: Show all #defines, I: Show Internal table
2: Dual line space listing
--aarch64 Generate code for AArch64, same as --cpu_mode A64
--abi {lp64|ilp32}
Specify ABI for AArch64: ilp32 or lp64.
--arm Generate code in arm mode, same as --cpu_mode arm
--cmse
Target secure mode in CMSE (ARMv8-M security extensions)
--cpu core Specify target core
Valid options are core names such as Cortex-M3
and architecture names such as 7M
Default is Cortex-M3
--cpu_mode {arm|a|thumb|t}
Select default mode for CODE directive, ARM is default
--endian {little|l|big|b}
Specify target byte order
--fpu {VFPv1|VFPv2|VFPv3{_D16}{_FP16}|VFP9-S|none}
Specify target FPU coprocessor support
Default is none, which selects the software
floating-point library.
--legacy {legacyOption}
Generate object files compatible with
older toolchains. Valid options are:
RVCT3.0
--no_dwarf3_cfi
Suppress Dwarf 3 Call Frame Information instructions
--no_it_verification
Do not verify that the instructions following
an IT instruction has the correct condition set
--no_literal_pool
Use MOV32 for LDR Rd,=expr (requires ARMv7-M)
--no_path_in_file_macros
Strip path from __FILE__ macros
--source_encoding {locale|utf8}
Encoding to use for source files with no BOM
--suppress_vfe_header
Do not generate VFE header info
--system_include_directory <path>
Set system header directory
--thumb Generate code in thumb mode, same as --cpu_mode thumb
--version Output version info and exit
iccarm.exe
這個是 IAR 的 C/C++ 編譯器。官方文檔是這麼介紹的:The IAR C/C++ Compiler for Arm is a state-of-the-art compiler that offers the standard features of the C and C++ languages, plus extensions designed to take advantage of the Arm-specific facilities.
大意就是: IAR C / C ++ Compiler for Arm是一個最先進的編譯器,提供C和C ++語言的標準功能,以及旨在利用Arm特定功能的擴展。
默認使用的頭文件目錄.\arm\inc\<vendor>
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iccarm
IAR ANSI C/C++ Compiler V8.32.3.193/W32 for ARM
Copyright 1999-2019 IAR Systems AB.
PC-locked license - IAR Embedded Workbench for ARM
Available command line options:
--aapcs {std|vfp}
Specify calling convention.
--aeabi Generate aeabi compliant code
--align_sp_on_irq
Generate code to align SP on entry to __irq functions
--arm Generate code in arm mode, same as --cpu_mode arm
--c++ C++
--c89 Use C89 standard
--char_is_signed
'Plain' char is treated as signed char
--char_is_unsigned
'plain' char is treated as unsigned char
--cmse Enable CMSE secure object generation
--cpu core Specify target core
Valid options are core names such as Cortex-M3
and architecture names such as 7M
Cortex-M3 is default
--cpu_mode {arm|a|thumb|t}
Select default mode for functions, arm is default
-D symbol[=value]
Define macro (same as #define symbol [value])
--debug
-r Insert debug info in object file
--dependencies=[i|m|n][s][lw][b] file|directory|+
List file dependencies
i Include filename only (default)
m Makefile style (multiple rules)
n Makefile style (one rule)
s Don't include system file dependencies
l Use locale encoding instead of UTF-8
w Use little endian UTF-16 instead of UTF-8
b Use a Byte Order Mark in UTF-8 output
(+: output same as -o, only with .d extension)
--deprecated_feature_warnings [+|-]feature,[+|-]feature,...
Enable (+) or disable (-) warnings about deprecated features:
attribute_syntax Warn about attribute syntax that
will change
preprocessor_extensions Warn about use of migration
preprocessor extensions
segment_pragmas Warn about use of #pragma constseg/
dataseg/memory
--diagnostics_tables file|directory
Dump diagnostic message tables to file
--diag_error tag,tag,...
Treat the list of tags as error diagnostics
--diag_remark tag,tag,...
Treat the list of tags as remark diagnostics
--diag_suppress tag,tag,...
Suppress the list of tags as diagnostics
--diag_warning tag,tag,...
Treat the list of tags as warning diagnostics
--discard_unused_publics
Discard unused public functions and variables
--dlib_config name|path
Specify DLib library configuration
--do_explicit_zero_opt_in_named_sections
Allow zero init optimization for variables in named
sections/segments
-e Enable IAR C/C++ language extensions
--enable_hardware_workaround waid[,waid[...]]
Generate hardware workaround for specified problem
--enable_restrict
Enable the restrict keyword
--endian {little|l|big|b}
Select byte order, little-endian is default
--enum_is_int Force the size of all enumeration types to be at least 4 bytes
--error_limit limit
Stop after this many errors (0 = no limit)
-f file Read command line options from file
--f file Read command line options from file and report dependency
--fpu {VFPv2|VFPv3{_D16}{_FP16}|VFPv4{_sp}|VFP9-S|none}
Specify target FPU coprocessor support
Default is none, which selects the software
floating-point library.
--generate_entries_without_bounds
Generate functions for use from non-instrumented code
--guard_calls Use a guard call for a function static initialization
--header_context
Adds include file context to diagnostics
-I directory Add #include search directory
--ignore_uninstrumented_pointers
Disable checking of accesses via pointers from uninstrumented
functions
-l[c|C|D|E|a|A|b|B][N][H] file|directory
Output list file
c C source listing
C with assembly code
D with pure assembly code
E with non-sequential assembly code
a Assembler file
A with C source
b Basic assembler file
B with C source
N Do not include diagnostics
H Include header file source lines
--lock_regs registers
Prevent compiler from using specified registers (R4-R11).
--macro_positions_in_diagnostics
Use positions inside macros in diagnostics
--make_all_definitions_weak
Make all variable and function definitions weak
--max_cost_constexpr_call limit
Maximum cost (number of calls/number of loop iterations) when
evaluating a top-level constexpr call
--max_depth_constexpr_call limit
Maximum depth of recursion when evaluating a top-level
constexpr call
--mfc Enable multiple file compilation
--misrac1998[=arg,arg,...]
Enable MISRA-C 1998 diagnostics
all Enable all rules
required Enable all required rules
i Enable rule i
i-j Enable rule i through j
~i Disable rule i
~i-j Disable rule i through j
--misrac2004[=arg,arg,...]
Enable MISRA-C 2004 diagnostics
all Enable all rules
required Enable all required rules
X Enable rule or chapter
X-Y Enable range
~X Disable rule or chapter
~X-Y Disable range
where X and Y is one of:
i All rules in chapter i
i.j Rule i.j
--misrac_verbose
Enable verbose MISRA C messages
--nonportable_path_warnings
Enable warning for non-matching case in paths
--no_alignment_reduction
Disable alignment reduction of simple thumb functions
--no_bom Don't use a Byte Order Mark in Unicode output
--no_call_frame_info
Suppress output of call frame information
--no_clustering Disable static clustering for static and global variables
--no_code_motion
Disable code motion
--no_const_align
Turn off the alignment optimization for constants
--no_cse Disable common sub-expression elimination
--no_exceptions Disable C++ exception support
--no_fragments Do not generate section fragments
--no_inline Disable function inlining
--no_literal_pool
Generate code that does not issue read request to .text
--no_loop_align Disable alignment of labels in loops (Thumb2)
--no_mem_idioms Disable idiom recognition for memcpy/memset/memclr
--no_path_in_file_macros
Strip path from __FILE__ and __BASE_FILE__ macros
--no_rtti Disable C++ runtime type information support
--no_rw_dynamic_init
Don't allow C-object to be initialized at runtime
--no_scheduling Disable instruction scheduling
--no_size_constraints
Remove limits for code expansion
--no_static_destruction
Do not emit code to destroy C++ static variables
--no_system_include
Do not search in the default system header directory
--no_tbaa Disable type based alias analysis
--no_typedefs_in_diagnostics
Do not use typedefs when printing types
--no_unaligned_access
Don't generate unaligned accesses
--no_uniform_attribute_syntax
Use old meaning for IAR type attributes before initial type
--no_unroll Disable loop unrolling
--no_var_align Turn off the alignment optimization for variables
--no_warnings Disable generation of warnings
--no_wrap_diagnostics
Don't wrap long lines in diagnostic messages
-O[n|l|m|h|hs|hz]
Select level of optimization:
n No optimizations
l Low optimizations (default)
m Medium optimizations
h High optimizations
hz High optimizations, tuned for small code size
hs High optimizations, tuned for high speed
(-O without argument) The same setting as -Oh
--only_stdout Use stdout only (no console output on stderr)
--output file|path
-o file|path Specify object file
--pending_instantiations limit
Maximum number of instantiations of a given template in
progress at a time (0 -> no limit)
--predef_macros file|directory
Output predefined macros
--preinclude filename
Include file before normal source
--preprocess=[c][n][s] file|directory
Preprocessor output
c Include comments
n Preprocess only
s Suppress #line directives
--public_equ symbol[=value]
Define public assembler symbol (EQU)
--relaxed_fp Enable floating point optimizations that may affect the result
--remarks Enable generation of remarks
--require_prototypes
Require prototypes for all called or public functions
--ropi Generate read-only position independent code
--runtime_checking check,check,...
Instrument code to do runtime checks for the selected problems:
bounds Check pointer bounds
bounds_no_checks Track pointer bounds, but emit no checks
div_by_zero Check division by zero
implicit_integer_conversion
Check only implicit integer conversion
integer_conversion Check any integer conversion
signed_overflow Check for signed integer overflow
signed_shift Check for overflow in signed shift
switch Check for unhandled cases in switch
statements
unsigned_overflow Check for unsigned integer overflow
unsigned_shift Check for overflow in unsigned shift
--rwpi Generate read-write position independent code
--rwpi_near Generate read-write position independent code
--section section-name=new section-name
Rename section
--silent Silent operation
--source_encoding {locale|utf8}
Encoding to use for source files with no BOM
--stack_protection
Insert stack smash protection
--strict Strict C/C++ standard language rules
--system_include_dir directory
Set system header directory
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--thumb Generate code in thumb mode, same as --cpu_mode thumb
--uniform_attribute_syntax
Same syntax for IAR type attributes as for const/volatile
--use_c++_inline
Use C++ inline semantics in C mode
--use_paths_as_written
Use paths as written in debug information
(normally absolute paths are used)
--use_unix_directory_separators
Use forward slashes in paths in debug information
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--vectorize Perform autovectorization
--version Output version information and exit
--vla Allow variable length arrays
--warnings_affect_exit_code
Warnings affect exit code
--warnings_are_errors
All warnings are errors
--warn_about_c_style_casts
Warn about uses of C-style casts in EC++/C++
IDE中有兩個工具可將應用程序源文件轉換爲中間文件目標文件。 IAR C / C ++編譯器和IAR彙編器。 兩者都產生行業標準格式ELF中的可重定位目標文件,包括DWARF調試信息的格式。下圖顯示了編譯過程:
ilinkarm.exe
這個是 IAR 的連接器。官方文檔是這麼介紹的:The IAR ILINK Linker for Arm is a powerful, flexible software tool for use in the development of embedded controller applications. It is equally well suited for linking small, single-file, absolute assembler programs as it is for linking large, relocatable input, multi-module, C/C++, or mixed C/C++ and assembler programs.
大意就是:IAR ILINK Linker for Arm是一款功能強大,靈活的軟件工具,可用於嵌入式控制器應用程序的開發。 它同樣適用於鏈接小型,單文件,絕對彙編程序,因爲它用於鏈接大型可重定位輸入,多模塊,C / C ++或混合C / C ++和彙編程序。
ilinkarm
使用並生成行業標準的ELF和DWARF作爲對象格式文件。在.\arm\config
目錄下,包含了針對各平臺的連接器使用的配置文件。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>ilinkarm
IAR ELF Linker V8.32.3.193/W32 for ARM
Copyright 2007-2019 IAR Systems AB.
Available command line options:
--advanced_heap Use an advanced heap manager.
--basic_heap Use a basic heap manager
--BE32 Use old type big-endian mode.
--BE8 Use byte invariant mode.
--bounds_table_size number_of_records[:number_of_buckets]|(number_of_bytes)
Specify size of bounds checking tables
--call_graph file|directory
Produce an XML call graph file
--config file Read linker configuration from file
--config_def symbol=value
Define a config symbol
--config_search directory
Look for config files in directory
--cpp_init_routine symbol
Specify C++ dynamic init routine name
--cpu core Specify target core
Valid options are core names such as Cortex-M3
and architecture names such as 7M
default is extracted from objects
--debug_heap Use heap with runtime checks
--default_to_complex_ranges
Make "complex ranges" the default in initialize directives
--define_symbol symbol=value
Define absolute symbol
--dependencies=[i|m|n][s][lw][b] file|directory|+
List file dependencies
i Include filename only (default)
m Makefile style (multiple rules)
n Makefile style (one rule)
s Don't include system file dependencies
l Use locale encoding instead of UTF-8
w Use little endian UTF-16 instead of UTF-8
b Use a Byte Order Mark in UTF-8 output
(+: output same as -o, only with .d extension)
--diagnostics_tables file|directory
Dump diagnostic message tables to file
--diag_error tag,tag,...
Treat the list of tags as error diagnostics
--diag_remark tag,tag,...
Treat the list of tags as remark diagnostics
--diag_suppress tag,tag,...
Suppress the list of tags as diagnostics
--diag_warning tag,tag,...
Treat the list of tags as warning diagnostics
--do_segment_pad
Pad segments to 4 byte alignment
--enable_hardware_workaround waid[,waid[...]]
Generate hardware workaround for specified problem
--enable_stack_usage
Enable stack usage analysis
--entry symbol Set program entry point
--error_limit limit
Stop after this many errors (0 = no limit)
--exception_tables action
Generate exception tables for modules lacking them
nocreate Do not generate entries (default)
unwind Generate unwind entries
cantunwind Generate nounwind entries
--export_builtin_config file|directory
Export the builtin configuration
--extra_init routine
Call extra init routine if defined
-f file Read command line options from file
--f file Read command line options from file and report dependency
--force_exceptions
Always include exception code
--force_output Produce an output file in spite of errors
--fpu {VFPv1|VFPv2|VFPv3{_D16}{_FP16}|VFP9-S|none}
Specify target FPU coprocessor support
Default is extracted from objects.
--ignore_uninstrumented_pointers
Disable checking of accesses via pointers in memory with
no bounds
--image_input file[,symbol[,section[,alignment]]]
Put image file in section
--import_cmse_lib_in file
Read previous version of import library for building non-secure image
--import_cmse_lib_out file|directory
Produce import library for building non-secure image
--inline Try to inline small functions.
--keep symbol Require global symbol
--log topic,topic,...
Do log output for the selected topics
call_graph Call graph with stack usage
crt_routine_selection
CRT routine implementation selection
demangle Demangle symbols in log output
fragment_info Supplementary info for --log sections
initialization Initialization decisions
inlining Small function inlining
libraries Automatic library selection
merging Results of --merge_duplicate_sections
modules Module selection
redirects Redirected symbols
sections Section fragment selection
unused_fragments Unused section fragments
veneers Veneer statistics
--log_file file Specify file for log output
--mangled_names_in_messages
Include mangled symbol names in diagnostics
--manual_dynamic_initialization
Don't perform dynamic initialization during startup
--map file|directory
Produce a linker list file
--merge_duplicate_sections
Merge equivalent read-only sections
--misrac1998[=arg,arg,...]
Enable MISRA-C 1998 diagnostics
all Enable all rules
required Enable all required rules
i Enable rule i
i-j Enable rule i through j
~i Disable rule i
~i-j Disable rule i through j
--misrac2004[=arg,arg,...]
Enable MISRA-C 2004 diagnostics
all Enable all rules
required Enable all required rules
X Enable rule or chapter
X-Y Enable range
~X Disable rule or chapter
~X-Y Disable range
where X and Y is one of:
i All rules in chapter i
i.j Rule i.j
--misrac_verbose
Enable verbose MISRA C messages
--no_bom Don't use a Byte Order Mark in Unicode output
--no_dynamic_rtti_elimination
Disable dynamic rtti elimination
--no_entry This program has no entry point
--no_exceptions Signal an error if exceptions are used
--no_fragments Always link entire sections
--no_free_heap Use a heap manager with no 'free'
--no_inline func,func,...
Do not inline any of the specified functions
--no_library_search
Disable automatic runtime library search
--no_literal_pool
Don't generate literal pool in code memory
--no_locals Do not include local symbols in output symbol table
--no_range_reservations
Do not reserve address ranges for absolute symbols
--no_remove Do not remove unused sections
--no_vfe Disable Virtual Fuction Elimination
--no_warnings Disable generation of warnings
--no_wrap_diagnostics
Don't wrap long lines in diagnostic messages
--only_stdout Use stdout only (no console output on stderr)
--output file
-o file Specify output file
--pi_veneers Generate position independent veneers.
--place_holder symbol[,size[,section[,alignment]]]
Reserve a place in ROM for later use
--preconfig file
Read before normal linker configuration file
--printf_multibytes
Enable multibyte support in printf & friends
--redirect orig=replacement
Redirect symbol refs to replacement symbol
--remarks Enable generation of remarks
--scanf_multibytes
Enable multibyte support in scanf & friends
--search directory
-L directory Look for object and library files in directory
--semihosting[=iar_breakpoint]
Link with debug interface.
Specify interface to override default.
--silent Silent operation
--stack_usage_control file
Read stack usage control file
--strip Do not include debug information
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--threaded_lib Configure runtime library for use with threads
--timezone_lib Enable timezone and daylight savings support
--treat_rvct_modules_as_softfp
link softfp versions of math function for modules
compiled with RVCT even though they are built with
vfp calling-convention
--use_full_std_template_names
Don't use short names for standard C++ templates
--use_optimized_variants no|auto|small|fast
Use optimized variants of DLIB library functions
no Do not use redirects to use optimized variants
auto Use redirects based on attributes in object files
(default)
small Always use a small variant if available
fast Always use a fast variant if available
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--version Output version information and exit
--vfe=[forced] Perform Virtual Function Elimination
forced Force the use of VFE for all modules
with VFE information.
--warnings_affect_exit_code
Warnings affect exit code
--warnings_are_errors
All warnings are errors
--whole_archive archive
Link all modules in archive
IAR ILINK鏈接器(ilinkarm.exe)用於構建最終應用程序。通常,鏈接器需要以下信息作爲輸入:
- 幾個目標文件,可能還有某些庫
- 程序開始標籤(默認設置)
- 鏈接器配置文件,用於描述目標系統內存中代碼和數據的放置
下圖顯示了鏈接過程:
IAR ILINK鏈接器生成ELF格式的絕對目標文件,其中包含可執行鏡像。 鏈接後,可以使用生成的絕對可執行映像
- 加載到IAR C-SPY調試器或任何其他兼容的外部調試器讀取ELF和DWARF。
- 使用flash / PROM編程器對flash / PROM進行編程。 在此之前可能必須使用
ielftool
將鏡像中的實際字節轉換爲標準的Motorola 32-bit S-record 格式或Intel Hex-32格式。
iarchive.exe
檔案管理工具,類似於 ARM 的 armar
和 GCC 的 ar
。用於創建和操作幾個ELF目標文件的庫(存檔)。庫文件包含多個可重定位的ELF對象模塊,每個模塊都可以由鏈接器獨立使用。 與直接指定給鏈接器的對象模塊相比,只有在需要時才包含庫中的每個模塊。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iarchive
IAR Archive Tool V10.4.14.1149
Copyright 2008-2019 IAR Systems AB.
Usage: iarchive [command] archive obj1 ... objN
iarchive [command] obj1 ... objN -o archive
iarchive [command] archive
Available command line options:
--create Create new archive
--delete
-d Delete module(s) from archive
--extract
-x Extract module(s) from archive
-f file Read command line options from file
--f file Read command line options from file and report dependency
--no_bom Don't use a Byte Order Mark in Unicode output
--output archive
-o archive Name of archive file
--replace
-r Replace or add module(s) to archive
--symbols List symbol table of archive
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--toc
-t List archive table of content
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--verbose
-V verbose operation
--version Output version information and exit
--vtoc List archive table of content (verbose)
使用示例:
- 使用源對象文件
module1.o
、module.2.o
和module3.o
創建了一個名爲mylibrary.a
的庫文件:iarchive mylibrary.a module1.o module2.o module3.o
- 列出 mylibrary.a中的內容:
iarchive --toc mylibrary.a
- This example replaces module3.o in the library with the content in the module3.o file and appends module4.o to mylibrary.a:
iarchive --replace mylibrary.a module3.o module4.o
ielftool.exe
ARM ELF文件工具,類似於 ARM 的 fromelf
和 GCC 的 elfedit
。對ELF可執行映像執行各種轉換(例如,填充,校驗和,格式轉換等)。安裝目錄.\arm \ src\elfutils
下提供了 ielftool 源代碼(Microsoft VisualStudio項目)。 如果對如何生成校驗和或格式轉換要求有特定要求,則可以相應地修改源代碼。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iarchive
IAR Archive Tool V10.4.14.1149
Copyright 2008-2019 IAR Systems AB.
Usage: iarchive [command] archive obj1 ... objN
iarchive [command] obj1 ... objN -o archive
iarchive [command] archive
Available command line options:
--create Create new archive
--delete
-d Delete module(s) from archive
--extract
-x Extract module(s) from archive
-f file Read command line options from file
--f file Read command line options from file and report dependency
--no_bom Don't use a Byte Order Mark in Unicode output
--output archive
-o archive Name of archive file
--replace
-r Replace or add module(s) to archive
--symbols List symbol table of archive
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--toc
-t List archive table of content
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--verbose
-V verbose operation
--version Output version information and exit
--vtoc List archive table of content (verbose)
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>ielftool
IAR ELF Tool V10.4.14.1149 [BUILT at IAR]
Copyright 2007-2019 IAR Systems AB.
Usage: ielftool input_file output_file
Available command line options:
--bin Save as raw binary
--checksum sym:size,algo[:[1|2][a|m|z][r][R][o][x][i|p][W|L]][,start]
;range[;range...]
Generate checksum
sym Checksum symbol
size Length of the symbol in bytes
algo Algorithm: sum, sum8wide, sum32, crc16, crc32
crc64iso, crc64ecma or crc=poly
1|2 Complement: 1 or 2
a|m|z Reverse the bit order for:
input bytes only: a
input bytes and final checksum: m
final checksum only: z
o Output the Rocksoft model specification
r Reverse the byte order within each word
R Traverse the range(s) in reverse order
x Toggle the endianess of the checksum
i|p Use initial value normally: i
Prefix input data with the start value: p
W|L Use a checksum unit length of 2 bytes: W
Use a checksum unit length of 4 bytes: L
start Initial checksum value (defaults to 0)
range Do checksum of bytes in range
--fill [v;]pattern;range[;range...]
Specify fill
v Virtual fill, do not generate actual filler bytes.
This can be used for checksums and parities.
pattern Sequence of filler bytes
range Fill range
--front_headers Move program and section headers to the front of the ELF file.
--ihex Save as 32-bit linear Intel Extended hex
--offset [-]offset
Add (subtract if - is used) offset to all address records.
This only works for the output formats: Motorola S-records,
Intel Hex, Simple-Code and TI-TXT
--parity sym:size,algo:flashbase[:[r][[B|W|L]];range[;range...]
Generate parity bits
sym Parity symbol
size Length of the symbol in bytes
algo Parity algorithm: odd, even
flashbase Ignore bytes before this address
r Traverse the range(s) in reverse order
B Use a parity unit length of 1 byte
W Use a parity unit length of 2 bytes
L Use a parity unit length of 4 bytes
range Perform parity on bytes in this range
--self_reloc relocator[,jtc]
Create self-relocating image with relocator
jtc Number of jump table entries
--silent Silent operation
--simple Save as Simple-code
--simple-ne Save as Simple-code without entry record
--srec Save as Motorola S-records
--srec-len length
Restrict the length of S-records
--srec-s3only Restrict the type of S-records to S3 (and S7)
--strip Remove all section headers and non-program sections
--titxt Save as Texas Instruments TI-TXT
--verbose Print all performed operations
--version Output tool version
使用示例:
- This example fills a memory range with 0xFF and then calculates a checksum on the same range:
ielftool my_input.out my_output.out --fill 0xFF;0–0xFF --checksum __checksum:4,crc32;0–0xFF
ielfdumparm.exe
針對 ARM ELF 格式的文件的 Dumper工具。類似於 GCC 的 objdump
,用於創建ELF可重定位或可執行映像內容的文本表示。主要用於以下三個方面:
- To produce a listing of the general properties of the input file and the ELF segments and ELF sections it contains. This is the default behavior when no command line options are used.生成輸入文件的常規屬性列表以及它包含的ELF段和ELF節。 當沒有使用命令行選項時,這是默認行爲。
- To also include a textual representation of the contents of each ELF section in the input file. To specify this behavior, use the command line option --all .還包括輸入文件中每個ELF部分內容的文本表示。 要指定此行爲,請使用命令行選項–all。
- To produce a textual representation of selected ELF sections from the input file. To specify this behavior, use the command line option --section 從輸入文件生成所選ELF節的文本表示。 要指定此行爲,請使用命令行選項–section
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>ielfdumparm
IAR ELF Dumper V8.32.3.193 for ARM
Copyright 2007-2019 IAR Systems AB.
Usage: IElfDump input_file [output_file]
Available command line options:
-a All sections, except strtab sections
--aarch64 Disassemble in Aarch64 mode if mode cannot be deduced by the image.
--all Dump all sections
--arm Disassemble in Arm mode if mode cannot be deduced by the image.
--code Dump only code sections
--disasm_data Use disassembly format for data sections
-f file Read command line options from file
--f file Read command line options from file and report dependency
--no_bom Don't use a Byte Order Mark in Unicode output
--no_header Do not produce a list header
--no_rel_sections
Do not output associated .rel sections
--no_strtab Do not include strtab sections
--no_utf8_in Non-IAR input files are by default assumed to use UTF-8
encoding unless this option is used.
--output file
-o file Name of text file to create
--range A-B Disassemble only addresses in the specified range
(from A to B).
--raw Use raw text format
--section #|name[,...]
-s #|name[,...] Dump only section(s) with given numbers/names
--source Include source in disassembled code in executables
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--thumb Disassemble in thumb mode if mode cannot be deduced by the image.
--use_full_std_template_names
Don't use short names for standard C++ templates
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--version Output version information and exit
iobjmanip.exe
針對 ARM ELF 格式的 Object 文件的操作工具。用於執行ELF目標文件的低級操作。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iobjmanip
IAR Object File Manipulator V10.4.14.1149
Copyright 2009-2019 IAR Systems AB.
Usage: iobjmanip <op1>[,...<opN>] <src> <dest>
Available command line options:
-f file Read command line options from file
--f file Read command line options from file and report dependency
--no_bom Don't use a Byte Order Mark in Unicode output
--remove_file_path
remove path information from file symbol
--remove_section #|name
remove matching section(s)
--rename_section (#|name)=name
rename matching section(s)
--rename_symbol name=name
rename matching symbol
--strip strip debug information
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--version Output version information and exit
使用示例:
- This example renames the section .example in input.o to .example2 and stores the result in output.o:
iobjmanip --rename_section .example=.example2 input.o output.o
isymexport.exe
絕對符號導出器。 從ROM映像文件中導出絕對符號,以便在鏈接附加應用程序時使用它們。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>isymexport
IAR Absolute Symbol Exporter V10.4.14.1149
Copyright 2008-2019 IAR Systems AB.
Usage: ISymExport input_file output_file
Available command line options:
--edit steering_file
Show/hide/rename symbols
--export_locals[=symbol_prefix]
Export local variable and function symbols
-f file Read command line options from file
--f file Read command line options from file and report dependency
--generate_vfe_header
Generate vfe header section
--no_bom Don't use a Byte Order Mark in Unicode output
--ram_reserve_ranges[=symbol_prefix]
Generate symbols to reserve all occupied RAM ranges
--reserve_ranges[=symbol_prefix]
Generate symbols to reserve all occupied ranges
--show_entry_as[=name]
Export the entry point of the program as name
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--version Output version information and exit
iexe2obj.exe
IAR ELF可重定位對象創建器。從可執行的ELF目標文件創建可重定位的ELF目標文件。
E:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin>iexe2obj
IAR ELF Exe to Object Tool V10.4.14.1149
Copyright 2008-2019 IAR Systems AB.
Usage: IExe2Obj input_file output_file
Available command line options:
-f file Read command line options from file
--f file Read command line options from file and report dependency
--hide_symbols Hide all symbols in the image
--keep_mode_symbols
Keep mode symbols in the image
--no_bom Don't use a Byte Order Mark in Unicode output
--prefix prefix Set section/symbol name prefix
--text_out encoding
Encoding to use for text output files
utf8 UTF-8
utf16le Little-endian UTF-16
utf16be Big-endian UTF-16
locale Locale specific encoding
--utf8_text_in Non-source text input files with no BOM use UTF-8 encoding
--version Output version information and exit
--wrap function Create wrapper for function
GCC for ARM
GCC 全稱爲 GNU Compiler Collection。 GCC 是幾種主要編程語言的編譯器的集成分發。 這些語言目前包括 C,C ++,Objective-C,Objective-C ++,Fortran,Ada,Go 和 BRIG(HSAIL)。
GCC 原名爲 GNU C 語言編譯器(GNU C Compiler),因爲它原本只能處理 C語言。GCC 很快地擴展,變得可處理 C++。後來又擴展能夠支持更多編程語言,如 Fortran、Pascal、Objective-C、Java、Ada、Go 以及各類處理器架構上的彙編語言等,所以改名GNU編譯器套件(GNU Compiler Collection)。 更名之後,原來的針對於 C 語言的編譯器名字還叫 gcc,針對 C++ 的編譯器叫做 g++ 。
GCC for ARM 則是基於 GCC 開發的,用來編譯生成 ARM 內核可執行文件的編譯套件,俗稱 ARM 交叉編譯套件。 相比於以上兩個巨貴的編譯器,GCC for ARM 因爲是基於開源的 GCC 的,因此是免費的。目前主要由三大主流工具商提供,第一是 ARM,第二是 Codesourcery,第三是 Linora。目前我們用的針對 ARM 芯片的集成開發環境(IDE),除了 IAR 和 ARM 自己的 Keil、DS 等都是使用 GCC for ARM 的編譯器!
首先,看看 ARM 交叉編譯工具鏈的命名規則:arch [-vendor] [-os] [-(gnu)eabi] [-gcc]
- arch: 體系架構,如 ARM,MIPS
- vendor: 工具鏈提供商,沒有 vendor 時,用 none 代替;
- os: 目標操作系統,沒有 os 支持時,也用 none 代替
- eabi: 嵌入式應用二進制接口(Embedded Application Binary Interface)
如果同時沒有 vendor 和 os 支持,則只用一個 none 代替。例如 arm-none-eabi 中的 none 表示既沒有 vendor 也沒有 os 支持。 前面說過,GCC for ARM 則是基於 GCC 開發的。因此,其和 GCC 一樣是一套命令行工具的集合,理論上可以將它集成到其他任何集成開發環境中,從而不直接使用命令行。GCC for ARM 中的各命令行工具與 GCC 中的各命令行工具都是對應的,功能基本一致,僅僅是名字有些改變!
Codesourcery Toolchain
Codesourcery推出的產品叫 Sourcery G++ Lite Edition,其中基於 command-line 的編譯器是免費的,在官網上可以下載,而其中包含的 IDE 和 debug 工具是收費的。Codesourcery 公司(目前已經被Mentor收購)基於GCC推出的ARM交叉編譯工具。可用於交叉編譯 ARM MCU 芯片,如 ARM7、ARM9、Cortex-M/R 芯片程序。
目前 CodeSourcery 已經由明導國際(Mentor Graphics)收購,所以原本的網站風格已經全部變爲 Mentor 樣式,這貨被收之後,不知道怎麼下載其編譯工具鏈。。。
- arm-none-linux-gnueabi-gcc: 用於交叉編譯ARM(32位)系統中所有環節的代碼,包括裸機程序、u-boot、Linux kernel、filesystem和App應用程序。
- arm-none-elf-gcc: 用於交叉編譯ARM MCU(32位)芯片,如ARM7、ARM9、Cortex-M/R芯片程序。
Linaro Toolchain
Linaro 是在 2010 年臺北國際計算機展( COMPUTEX )期間,ARM、Freescale、Samsung ,ST-Ericsson、德州儀器(TI)與IBM等6家大廠,宣佈合資成立的非贏利 Linux 基礎架構軟件研發商。其基於 GCC 推出的 ARM 交叉編譯工具如下圖所示:
下載地址爲:https://www.linaro.org/downloads/ 。從上圖不難看出,Linaro 提供的交叉編譯環境,僅針對於Cortex-A 內核,其他 ARM 內核則需要去 ARM 官網下載!
- aarch64-linux-gnu: 針對於目標平臺是 Linux 系統,用於交叉編譯 ARMv8 64位目標中的裸機程序、u-boot、Linux kernel、filesystem 和 App 應用程序。
- arm-linux-gnueabihf: 針對於目標平臺是 Linux 系統,用於交叉編譯ARM(32位)系統中所有環節的代碼,包括裸機程序、u-boot、Linux kernel、filesystem和 App 應用程序。
- arm-eabi-gcc: 用於編譯 ARM 架構的裸機系統,包括 ARM Linux 的 boot、kernel,不適用編譯 Linux 應用 Application
- aarch64-elf: 用於編譯 ARM v8 64位 架構的裸機系統,包括 ARM Linux 的 boot、kernel,不適用編譯 Linux 應用 Application
正如官網的說明,官方發佈的編譯好二進制可執行編譯器文件,僅在 Linux 系統( Ubuntu LTS)進行了測試。 目前,官方沒有提供其他平臺的可執行程序!
ARM Toolchain
ARM 除了有自己的專用編譯器之外,還維護了一套基於 GCC 的交叉編譯工具鏈。估計是爲了能更有效的佔有市場吧!絕大多數第三方的 IDE 都是使用這一套交叉編譯工具鏈。
arm-none-eabi
用於編譯 ARM 架構的裸機系統(包括 ARM Linux 的 boot、kernel,不適用編譯 Linux 應用 Application),所以不支持那些跟操作系統關係密切的函數,比如fork,它使用的是 newlib 這個專用於嵌入式系統的C庫。
作爲維持和增強 GCC 編譯器支持 ARM 架構的持續承諾的一部分,ARM 正在維護一個 GNU 工具鏈,其 GCC 源分支針對嵌入式 ARM 處理器,即 Cortex-R / Cortex-M處理器系列,覆蓋 Cortex-M0 ,Cortex-M3,Cortex-M4,Cortex-M0 +,Cortex-M7,Armv8-M基線和主線,Cortex-R4,Cortex-R5,Cortex-R7和Cortex-R8。
作爲其中的一部分,ARM 定期發佈來自 ARM 嵌入式分支的預構建和測試二進制文件。 這些改進可以免費集成到第三方工具鏈中,也可以由最終用戶直接下載。整套工具鏈包含以下組件:
- gcc : gcc-8-branch revision 267074
svn://gcc.gnu.org/svn/gcc/branches/gcc-8-branch - binutils : 2.31 with mainline backports
git://sourceware.org/git/binutils-gdb.git commit fe554d200d1befdc3bddc9e14f8593ea3446c351 - newlib and newlib-nano :
git://sourceware.org/git/newlib-cygwin.git commit df6915f029ac9acd2b479ea898388cbd7dda4974 - gdb : 8.2 without target sim support
git://sourceware.org/git/binutils-gdb.git commit fe554d200d1befdc3bddc9e14f8593ea3446c351
目前由 ARM 來維護開發。使用 launchpad 來維護該項目源碼。但是根據之前的公告,launchpad 上不發佈編譯好的程序和源碼包("As previously announced all new binary and source packages will not be released on Launchpad henceforth, they can be found on:
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm."),只能從 ARM 官網:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads 進行下載。下面是,版本發佈時間線:
這是目前,我們編寫 ARM 裸機程序時,使用最多的交採編譯工具鏈! 安裝/解壓 之後,目錄如下圖所示:
編譯器工具中的各工具,與標準的GCC沒有太多區別,主要就是針對的平臺變了。各工具的功能是一樣的!比如:arm-none-eabi-gcc.exe
是C 語言編譯器、arm-none-eabi-g++.exe
是 C++ 編譯器、arm-none-eabi-ld.exe
是連接器、arm-none-eabi-gdb.exe
是調試器等等。
Cortex-A 專用
以上交叉編譯工具鏈只支持 ARM Cortex-M/R等系列的核,ARM 官網還提供了針對於 ARM Cortex-A 系列內核的交叉編譯工具鏈,可以從以下地址下載
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads。 具體如下所示:
需要注意的是,上圖中紅框全稱的就是編譯工具鏈的名字。以 gcc-arm-8.3-2019.03-i686-mingw32-arm-eabi 爲例,解壓後如下圖所示:
各命令行工具與標準 GCC 也沒啥區別!
再一個需要注意的是,上圖中的 i686-mingw32 host 指定是運行平臺爲 Windows 7 32/64 bits or later;x86_64 host 指定是運行平臺爲 Ubuntu 14.04 LTS x86_64 or later or RHEL 6 x86_64。也就是說,僅支持 Windows 和 Linux 平臺! 整套工具包含以下組件:
再再一個需要注意的是,編譯器的目標平臺。
- AArch32 bare-metal target:32位純裸機平臺
- AArch64 ELF bare-metal target:64位純裸機平臺
- AArch64 ELF bare-metal, big-endian target:64位純裸機平臺(大端模式)
- AArch64 GNU/Linux target:64位 Linux 平臺
- AArch64 GNU/Linux big-endian target:64位 Linux 平臺(大端模式)
- AArch32 target with soft float:32位帶軟件模式浮點運算
- AArch32 target with hard float:32位帶硬件模式浮點運算