Android NDK: C++ struct member access, causes SIGBUS (signal SIGBUS: illegal alignment)

后端 未结 1 1468
花落未央
花落未央 2021-01-26 20:34

I\'m porting a C++ library on Android (Android Studio 2.3.1/NDK 25); the library works flawlessly on UWP (VS2017 VC 1.41 - ARM & Win32) a custom ARM7 board (GCC 4.8).

<
相关标签:
1条回答
  • 2021-01-26 21:17

    I had exactly the same issue.

    In your code snippet, secPtr is not aligned because it points to buffer offseted by 1(sizeof(_t_u8)) byte. (assuming that buffer is aligned address)

    All 4-byte ailgned memory addresses should end in '0', '4', '8' or 'C'. Since secPtr ends in '5', it is not aligned.

    ARM processors support some of unaligned memory access. That is why secPtr->crc32 = 0; is legal, but secPtr->counter= 0; is not.

    Try removing 1-byte offset in secPtr somehow and see if the problem goes away.

    Also check out this page for detailed information: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html

    0 讨论(0)
提交回复
热议问题