Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
874 views
in Technique[技术] by (71.8m points)

gcc - What does the "aw" flag in the section attribute mean?

In the following line of code (which declares a global variable),

unsigned int __attribute__((section(".myVarSection,"aw",@nobits#"))) myVar;

what does the "aw" flag mean?

My understanding is that the nobits flag will prevent the variable from being initialised to zero, but I am struggling to find info about the "aw" flag.

Also, what meaning do the @ and # have around the nobits flag?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The section("section-name") attribute places a variable in a specific section by producing the following assembler line:

.section    section-name,"aw",@progbits

When you set section-name to ".myVarSection,"aw",@nobits#" you exploit a kind of "code injection" in GCC to produce:

.section    .myVarSection,"aw",@nobits#,"aw",@progbits

Note that # sign starts a one-line comment.

See GNU Assembler manual for the full description of .section directive. A general syntax is

.section name [, "flags"[, @type[,flag_specific_arguments]]]

so "aw" are flags:

  • a: section is allocatable
  • w: section is writable

and @nobits is a type:

  • @nobits: section does not contain data (i.e., section only occupies space)

All the above is also applicable to functions, not just variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...