ARM对齐的内存访问的解决方法 [英] ARM unaligned memory access workaround

查看:316
本文介绍了ARM对齐的内存访问的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来港源$ C ​​$ C从到运行Linux的一个ARM平台。不幸的是我遇到了未对齐的内存访问问题。源使用指针类型转换和访问沉重。

I have to port source code from to an ARM platform that runs Linux. Unfortunately I have run into unaligned memory access problems. The source uses pointer casts and access heavily.

低于code类的人有超过codeBase的像S病毒$ P $垫。我可以找出有问题的位置由于海湾合作委员会 -Wcast对齐命令行选项,但有超过一千个实例去。

Code like the one below has spread over the codebase like a virus. I can pinpoint the problematic locations thanks to the gcc -Wcast-align command line option but there are over a thousand instances to go through.

u = (IEC_BOOL);
(((*(IEC_LINT*)pSP).H < b.H) 
   || (((*(IEC_LINT*)pSP).H == b.H) && ((*(IEC_LINT*)pSP).L < b.L) )) ? 1 : 0);
*(IEC_DWORD OS_SPTR *)pSP = 
    (IEC_DWORD)(*(IEC_DWORD OS_SPTR *)pSP >> u);  
*(IEC_DWORD OS_SPTR *)pSP = 
    (IEC_DWORD)(*(IEC_DWORD OS_SPTR *)pSP << -u);  
u = (IEC_BYTE)((*(IEC_DINT*)pSP != b) ? 1 : 0);  
*(IEC_DWORD*)pSP = (IEC_DWORD)(*(IEC_DWORD*)pSP & w);  
(*(IEC_ULINT*)pSP).H += u.H;   
(((*(IEC_ULINT OS_SPTR *)pSP).H == b.H) 
    && ((*(IEC_ULINT OS_SPTR *)pSP).L > b.L))) ? 1 : 0);
u = (IEC_BYTE)((*(IEC_REAL*)pSP >= b) ? 1 : 0);

使用回声2 - ;的/ proc / CPU /对准上使Linux内核解决问题,但应用程序的性能下降到一个点,是不能接受任何更多的

Using echo 2 > /proc/cpu/alignment on makes the Linux Kernel fix the problems but the performance of the application is degraded to a point that is not acceptable any more.

我搜索净的东西像 __对齐 __海湾合作委员会(v4.4.1)编译器包装关键字但由于尚未来到了空。

I searched the net for something like a __unaligned or __packed keyword for the GCC (v4.4.1) compiler but as of yet came up empty.

我想了很多的poblematic code线可以固定或多或少复杂的正则表达式/替换,但现在,这样做了,而我看到的,而且,这种方法将采取enourmous大量繁琐的工作后,

I thought a lot of the poblematic code lines could be fixed with a more or less complex regexp/replace but now, after doing that for a while I see, that also this approach will take enourmous amounts of tedious work.

难道你们有什么建议,如何得到这份工作呢?我觉得一个gcc 4.5编译器插件将是矫枉过正,但有什么比普通前pressions更好?你能想出什么其他的建议了?不一定所有的问题实例必须是固定的,因为我仍然可以依靠内核几罕见的情况。

Do you guys have any suggestion how to get this job done? I think a gcc 4.5 compiler plugin would be overkill but is there something better than regular expressions? what other suggestions can you come up with? Not necessarily all problem instances have to be fixed since I can still rely on the Kernel for a few rarer cases.

推荐答案

__属性__((__包装__))这可能有助于在某些情况下,但我真的认为这code应该被清理,而早比晚,因为它很可能你会花更多的时间各地工作的问题比它会采取修复它一劳永逸。

There is __attribute__((__packed__)) which might help in some instances, but I really think this code should be cleaned up rather sooner than later, because it is likely that you will spend more time working around problems than it would take to fix it once and for all.

这篇关于ARM对齐的内存访问的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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