嵌入式系统与单片机|技术阅读
登录|注册

您现在的位置是:嵌入式系统与单片机 > 技术阅读 > 基于ARM编译器版本5的工程迁移与适配到ARM编译器版本6.12 后续1 - 汇编代码处理问题

基于ARM编译器版本5的工程迁移与适配到ARM编译器版本6.12 后续1 - 汇编代码处理问题

为了描述方便,将ARM Compiler 5简称为AC5,将ARM Compiler 6.12简称AC6.12。

在公众号中回复"arm编译器升级文档"可以获取AC5升级到AC6.12的ARM官方文档。

1、armasm编译汇编代码,链接失败的问题

这里新开一篇博文,专门讲讲针对ARM格式的汇编代码,使用AC6.12应该如何处理。下述内容大多来自文档《migration_and_compatibility_guide_100068_0612_00_en.pdf》文档的 3.3 Command-line options for preprocessing assembly source code

我在我自己的工程中遇到过使用AC6.12编译汇编代码成功,但是链接会失败。提示内容大致是:xxx.scf Error: L6236E: No section matches selector - no section to be FIRST/LAST.对于这个问题,我起初以为是分散加载文件(*.scf)有问题,看了半天的分散加载文件内容,也没发现分散加载文件有问题。于是我转换方向,使用命令去手动编译startup_LPC55S69_cm33_core0.s,然后再手动链接,发现还是提示xxx.scf Error: L6236E: No section matches selector - no section to be FIRST/LAST.错误。

于是我再次查阅ARM官方的升级与适配手册《migration_and_compatibility_guide_100068_0612_00_en.pdf》,发现armasm使用--cpreproc--cpreproc_opts选项编译汇编代码时,输入源代码的后缀名是.S(大写)。然而我的工程的ARM格式的汇编代码文件的后缀名均为小写,导致了armasm处理出错。下面是文档中3.3 Command-line options for preprocessing assembly source code--cpreproc--cpreproc_opts的描述:

If you are using armasm to assemble source code that requires the use of the preprocessor, you must use both the --cpreproc and --cpreproc_opts options together. Also:
• As a minimum, you must include the armclang options --target and either -mcpu or -march in --cpreproc_opts.
• The input assembly source must have an upper-case extension .S.

其中第2点,对汇编源文件后缀名为大写.S作了一个说明吧。

为了处理汇编源文件后缀是小写.s的情况,文档的下面也提供了一个操作的说明吧:

If you have existing source files, which require preprocessing, and that have the lower-case extension .s, then to avoid having to rename the files:
1.Perform the preprocessing step separately using the armclang -x assembler-with-cpp option.
2.Assemble the preprocessed file without using the --cpreproc and --cpreproc_opts options.

上面这段英文的内容给出了汇编源代码文件后缀是小写.s,但是又不想修改源代码后缀的方法,首先使用armclang (带编译选项-x assembler-with-cpp)去预处理*.s汇编代码,生成一个过程*.s文件,接着再使用armasm(不带编译选项--cpreproc--cpreproc_opts)去编译这个过程*.s文件。这里提供一个例子如下:

(1).armclang --target=arm-arm-none-eabi -mcpu=cortex-m33 -x assembler-with-cpp -E test.s -o test_preproc.s

(2).armasm --cpu=Cortex-M33 --fpu=FPv5-SP test_preproc.s

2、总结

ARM Compiler 6.12对于ARM格式的汇编处理,这里总结下吧,分两种情况:

(1).如果ARM格式汇编代码源文件的后缀名是大写的.S,那么直接使用armasm 带编译选项--cpreproc--cpreproc_opts进行编译即可,例如:

armasm --cpu=cortex-m33 --cpreproc --cpreproc_opts=--target=arm-arm-none-eabi,-mcpu=cortex-m33 startup_LPC55S69_cm33_core0.S

(2).如果ARM格式汇编代码源文件的后缀名是小写的.s,这里就需要特殊处理了,有两种方法:

a.将ARM格式汇编代码源文件的后缀名改为大写.S,然后按照步骤(1)进行处理即可。

b.首先使用armclang (带编译选项-x assembler-with-cpp)去预处理*.s汇编代码,生成一个过程*.s文件,接着再使用armasm(不带编译选项--cpreproc--cpreproc_opts)去编译这个过程*.s文件。这里提供一个例子如下:

1).armclang --target=arm-arm-none-eabi -mcpu=cortex-m33 -x assembler-with-cpp -E test.s -o test_preproc.s

2).armasm --cpu=Cortex-M33 --fpu=FPv5-SP test_preproc.s

迎关注博主的公众号:

如果文中有什么问题欢迎指正,毕竟博主的水平有限。

如果这篇文章对你有帮助,记得点赞和关注博主就行了。

注:转载请注明出处,谢谢!