memcpy on gcc code sourcery for ARM

有些话、适合烂在心里 提交于 2019-12-11 03:49:12

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/10659914/memcpy-on-gcc-code-sourcery-for-arm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!