memcpy关于ARM的gcc代码源 [英] memcpy on gcc code sourcery for ARM

查看:402
本文介绍了memcpy关于ARM的gcc代码源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用arm code sourcery(arm-none-eabi-gcc)(我认为是精简版)编译了我的代码.

我在函数内部定义一个struct变量,并像

一样进行memcpy

typedef struct  {
  char        src[6];           
  char        dst[6];          
  uint16_t    a;          
  uint16_t    b;    
  uint32_t    c;       
  uint16_t    d;       
} Info_t;

Info_t Info;

    memcpy(Info.src, src, sizeof(Info.src));
    memcpy(Info.dst, dst, sizeof(Info.dst));

第一个memcpy通过,但是第二个memcpy导致中止.

我听说gcc优化了memcpy并导致结构对齐方式不对齐?

我尝试将struct变量与单词边界等对齐.但这没有用.

任何人都可以提供有关gcc和对齐方式问题的更多详细信息.

谢谢!

据我所知,ARM中的memcopy()问题与编译器对优化实现的使用有关.

"在许多情况下,当编译对memcpy()的调用时,ARM C编译器将改为生成对专用的,优化的库函数的调用.自RVCT 2.1起,这些专用函数是ARM体系结构的ABI(AEABI ),并包括:

  • __ aeabi_memcpy

此函数与ANSI C memcpy相同,不同之处在于返回值是空的.

  • __ aeabi_memcpy4

此功能与__aeabi_memcpy相同;但可以假定指针是4字节对齐的.

  • __ aeabi_memcpy8

此函数与__aeabi_memcpy相同,但可以假定指针是8字节对齐的."

详细信息可以在这里找到: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3934.html

I have my code compiled using arm code sourcery (arm-none-eabi-gcc) ( I think Lite Edition).

I define a struct variable inside a function, and do a memcpy like

typedef struct  {
  char        src[6];           
  char        dst[6];          
  uint16_t    a;          
  uint16_t    b;    
  uint32_t    c;       
  uint16_t    d;       
} Info_t;

Info_t Info;

    memcpy(Info.src, src, sizeof(Info.src));
    memcpy(Info.dst, dst, sizeof(Info.dst));

The first memcpy goes through, but the second one is causing a abort.

I heard that the gcc optimizes memcpy and is resulting in an non- aligned struct acess?

I tried aligning the struct variable to a word boundary etc. But it did not work.

Can anyone give more details on the memcpy of gcc and alignment issue.

Thanks!

解决方案

The memcopy() issue in ARM is related with the use of optimized implementation by the compiler as far as I understand.

"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.

  • __aeabi_memcpy4

This function is the same as __aeabi_memcpy; but may assume the pointers are 4-byte aligned.

  • __aeabi_memcpy8

This function is the same as __aeabi_memcpy but may assume the pointers are 8-byte aligned."

Details can be found here : http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3934.html

这篇关于memcpy关于ARM的gcc代码源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