GCC 中的 C 函数对齐
我正在尝试使用“aligned(16)”属性将函数字节对齐到 16 字节边界。我执行了以下操作: void __attribute__((aligned(16))) function() { }
(来源:http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html)
但是当我编译时 (gcc foo.c ; 没有 makefiles 或链接器脚本使用),我收到以下错误:
FOO.c:99: error:alignment may not bespecified for 'function'
我也尝试对齐到 4,8,32 等,但错误仍然相同。 我需要它来调整基于 powerpc 的处理器的中断服务例程。这样做的正确方法是什么?
I am trying to byte-align a function to 16-byte boundary using the 'aligned(16)' attribute. I did the following: void __attribute__((aligned(16))) function() { }
(Source: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html)
But when I compile (gcc foo.c ; no makefiles or linker scripts used), I get the following error:
FOO.c:99: error: alignment may not be specified for 'function'
I tried aligning to 4,8,32, etc as well but the error remains the same.
I need this to align an Interrupt Service Routine for a powerpc-based processor. What is the correct way of doing so ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据我对这个 GCC 问题的回答,你可以尝试使用#pragma指令,如下所示:
#pragma push_options
和pop_options
宏用于控制optimize的范围
pragma 的效果。有关这些宏的更多详细信息,请参阅 GCC 文档。或者,如果您更喜欢GCC 的属性语法< /strong>,您应该能够执行以下操作:
Adapting from my answer on this GCC question, you might try using #pragma directives, like so:
The
#pragma push_options
andpop_options
macros are used to control the scope of theoptimize
pragma's effect. More details about these macros can be found in the GCC docs.Alternately, if you prefer GCC's attribute syntax, you should be able to do something like:
为什么编译时不直接将 -falign-functions=16 传递给 gcc 呢?
Why don't you just pass the -falign-functions=16 to gcc when compiling?
您可能使用的是不支持该属性的旧版本 gcc。您提供的文档链接适用于 gcc 的“当前开发”。浏览各个版本,该属性仅出现在 gcc 4.3 及更高版本的文档中。
You are probably using an older version of gcc that does not support that attribute. The documentation link you provided is for the "current development" of gcc. Looking through the various releases, the attribute only appears in the documentation for gcc 4.3 and beyond.