如何摆脱GCC汇编警告&QUOT的;设置不正确节.init&QUOT属性;在C code吗? [英] How to get rid of gcc assembler warning "setting incorrect section attributes for .init" in C code?
问题描述
我有以下的C code:
I have the following C code:
struct myStruct_t
{
const char m_name[60];
const uint32_t m_data;
};
const struct myStruct_t myStruct
__attribute__(( __aligned__( 64 ), section(".init") )) =
{
"myName",
(uint32_t)&someOtherStruct
};
当我在GCC 4.1.1(适用于PS3)编译,我得到警告:
When I compile in gcc 4.1.1 (for PS3), I get the warning:
1>c:/t/ccy6.s: Assembler messages:
1>c:/t/ccy6.s(106): Warning: setting incorrect section attributes for .init
组装code警告指的是下面的.section伪条款:
The assembly code the warning points to is the ".section" clause below:
.section .init,"aw",@progbits
.align 6
.type myStruct , @object
.size myStruct , 64
myStruct :
.ascii "myName"
.long someOtherStruct
它不喜欢的标志的W(写入)的部分,因为在.init东西是只读的,而在所有可能的地方并不强迫编译器不吐出常量,在 W。我怎么能告诉编译器没有,真的,这是const的,我不是在开玩笑?
It doesn't like the "w" (writable) part of the flags since stuff in .init is read-only, and "const" in all the possible places doesn't compel the compiler not to spit out the "w". How can I tell the compiler "no, really, it is const, I'm not kidding"?
推荐答案
这是与海湾合作委员会自指定为.section伪指令的参数有问题。幸运的是,栏目名称参数直接复制到汇编输出,允许您解决此问题。
This is a problem with GCC auto-specifying the parameters for the .section directive. Luckily, the section name parameter is copied directly into the assembly output, permitting you to work around this issue.
这个指令:
__attribute__ ((section(".init")))
生成此组件:
.section .init,"aw",@progbits
要删除的警告,你可以指定这样的属性:
To remove the warning, you can specify the attribute like this:
__attribute__ ((section(".init,\"ar\",@progbits ;")))
这将产生:
.section .init,"ar",@progbits ;"aw",@progbits
分号标志着该行作为注释的休息,所以汇编程序会忽略它。
The semicolon marks the rest of the line as a comment, so the assembler ignores it.
这篇关于如何摆脱GCC汇编警告&QUOT的;设置不正确节.init&QUOT属性;在C code吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!