ARMCC:memcpy问题(对齐异常)

ARMCC:memcpy问题(对齐异常),第1张

概述我正在将一些软件从 gcc-toolchain移植到armcc-toolchain(处理器保持不变(Cortex-A9)).在C代码中使用memcpy. armcc通过调用__aeabi_memcpy替换对memcpy的调用.常见问题解答如下关于__aeabi_memcpy( How do the ARM Compilers handle memcpy()?): In many cases, wh 我正在将一些软件从 gcc-toolchain移植到armcc-toolchain(处理器保持不变(Cortex-A9)).在C代码中使用memcpy. armcc通过调用__aeabi_memcpy替换对memcpy的调用.常见问题解答如下关于__aeabi_memcpy( How do the ARM Compilers handle memcpy()?):

In many cases,when compiling calls to memcpy(),the ARM C compiler will generate calls to specialized,optimised,library functions instead. Since RVCT 2.1,these specialized functions are part of the ABI for the ARM architecture (AEABI),and include:

__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.

但是与gcc相比,在我的所有情况下对memcpy的调用都可以正常工作,使用armcc对memcpy的调用__aeabi_memcpy会连续产生对齐异常.同时我发现,对memcpy的调用可以处理源和目标地址不是4字节对齐的调用,但前提是它们都不是4字节对齐的.例如:

将工作.但是例如:

会导致对齐异常.我正在使用uint8_t类型的指针*我明确告诉编译器地址可以有任何对齐.但显然这个__aeabi_memcpy无法处理每个路线组合.如何解决此问题(最好不使用用户特定版本的memcpy更改现有代码中对memcpy的所有调用)?感谢帮助.

volatile uint32_t len = 10; uint8_t* src = (uint8_t*)0x
__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.

002; // 2-byte aligned
uint8_t* dst = (uint8_t*)(0x

__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.
__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.002 + 20); // 2-byte aligned
memcpy(dst,src,len);
volatile uint32_t len = 10; uint8_t* src = (uint8_t*)0x
__aeabi_memcpyThis function is the same as ANSI C memcpy,except that the return value is voID.002 + 22); // 4-byte aligned
memcpy(dst,len);
解决方法 如果您不想更改代码,可以使用以下两个选项:

1)禁用Cortex-A9上的未对齐异常.这完全解决了问题,但您可能会受到性能影响.

2)修补图书馆.您可以在要链接的lib文件中重命名符号__aeabi_memcpy.然后,您可以实现自己的__aeabi_memcpy来检测对齐错误,使用专门的例程处理它或跳转到原始的memcpy函数.如果您使用的是linux,则甚至不需要重命名该符号.链接器允许您覆盖函数.

这两种解决方案都很脏,但如果您不想更改代码,这就是我能想到的全部内容.

哦,你应该提交一份错误报告.你见过的行为肯定是一个错误. Memcpy应该可以正常工作任何对齐.

总结

以上是内存溢出为你收集整理的ARMCC:memcpy问题(对齐异常)全部内容,希望文章能够帮你解决ARMCC:memcpy问题(对齐异常)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1239582.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)