[PATCH] D33412: Add support for #pragma clang section
Javed Absar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 22 08:19:40 PDT 2017
javed.absar created this revision.
Herald added a subscriber: aemerson.
This patch adds support for a '#pragma clang section' directive in clang.
An RFC was sent out earlier by my colleague James Molloy:
The purpose of this is to provide to developers a means to specify section-names
for global variables, functions and static variables, using #pragma directives.
This will provide a migration path towards clang for developers in the embedded
and automotive domain. For example, AUTOSAR, an automotive standard, mandates
the use of a #pragma in header files to determine in which sections initialized
and uninitialized data get put into.
This feature is implemented in our legacy ARM Compiler 5 toolchain and GCC forks
used across the automotive space that have this feature implemented compatible
with the ARM Compiler 5 implementation. The documentation is here:
The developer can specify section names as:
#pragma clang section bss="myBSS" data="myData" rodata="myRodata" text="myText"
The developer can "unspecify" a section name with empty string e.g.
#pragma clang section bss="" data="" text="" rodata=""
1. The pragma applies to all global variable, statics and function declarations
from the pragma to the end of the translation unit.
2. The pragma clang section is enabled automatically, without need of any flags.
3. This feature is only defined to work sensibly for ELF targets.
4. If section name is specified through _attribute_((section("myname"))), then
the attribute name gains precedence over any applicable section name via pragma directives.
5. Global variables, including - basic types, arrays, struct - that are initialized to zero
e.g. int x = 0; will be placed in the named bss section, if one is present.
6. The section type using '#pragma clang section' approach does not does NOT
try to infer section-kind from the name.
For example, assigning a section ".bss.mysec" does NOT mean it will be placed in BSS.
The decision about which section-kind applies to each global is not taken by this
implementation but is purely inquired from the default back-end implementation in LLVM.
Once the section-kind is known, appropriate section name as specified by the user
using pragma directive, is applied to that global.
Note that this is more effective approach than choosing the section name in the front-end
when optimisation passes have not been run and the final proper section is not known.
There is a llvm corresponding patch with this patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 21447 bytes
Desc: not available
More information about the cfe-commits