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

By: Ailson Jack
Date: 2019.12.29
个人博客:http://www.only2fire.com/
本文在我博客的地址是:http://www.only2fire.com/archives/110.html,排版更好,便于学习,也可以去我博客逛逛,兴许有你想要的内容呢。

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

         ARM官方的迁移文档,下载地址:,密钥:。(可到我的个人博客中进行下载)

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

    这里新开一篇博文,专门讲讲针对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

       如果觉得文章写的不错,对你有帮助,欢迎点赞,关注博主哟!

排版更好的内容见我博客的地址:http://www.only2fire.com/archives/110.html
注:转载请注明出处,谢谢!^_^

猜你喜欢

转载自blog.csdn.net/jackailson/article/details/103753951
今日推荐