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

There is a llvm corresponding patch with this patch.


https://reviews.llvm.org/D33412

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaAttr.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/clang-sections-tentative.c
  test/CodeGenCXX/clang-sections.cpp
  test/Sema/pragma-clang-section.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33412.99765.patch
Type: text/x-patch
Size: 21447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170522/8f9ea6c4/attachment-0001.bin>


More information about the cfe-commits mailing list