Arm Compiler for Embedded 6 编译器工具链常用选项
目錄
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支持許多命令行編譯選項,用戶可以根據自己代碼的使用場景,使用對象來選擇使用,從而生成不同屬性的應用程序。
1,標準的 armclang 編譯選項
當使用armclang時,用戶必須指定一個target,如 A64、A32或者T32等,然后執行一個ARM 架構:ARMv7、ARMv8或者ARMv9等,以及指定目標處理器,比如Cortex-A53、Cortex-M4或者Cortex-M33等。
1.1 --target選項:指定執行狀態
用戶在使用armclang?時,必須加上?--target?選項,來指定當前的代碼是運行在AArch64狀態還是AArch32狀態。語法為:
--target=<triple>?其中<triple>的含義為<architecture>-<vendor>-<OS>-<abi>,可以為以下兩個選項:
aarch64-arm-none-eabi
為AArch64狀態生成 A64指令,如果沒有特別指定ARM架構或者目標處理器,其默認的ARM架構為ARMv8-A,即-march=armv8-a。
arm-arm-none-eabi
為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。
1.2 -march選項:指定ARM 架構/ -mcpu 選項:指定處理器
用戶需要-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=<name>-march=<name>[+[no]<feature>+...] (to enable or disable optional extensions)如果要查看所選target的所有受支持架構的列表,使用-march=list。?其中<name>字段可以是如下表格中的架構:
| 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. |
?<feature>字段是可選的,用于指定一些功能的開啟或關閉。
- +<feature>如果默認禁用該功能,則啟用該功能。+<feature>在默認啟用的情況下無效。
- +no<feature>如果默認啟用該功能,則禁用該功能。+no<feature>對于默認禁用的功能無效。
使用+<feature>或+no<feature>顯式地啟用或禁用一個可選的架構特性。
用戶需要避免同時指定架構(-march)和處理器(-mcpu),因為同時指定兩者有可能導致沖突。編譯器優先從處理器推斷正確的體系結構。
- 如果你想在一個特定的處理器上運行代碼,使用-mcpu指定處理器。性能將得到優化,但代碼只能保證在該處理器上運行。如果你為-mcpu指定了一個值,就不要再使用-march。
- 如果希望代碼在特定體系結構的一系列處理器上運行,請使用-march指定該體系結構。代碼可以在該指定架構支持的任何處理器上運行。
1.3 -x/ -std 選擇源語言
armclang為不同的源語言標準提供了不同級別的支持。Arm Compiler for Embedded 6可以從文件擴展名中推斷源語言,例如.c 表明是C語言,.CPP表明是C++。用戶可以使用-x和-std選項強制編譯器針對特定的源語言和源語言標準進行編譯。
使用-xc++強制編譯器對.c文件使用c++語言標準編譯:
armclang --target=aarch64-arm-none-eabi -march=armv8-a -xc++ file.c使用-xc強制編譯器對.cpp文件使用c語言標準編譯:
armclang --target=aarch64-arm-none-eabi -march=armv8-a -xc file.cpp
Arm Compiler for Embedded 所支持的源語言:
| c90 | gnu90 | c++98 | gnu++98 |
| c99 | gnu99 | c++03 | gnu++03 |
| c11 [COMMUNITY] | gnu11 [COMMUNITY] | c++11 | gnu++11 |
| - | - | c++14 | gnu++14 |
| - | - | c++17 | gnu++17 |
C代碼的默認語言標準是gnu11 [COMMUNITY]。c++代碼的默認語言標準是gnu++17。要指定不同的源語言標準,請使用-std=<name>選項。?因為Arm Compiler for Embedded默認使用可用的語言擴展,所以它不遵守嚴格的ISO標準。要將源語言編譯為嚴格的ISO標準,請使用-Wpedantic選項。此選項在源代碼違反ISO標準時生成警告。Arm嵌入式編譯器不支持嚴格遵守c++ 98或c++ 03。
2,使用示例
Armv8-A +AArch64 :
armclang --target=aarch64-arm-none-eabi -march=armv8-a helloworld.cArmv8-R + AArch32 :
armclang --target=arm-arm-none-eabi -march=armv8-r helloworld.cArmv8-M architecture mainline profile:
armclang --target=arm-arm-none-eabi -march=armv8-m.main helloworld.cCortex?-A53 +AArch64 :
armclang --target=aarch64-arm-none-eabi -mcpu=cortex-a53 helloworld.cCortex-A53 +?AArch32 :
armclang --target=arm-arm-none-eabi -mcpu=cortex-a53 helloworld.cCortex-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.cAArch32 + Arm? Neoverse? N1 :
armclang --target=arm-arm-none-eabi -mcpu=neoverse-n1 helloworld.cAArch64 state + Arm Neoverse E1 :
armclang --target=aarch64-arm-none-eabi -mcpu=neoverse-e1 helloworld.c3,armclang common options?
| -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,?--target=arm-arm-none-eabi -march=armv7-a -marm. This option emphasizes performance. The?-marm?option is not valid with M-profile or AArch64 targets:
|
| -mthumb | Requests that the compiler targets the T32 instruction set, which consists of both 16-bit wide and 32-bit wide instructions. For example,?--target=arm-arm-none-eabi -march=armv8-a -mthumb. This option emphasizes code density. The?-mthumb?option is not valid with AArch64 targets. The compiler ignores the?-mthumb?option and generates a warning if used with AArch64 targets. |
| -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. |
4, armlink common options
| --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,?--info=sizes,unused,unusedsymbols?displays information about all the following:
|
| --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. |
5, armar common options
| --debug_symbols | Includes debug symbols in the library. |
| -a pos_name | Places new files in the library after the file?<pos_name>. |
| -b pos_name | Places new files in the library before the file?<pos_name>. |
| -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. |
6, fromelf common options
| --elf | Selects ELF output mode. |
| --text <options> | Displays image information in text format. The optional?<options>?specify additional information to include in the image information. Valid?<options>?include?-c?to disassemble code, and?-s?to print the symbol and versioning tables. You can also use?<options>?without specifying?--text. |
| --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. |
7,armasm common options?
| --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. |
總結
以上是生活随笔為你收集整理的Arm Compiler for Embedded 6 编译器工具链常用选项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网站维护要做哪些工作
- 下一篇: 刚刚!华为突然传来这一消息,我想辞职回家