[PATCH] D33413: Add support for #pragma clang section

Javed Absar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 08:34:06 PDT 2017


javed.absar created this revision.
Herald added subscribers: emaste, aemerson.

This is the corresponding llvm part for the clang patch https://reviews.llvm.org/D33412 that is also under review.

This patch adds support for a '#pragma clang section' directive in clang. An RFC was sent out earlier by my colleague James Molloy: http://lists.llvm.org/pipermail/cfe-dev/2017-March/053100.html

Purpose: 
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 initialised 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:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472m/chr1359124985290.html

User-Visible Behavior:
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.

Design:
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.


https://reviews.llvm.org/D33413

Files:
  include/llvm/IR/GlobalVariable.h
  lib/CodeGen/GlobalMerge.cpp
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  lib/Target/TargetLoweringObjectFile.cpp
  test/CodeGen/ARM/clang-section.ll
  test/MC/ELF/clang-section.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33413.99769.patch
Type: text/x-patch
Size: 18759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170522/7a967b31/attachment-0001.bin>


More information about the llvm-commits mailing list