Reputation: 920
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?
Upvotes: 29
Views: 13935
Reputation: 4962
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:
and @nobits
is a type:
All the above is also applicable to functions, not just variables.
Upvotes: 38
Reputation:
what does the "aw" flag mean?
It means that the section is allocatable (i.e. it's loaded to the memory at runtime) and writable (and readable, of course).
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?
@nobits (@ is just a part of the name) means that the section isn't stored in the image on disk, it only exists in runtime (and it's filled with zeros at the startup).
# character begins the comment, so whatever the compiler will put in addition to what you have specified will be ignored.
Upvotes: 5