目录

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.

Arm Compiler for Embedded 6 编译器工具链常用选项相关推荐

  1. ARM 编译器 Arm Compiler for Embedded 6 相关工具链简介

    目录 1, Introduction to Arm® Compiler 6 1.1 armclang 1.2 armasm 1.3 armlink 1.4 armar 1.5 fromelf 1.6  ...

  2. 编译器工具链(二)——交叉编译

    编译器工具链 编译器工具链包含各种其他的二进制文件,以帮助整个编译过程.在某些情况下,编译器本身也是工具链的一部分.以下列表被打包在工具链中: binutils(汇编器.链接器等) 各种编译器(gcc ...

  3. 编译器工具链初步解析

    GNU 一般编译器分为三个stage: cc1,as,ld. 预处理器:cc1 编译器:cc1 →输出汇编代码 (* .s) 汇编程序:as → 输出目标文件 (* .o) 链接器:ld (colle ...

  4. 交叉编译器工具链的使用

    在hi3536中使用的是arm-hisiv400-linux- ,使用的是glibc 在hi3516中使用的是arm-hisiv300-linux-,使用的是ulibc

  5. ARM 编译工具链详解

    ARM 编译工具链详解 GNU Arm Embedded Toolchain 是用于 C/C++ 和汇编编程的即用型开源工具套件.GNU Arm 嵌入式开发工具链适用于 32 位 Arm Cortex ...

  6. Keil(MDK-ARM)如何补充安装旧的编译器 AC5(ARM Compiler 5)

    目录 一.前言 二.下载 1. 进入 Arm Developer 官网 2. 下载 ARM Compiler 5 安装包 3. 下载完成 三.安装 1. 开始安装 2. 安装过程 3. 安装完成 四. ...

  7. 使用CMAKE和交叉编译工具链

    记录使用CMake过程中的一段CMakeLists.txt的代码以及交叉编译脚本cross.cmake的代码. 文章目录 一.CMakeLists.txt 二.cross.cmake 总结 提示:代码 ...

  8. 交叉编译工具链建立与常识

    交叉编译工具链的命名规则 arch [-vendor] [-os] [-(gnu)eabi] arch – 体系架构,如ARM,MIPS,对于MIPS可能还分大端模式mips或者小端模式mipsel: ...

  9. Linux在Ubuntu虚拟机安装交叉编译工具链

    1.进入Linaro官网下载ARM交叉编译器工具链. 官网连接如下: https://releases.linaro.org/components/toolchain/binaries/4.9-201 ...

最新文章

  1. python sleep准确吗_Time.sleep对于Python计数器不准确?
  2. Python数据可视化2.6 一些最好的可视化实践
  3. 操作系统P,V(wait,signal原语)操作讲解,以及两个例题(答案仅供参考)
  4. 支持批任务的Coscheduling/Gang scheduling
  5. python误删文件怎么恢复_记录一次脚本误删文件后恢复
  6. python面试题之如何用Python输出一个斐波那契数列
  7. ios 如何在cell中去掉_iOS开发:关于 去除UITableViewCell复用机制 的几种方法
  8. varnish4.0简介
  9. Linux环境下实现一个简单socket通信
  10. java 图形化界面 布局管理器
  11. linux php 扩展包 下载地址
  12. 十种可以成为知己的异性
  13. 《基于Nginx的中间件架构》学习笔记---3.nginx的目录分析
  14. 解决安全频道支持出错,代码:80072F7D问题
  15. c语言扩展欧几里得算法编程实现,C语言实现欧几里得算法与扩展欧几里得算法.doc...
  16. 超市扫码机器服务器系统搭建,超市用的扫码机是怎么个原理?
  17. 基于方格网法的填挖方量计算(C++)
  18. jupyter无法重命名,文件不可信,后台被自动关闭
  19. PNP三极管和NPN三极管的开关电路(EC极性接线判断简单明了)简单的技巧:三极管上箭头所在方向的二极管,只要二极管正向导通,那么三极管上下就能导通。
  20. CVPR 2020 论文大盘点-人脸技术篇

热门文章

  1. 蒲香仲夏、专注字体全产业链接研究-江西字研#174;所隆重揭牌
  2. An中的共轭类的个数
  3. SSM框架实现不同用户登陆进入不同页面
  4. signature=ae0de8e34b6245c325b1b433d9eb5401,ELMA 德国艾尔玛,机械式增量型编码器, E27-0-21151 AL011...
  5. oracle enlist,针对各版本的 .NET 的 Oracle 新特性
  6. android高仿美团筛选控件,Android高仿美团首页分类按钮
  7. 大屏可视化的适配方案
  8. 8188gu驱动和su realtek_RTL8188CU 和RTL8188SU有什么区别,哪个好,谢谢
  9. win 10 查看mysql密码_win10下mysql重设密码教程
  10. 从qq服务器删除误收邮件,QQ邮箱撤回时显示撤回失败,对方已读 收件箱里的消息却是对方已阅读或已删除 这种情况下邮件有没有被删除...