打印
[MCU]

keil MDK compiler v6代码最高优化下,无法把函数加载到指定位置

[复制链接]
2441|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
用的keil mdk2.5版本,编译器用的V6版本
以前比如要把一个函数加载到指定地址,只需如下写即可:
void fun (void)  __attribute__((section(".ARM.__at_0x20001000"))) ;
上述代码在V5版本各种优化级别下都可正常工作,在V6不优化级别可以正常工作,提高优化级别就不能加载到指定地址,求大神帮忙解答,拜谢!

使用特权

评论回复

相关帖子

沙发
java0735|  楼主 | 2019-6-14 07:04 | 只看该作者
大家工作中没遇到这种问题吗?还是我描述不清? 我现在任何的问题是要把几个函数放在RAM中运行,但不知道怎么在keil里面编程

使用特权

评论回复
板凳
ayb_ice| | 2019-6-14 08:13 | 只看该作者
java0735 发表于 2019-6-14 07:04
大家工作中没遇到这种问题吗?还是我描述不清? 我现在任何的问题是要把几个函数放在RAM中运行,但不知道怎 ...

网上搜索,方法很多的,根本不需要绝对定位

使用特权

评论回复
地板
linqing171| | 2019-6-14 11:07 | 只看该作者
V6是基于LLVM的clang的前端,非C标准的扩展都变了,不再兼容V5的,你按GCC的来用一下看看。
V3-V5都是keil自己的编译器兼容keil和ADS,
V1-V2是老keil的编译器

使用特权

评论回复
5
java0735|  楼主 | 2019-6-14 17:25 | 只看该作者
ayb_ice 发表于 2019-6-14 08:13
网上搜索,方法很多的,根本不需要绝对定位

网上的方法都是针对V5及以前的版本,V6都没法用

使用特权

评论回复
6
java0735|  楼主 | 2019-6-14 17:26 | 只看该作者
linqing171 发表于 2019-6-14 11:07
V6是基于LLVM的clang的前端,非C标准的扩展都变了,不再兼容V5的,你按GCC的来用一下看看。
V3-V5都是keil ...

在网上没有找到

使用特权

评论回复
7
java0735|  楼主 | 2019-6-14 17:26 | 只看该作者
哪位大神,有没有碰到过?搞了好久都没搞定

使用特权

评论回复
8
ayb_ice| | 2019-6-14 17:29 | 只看该作者

RT:

QQ截图20190614172903.png (331.14 KB )

QQ截图20190614172903.png

使用特权

评论回复
9
apleilx| | 2019-6-15 09:20 | 只看该作者
V6确实各种坑,就连链接器的程序分区功能都没了。复杂的项目还要用V5或者IAR。

使用特权

评论回复
10
java0735|  楼主 | 2019-6-16 07:13 | 只看该作者
apleilx 发表于 2019-6-15 09:20
V6确实各种坑,就连链接器的程序分区功能都没了。复杂的项目还要用V5或者IAR。 ...

但是V6的优化能力还是很强的,同样的代码,最高优化级编译,V6编译后的code量比V5要小很多,我们用的CPU flash空间有限,还是要求用V6
继续等牛人帮忙解答

使用特权

评论回复
11
linqing171| | 2019-6-16 10:30 | 只看该作者
java0735 发表于 2019-6-16 07:13
但是V6的优化能力还是很强的,同样的代码,最高优化级编译,V6编译后的code量比V5要小很多,我们用的CPU  ...

