ARMCC:memcpy问题(对齐异常)

我正在将一些软件从 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_memcpy
This 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_memcpy
This 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_memcpy
This function is the same as ANSI C memcpy,except that the return value is void.
__aeabi_memcpy This function is the same as ANSI C memcpy,except that the return value is void.__aeabi_memcpy This 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_memcpy
This 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应该可以正常工作任何对齐.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...