目录
1,标准的 armclang 编译选项
1.1 --target选项:指定执行状态
aarch64-arm-none-eabi
arm-arm-none-eabi
1.2 -march选项:指定ARM 架构/ -mcpu 选项:指定处理器
2,使用示例
3,armclang common options
4, armlink common options
5, armar common options
6, fromelf common options
7,armasm common options
在上一篇文章中,介绍了ARM嵌入式编译器6工具链:ARM 编译器 Arm Compiler for Embedded 6 相关工具链简介_arm6 编译器_SOC罗三炮的博客-CSDN博客
接下来,笔者将对该编译器工具链的简单使用,一些常用的命令行选项进行介绍。
ARM 编译器6支持许多命令行编译选项,用户可以根据自己代码的使用场景,使用对象来选择使用,从而生成不同属性的应用程序。
当使用armclang时,用户必须指定一个target,如 A64、A32或者T32等,然后执行一个ARM 架构:ARMv7、ARMv8或者ARMv9等,以及指定目标处理器,比如Cortex-A53、Cortex-M4或者Cortex-M33等。
用户在使用armclang
时,必须加上 --target 选项,来指定当前的代码是运行在AArch64状态还是AArch32状态。语法为:
--target=
其中
为AArch64状态生成 A64指令,如果没有特别指定ARM架构或者目标处理器,其默认的ARM架构为ARMv8-A,即-march=armv8-a。
为AArch32状态生成 A32或者T32指令,为了区别使用A32还是T32,需外一个额外的选项: -marm 或者-mthumb 来区分。此外,没有默认的ARM架构,必须与-march(指定架构)或-mcpu(指定处理器)一起使用。
需要注意的是,--target选项是大小写敏感的,并且只有armclang可以使用,armasm
或者armlink使用--cpu
或者--fpu
来指定目标架构和处理器。另外Scalable Vector Extension (SVE)是 AArch64状态下的一种扩展功能,所以只能使用 aarch64-arm-none-eabi。
用户需要-march 选项来指定代码是运行在何种AMR架构上。
应该避免同时指定架构(-march)和处理器(-mcpu),因为同时指定两者有可能导致冲突。编译器将会从处理器的型号反推出正确的体系结构。
当使用--target=aarch64-arm-none-eabi编译时,默认值是-march=armv8-a。当使用--target=arm-arm-none-eabi编译时,默认值是不支持的。所以必须至少使用-march或-mcpu选项中的一个。否则编译器将会报出如下警告:
warning: 'armv4t' is unsupported in this version of the product
-march选项的语法:
-march=
-march=[+[no]+...] (to enable or disable optional extensions)
如果要查看所选target的所有受支持架构的列表,使用-march=list。 其中
Architecture
|
Valid targets | Description |
---|---|---|
armv9-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv9-A application architecture profile. |
armv9.1-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv9.1-A application architecture profile. |
armv9.2-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv9.2-A application architecture profile. |
armv9.3-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv9.3-A application architecture profile. |
armv9.4-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv9.4-A application architecture profile. |
armv8-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8-A application architecture profile. |
armv8.1-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.1-A application architecture profile. |
armv8.2-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.2-A application architecture profile. |
armv8.3-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.3-A application architecture profile. |
armv8.4-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.4-A application architecture profile. |
armv8.5-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.5-A application architecture profile. |
armv8.6-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.6-A application architecture profile. |
armv8.7-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.7-A application architecture profile. |
armv8.8-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.8-A application architecture profile. |
armv8.9-a |
--target=aarch64-arm-none-eabi and --target=arm-arm-none-eabi |
Armv8.9-A application architecture profile. |
armv8-r |
--target=aarch64-arm-none-eabi |
Armv8-R AArch64 real-time architecture profile. Armv8-R AArch64 state with hardware floating-point. Armv8-R AArch64 implementations without hardware floating-point are not supported. |
armv8-r |
--target=arm-arm-none-eabi |
Armv8-R AArch32 real-time architecture profile. |
armv8-m.base |
--target=arm-arm-none-eabi |
Armv8-M microcontroller architecture profile without the Main Extension. Derived from the Armv6-M architecture. |
armv8-m.main |
--target=arm-arm-none-eabi |
Armv8-M microcontroller architecture profile with the Main Extension. Derived from the Armv7-M architecture. |
armv8.1-m.main |
--target=arm-arm-none-eabi |
Armv8.1 microcontroller architecture profile with the Main Extension. |
armv7-a |
--target=arm-arm-none-eabi |
Armv7-A application architecture profile. |
armv7-r |
--target=arm-arm-none-eabi |
Armv7-R real-time architecture profile. |
armv7-m |
--target=arm-arm-none-eabi |
Armv7-M microcontroller architecture profile. |
armv7e-m |
--target=arm-arm-none-eabi |
Armv7-M microcontroller architecture profile with DSP extension. |
armv6-m |
--target=arm-arm-none-eabi |
Armv6-M microcontroller architecture profile. |
使用+
用户需要避免同时指定架构(-march)和处理器(-mcpu),因为同时指定两者有可能导致冲突。编译器优先从处理器推断正确的体系结构。
Armv8-A +AArch64 :
armclang --target=aarch64-arm-none-eabi -march=armv8-a helloworld.c
Armv8-R + AArch32 :
armclang --target=arm-arm-none-eabi -march=armv8-r helloworld.c
Armv8-M architecture mainline profile:
armclang --target=arm-arm-none-eabi -march=armv8-m.main helloworld.c
Cortex®-A53 +AArch64 :
armclang --target=aarch64-arm-none-eabi -mcpu=cortex-a53 helloworld.c
Cortex-A53 + AArch32 :
armclang --target=arm-arm-none-eabi -mcpu=cortex-a53 helloworld.c
Cortex-M4 :
armclang --target=arm-arm-none-eabi -mcpu=cortex-m4 helloworld.c
Cortex-M33 processor, with DSP disabled:
armclang --target=arm-arm-none-eabi -mcpu=cortex-m33+nodsp helloworld.c
AArch32 + Arm® Neoverse® N1 :
armclang --target=arm-arm-none-eabi -mcpu=neoverse-n1 helloworld.c
AArch64 state + Arm Neoverse E1 :
armclang --target=aarch64-arm-none-eabi -mcpu=neoverse-e1 helloworld.c
Option | Description |
---|---|
-c | Performs the compilation step, but not the link step. |
-x | Specifies the language of the subsequent source files, -xc inputfile.s or -xc++ inputfile.s for example. |
-std | Specifies the language standard to compile for, -std=c90 for example. |
--target=arch-vendor-os-abi | Generates code for the selected Execution state (AArch32 or AArch64), for example --target=aarch64-arm-none-eabi or --target=arm-arm-none-eabi . |
-march=name | Generates code for the specified architecture, for example -march=armv8-a or -march=armv7-a . |
-march=list | Displays a list of all the supported architectures for the selected execution state. |
-mcpu=name | Generates code for the specified processor, for example -mcpu=cortex-a53 , -mcpu=cortex-a57 , or -mcpu=cortex-a15 . |
-mcpu=list | Displays a list of all the supported processors for the selected execution state. |
-marm | Requests that the compiler targets the A32 instruction set, which consists of 32-bit wide instructions only. For example, The
|
-mthumb | Requests that the compiler targets the T32 instruction set, which consists of both 16-bit wide and 32-bit wide instructions. For example, The |
-mfloat-abi | Specifies whether to use hardware instructions or software library functions for floating-point operations. |
-mfpu | Specifies the target FPU architecture. |
-g (armclang) | Generates DWARF debug tables compatible with the DWARF 4 standard. |
-e | Executes only the preprocessor step. |
-I | Adds the specified directories to the list of places that are searched to find included files. |
-o (armclang) | Specifies the name of the output file. |
-Onum | Specifies the level of performance optimization to use when compiling source files. |
-Os | Balances code size against code speed. |
-Oz | Optimizes for code size. |
-S | Outputs the disassembly of the machine code that the compiler generates. |
-### | Displays diagnostic output showing the options that would be used to invoke the compiler and linker. The compilation and link steps are not performed. |
Option | Description |
---|---|
--scatter=filename | Creates an image memory map using the scatter-loading description that the specified file contains. |
--entry | Specifies the unique initial entry point of the image. |
--info (armlink) | Displays information about linker operation. For example,
|
--list=filename | Redirects diagnostics output from options including --info and --map to the specified file. |
--map | Displays a memory map containing the address and the size of each load region, execution region, and input section in the image, including linker-generated input sections. |
--symbols | Lists each local and global symbol that is used in the link step, and their values. |
-o filename, --output=filename | Specifies the name of the output file. |
--keep=section_id | Specifies input sections that unused section elimination must not remove. |
--load_addr_map_info | Includes the load addresses for execution regions and the input sections within them in the map file. |
Option | Description |
---|---|
--debug_symbols | Includes debug symbols in the library. |
-a pos_name | Places new files in the library after the file . |
-b pos_name | Places new files in the library before the file . |
-a file_list | Deletes the specified files from the library. |
--sizes | Lists the Code , RO Data , RW Data , ZI Data , and Debug sizes of each member in the library. |
-t | Prints a table of contents for the library. |
Option | Description |
---|---|
--elf | Selects ELF output mode. |
--text |
Displays image information in text format. The optional |
--info (fromelf) | Displays information about specific topics, for example --info=totals lists the Code , RO Data , RW Data , ZI Data , and Debug sizes for each input object and library member in the image. |
Option | Description |
---|---|
--cpu=name | Sets the target processor. |
-g (armasm) | Generates DWARF debug tables compatible with the DWARF 3 standard. |
--fpu=name | Selects the target floating-point unit (FPU) architecture. |
-o (armasm) | Specifies the name of the output file. |