嵌入式技术
在讲解各编译器之前,必须先了解一下以下这些文件。这些文件在编译器目录下或者编译生成目标平台的可执行程序时经常见到。此外,还需要注意区分 Windows 平台 和 Linux 平台的文件。
.o 文件: 指的是 object 文件,俗称目标文件。在 Linux 下扩展名缩写为 .o,在 windows 下通常为 .obj 文件。
.a 文件: 指的是 archive 文件,俗称静态库文件。在 Linux 下扩展名缩写为 .a,在 windows 下通常为 .lib 文件。
.so 文件: 指的是 shared object 文件,用于动态连接的。在 Linux 下扩展名缩写为 .so,在 windows 下通常为 .dll 文件。
.o 文件是链接文件,.a 是静态库文件,需要 .o 文件生成,作为一个库为外部程序提供函数接口。详细的可以看一下博文 镜像文件(Image)/可执行文件/ELF文件/对象文件 详解。
??在交叉编译工具链目录中,有大量的 .o 和 .a 文件。这些文件在我们编译目标平台时会被用到!为什么在 Windows 下面的编译工具链中会有这么多的 .o 和 .a 文件呢?这是因为我们使用的这个编译工具链是在 Linux 系统中编译生成的! 。看下图:
如果有亲自编译过交叉编译工具链,那么就一定会对 build、host 和 target 这几个参数非常熟悉:
–build=编译该软件(就是指的交叉编译工具链本身)所使用的平台
–host=该软件(就是指的交叉编译工具链本身)将运行的平台
–target=该软件(就是指的交叉编译工具链本身)所要处理的目标平台。即交叉编译工具链编译出来的程序运行的平台。
比较
目前,针对于 ARM 平台的主流编译器主要有以下三者:
比较 | ARMCC | IAR | GCC for ARM | LLVM(clang) |
---|---|---|---|---|
命令行工具 | 随IDE发布,也独立提供 | 仅随其IDE发布,不独立提供 | 独立提供 | 只有命令行工具 |
开发商 | ARM | IAR | ARM、Linaro、Mentor | LLVM |
支持的平台 | Windows、Linux | Windows | Windows、Linux、Mac(部分) | Windows、Linux、Mac |
配套 IDE | Keil MDK、ARM Development Studio 5、ADS | IAR EMBEDDED WORKBENCH FOR ARM | 除以上两者外的其他支持ARM的IDE,例如:eclipse、Visual Studio | 除以上两者外的其他支持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 | https://llvm.org/ |
ARM
ARM 官网上除了提供了配套 IDE(参考博文《ARM 之 各集成开发环境(IDE)说明(Keil、RVDS、ADS、DS-5、MDK)》) 以外,每次都会提供编译器的独立下载。用户可以单独安装编译器,编译器采用命令行形式使用。
也就是说,ARM 的 IDE 和编译器是相互独立的,使用者可以为同一个 IDE 配置不同版本的编译器!目前,ARM 官方提供两个版本的编译器,如下图所示:
其中,Arm Compiler 6 被 ARM 称为是 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
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:ARMARM_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 优化最大优化级别的运行时间 --cpuSelect CPU to generate code for 选择CPU --cpu list Output a list of all the selectable CPUs 输出所有被选中的CPU列表 -o 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 Define on entry to the compiler 定义 符号并且传入编译过程 -g Generate tables for high-level debugging 为高级别调试创建表 -I Include on the #include search path 在编译的时候包含 作为头文件搜索目录 1234567891011121314151617181920212223242526272829
其默认的头文件搜索路径如下图所示:
armasm.exe
?? ARM 和 Thumb 汇编器。用来汇编 ARM 和 Thumb 汇编语言源文件。
D:ARMARM_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} 指令 --maxcacheMaximum 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 / 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 Read further arguments from 从 中读取更多参数 --cpu Set the target ARM core type 设置目标ARM核心类型 --cpu list Output a list of all the selectable CPUs 输出所有可选CPU的列表 --fpu 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 指令 12345678910111213141516171819202122232425262728293031323334353637383940
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:ARMARM_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文件里面。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
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:ARMARM_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, replace existing members of the same name. 在 中插入文件, 替换掉已经存在的同名成员。 -d Delete the members in . 从 中删除成员。 -x Extract members in placing in files of the same name. 从 中提取同名的成员。 -m Move files in . 在 中移动文件。 -p Print files to stdout. 打印文件到标准输出设备。 -a pos Insert/move files after file named . 插入/删除 后面的文件。 -b pos Insert/move files before file named . 插入/删除 前面的文件。 -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:ARMARM_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安装目录armdoc
。具体如下:
《 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 SystemsEmbedded Workbench 8.2armin>iasmarm IAR Assembler V8.32.3.193/W32 for ARM Copyright 1999-2019 IAR Systems AB. Usage: iasmarm {} { } 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 errors -f file Extend command line with <.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: <.lst> -Lpath Generate a list on:
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 特定功能的扩展。??默认使用的头文件目录.arminc
E:Program Files (x86)IAR SystemsEmbedded Workbench 8.2armin>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 作为对象格式文件。在.armconfig目录下,包含了针对各平台的连接器使用的配置文件。
E:Program Files (x86)IAR SystemsEmbedded Workbench 8.2armin>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 SystemsEmbedded Workbench 8.2armin>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) 123456789101112131415161718192021222324252627282930313233343536
使用示例:
使用源对象文件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 srcelfutils下提供了 ielftool 源代码(Microsoft VisualStudio项目)。如果对如何生成校验和或格式转换要求有特定要求,则可以相应地修改源代码。
E:Program Files (x86)IAR SystemsEmbedded Workbench 8.2armin>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 SystemsEmbedded Workbench 8.2armin>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 SystemsEmbedded Workbench 8.2armin>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 SystemsEmbedded Workbench 8.2armin>iobjmanip IAR Object File Manipulator V10.4.14.1149 Copyright 2009-2019 IAR Systems AB. Usage: iobjmanip[,... ] 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 1234567891011121314151617181920212223242526272829
使用示例:
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 SystemsEmbedded Workbench 8.2armin>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 SystemsEmbedded Workbench 8.2armin>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 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 平台的编译套件) 是基于 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 中的各命令行工具都是对应的,功能基本一致,仅仅是名字有些改变!
基于 GCC 的 ARM 编译工具链提供商有 ARM、Codesourcery、Linaro 这三家,但其中使用最多还是 ARM 提供的 GCC 编译器。下面我们分别简单来介绍一下这三家的编译工具链。
Arm GNU Toolchain
ARM 除了有自己的专用编译器之外,还维护了一套基于 GCC 的交叉编译工具链,被称为 Arm GNU Toolchain。估计是为了能更有效的占有市场吧!绝大多数第三方的 IDE 都是使用这一套交叉编译工具链。
注意,在 2022 年之前,Arm GNU Toolchain 被分为了 A-profile(GNU Toolchain for A-profile processors) 和 R & M profiles(GNU Arm Embedded Toolchain)两大类,但是从 2022 年开始统一为了一个,之前的已经停止开发。2022 年第一版叫做 Arm GNU Toolchain Version 11.2-2022.02。
在 2022 年以前 R & M profiles 编译工具链的名字只有 arm-none-eabi,只能编译裸机平台,Cortex-A 则有裸机和 Linux 版之分的多种编译工具链;在 2022 年开始,则根据架构及是否支持 Linux 系统进行了大一统,我们可以根据需要选择合适的版本。
下面这两个章节还是 2022 年以前的 Arm GNU Toolchain 的介绍。2022 年以前的 Arm GNU Toolchain 官网还提供下载,只是不再进行更新。
arm-none-eabi
用于编译 ARM 架构的裸机系统(包括 ARM Linux 的 boot、kernel,不适用编译 Linux 应用 Application),所以不支持那些跟操作系统关系密切的函数,比如 fork,它使用的是 newlib 这个专用于嵌入式系统的 C 库。这是目前我们编写 ARM 裸机程序时,使用最多的交采编译工具链! 安装/解压 之后,目录如下图所示:
??编译器工具中的各工具,与标准的 GCC 没有太多区别,主要就是针对的平台变了。各工具的功能是一样的!比如:arm-none-eabi-gcc.exe 是C 语言编译器、arm-none-eabi-g++.exe 是 C++ 编译器、arm-none-eabi-ld.exe 是连接器、arm-none-eabi-gdb.exe 是调试器等等。
?? 在很久以前,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/downloads 进行下载,launchpad 仅用于 BUG 提交等。
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 也没啥区别!再一个需要注意的是,编译器的目标平台。
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 位带硬件模式浮点运算
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)进行了测试。 目前,官方没有提供其他平台的可执行程序!
参考
https://www.veryarm.com/
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchai
编辑:黄飞
全部0条评论
快来发表一下你的评论吧 !