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>字段可以是如下表格中的架构:

Architecture <name> 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.

 <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 所支持的源语言:

Table 1. Supported C and C++ source language variants
Standard C GNU C Standard C++ GNU C++
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.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

3,armclang common options 

Table 1. armclang common options
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, --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:

  • If you use the -marm option with an M-profile target architecture, the compiler generates an error and stops, and does not output any code.
  • For AArch64 targets, the compiler ignores the -marm option and generates a warning.
-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

Table 2. armlink common options
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, --info=sizes,unused,unusedsymbols displays information about all the following:

  • Code and data sizes for each input object and library member in the image.
  • Unused sections that --remove has removed from the code.
  • Symbols that were removed with the unused sections.
--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

Table 3. armar common options
Option Description
--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 CodeRO DataRW DataZI Data, and Debug sizes of each member in the library.
-t Prints a table of contents for the library.

6, fromelf common options

Table 4. fromelf common options
Option Description
--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 CodeRO DataRW DataZI Data, and Debug sizes for each input object and library member in the image.

7,armasm common options 

Table 5. armasm common options
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.

猜你喜欢

转载自blog.csdn.net/luolaihua2018/article/details/130071574
今日推荐