GCC的方法你没有试?
keil2 是 __at
keil被ARM收购后合并ads后是  __attribute__((at, 不过包含了头文件后,也是有兼容的宏可以用的。
GCC的是__attribute__ ((section(  ......  然后再链接器配置文件里制定section的排序和位置定位

LLVM的优化效率确实比较高,clang的前端是可以兼容GCC的。至于有没有兼容的宏,需要看keil官方的
“Migration and Compatibility” 文档,和 v6版本的 “Compiler Reference Guide”文档。

我印象里装了ARM CC v6后,帮助里面有。因为除了工作外,我要测试我们项目在各个keil版本下的hex的汇编区别,以及是否有风险。 所以我装的最新版本的keil,不知道为什么里面没有带v6的编译器。project的options里面也无法选择项目使用v6的编译器。
一个问题好几天了还没有搞定?

使用特权

评论回复
12
linqing171| | 2019-6-16 10:42 | 只看该作者
如果你的keil的帮助里面没有,你可以看官方的:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.swdev.comp6/index.html
里面有章节讲了从v5到v6迁移的例子,pdf版本可以从
http://infocenter.arm.com/help/topic/com.arm.doc.100068_0611_00_en/migration_and_compatibility_guide_100068_0611_00_en.pdf
下载,
里面的第53页有讲怎么处理at。
如果你下载不下来,我复制了如下,格式很乱,自己看吧。

Section
__attribute__((section("name"))) is supported by Arm Compiler 5 and Arm Compiler 6. However,
this attribute might require modification in your code.
When using Arm Compiler 5, section names do not need to be unique. Therefore, you could use the same
section name to create different section types.
Arm Compiler 6 supports multiple sections with the same section name only if you specify a unique ID.
You must ensure that different section types either:
• Have a unique section name.
• Have a unique ID, if they have the same section name.
If you use the same section name, for another section or symbol, without a unique ID, then armclang
integrated assembler merges the sections and gives the merged section the flags of the first section with
that name.
Migrating __attribute__((at(address))) and zero-initialized __attribute__((section("name")))
from Arm®
Compiler 5 to Arm®
Compiler 6
Arm Compiler 5 supports the following attributes, which Arm Compiler 6 does not support:
• __attribute__((at(address))) to specify the absolute address of a function or variable.
• __attribute__((at(address), zero_init)) to specify the absolute address of a zero-initialized
variable.
• __attribute__((section(name), zero_init)) to place a zero-initialized variable in a zeroinitialized
section with the given name.
• __attribute__((zero_init)) to generate an error if the variable has an initializer.
The following table shows migration paths for these features using Arm Compiler 6 supported features:
Table 4-4 Migrating __attribute__((at(address))) and zero-initialized __attribute__((section("name")))
Arm Compiler 5 attribute Arm Compiler 6 attribute Description
__attribute__((at(address))) __attribute__((section(".ARM.__at_address"))) armlink in Arm Compiler 6
still supports the placement of
sections in the form
of .ARM.__at_address
__attribute__((at(address),
zero_init))
__attribute__((section(".bss.ARM.__at_address"))) armlink in Arm Compiler 6
supports the placement of zeroinitialized
sections in the form
of .bss.ARM.__at_address.
The .bss prefix is case
sensitive and must be all
lowercase.
__attribute__((section(name),
zero_init))
__attribute__((section(".bss.name"))) name is a name of your choice.
The .bss prefix is case
sensitive and must be all
lowercase.
__attribute__((zero_init)) Arm Compiler 6 by default places zero-initialized variables in
a .bss section. However, there is no equivalent to generate an
error when you specify an initializer.
Arm Compiler 5 generates an
error if the variable has an
initializer. Otherwise, it places
the zero-initialized variable in
a .bss section.

排版太差了,我也看不下去了,表格部分抓了个图,不过一定要配合上下文。
1 如果看不懂英语,继续问,论坛里有博士和博导天天吵架,要不耻上问。
2 如果keil本身有bug,和keil官方沟通。

keil_v6_at.png (144.48 KB )

keil_v6_at.png

使用特权

评论回复
13
java0735|  楼主 | 2019-6-16 14:51 | 只看该作者
linqing171 发表于 2019-6-16 10:42
如果你的keil的帮助里面没有,你可以看官方的:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm ...

非常感谢你的回复,你说的这几个文档,我都有查看,不知道是不是英文水平的问题,参考修改后,还是不能用

使用特权

评论回复
14
java0735|  楼主 | 2019-6-16 18:18 | 只看该作者
本帖最后由 java0735 于 2019-6-16 18:45 编辑

我觉问题主要出在,找不到指定的section name,比如说
void fun (void)  __attribute__((section("foo"))) ;
理论上编译器会配置fun函数的段名为foo,但是在map文件里根本找不到foo段名,不知道是不是哪个地方需要配置一下,求指导
只要编译后map文件有foo这个段名,我就可以在加载文件中做任何我想要的定位处理了。
楼上的建议我都试过了,都不行,V6以前的版本都没问题的,哎。
我使用的keil mdk版本是V5.25.2  编译器V6.9
继续等待大神
下图摘自Arm® Compiler armclang Reference Guide

使用特权

评论回复
15
java0735|  楼主 | 2019-6-16 18:21 | 只看该作者
V6编译器,优化等级配置O0,一切都能实现,只要优化等级提高,就不行了,我觉得还是哪个地方配置有问题,今天看mdk的英文文档看了一天,还是没解决(也有可能是英文理解能力有限),头大.......

使用特权

评论回复
16
wdliming| | 2019-12-20 14:20 | 只看该作者
java0735 发表于 2019-6-16 18:21
V6编译器,优化等级配置O0,一切都能实现,只要优化等级提高,就不行了,我觉得还是哪个地方配置有问题,今 ...

我也发现了这个问题的。很奇怪的

使用特权

评论回复
17
lavilycn| | 2019-12-24 18:19 | 只看该作者
ARM Compiler 5 attribute                   ARM Compiler 6 attribute
__attribute__((at(address)))        __attribute__((section(".ARM.__at_address")))

我已解决。如上

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

294

帖子

2

粉丝