[llvm-dev] proposal - pragma section directive in clang

Javed Absar via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 2 11:31:16 PST 2017


Hi all:

We would like to propose a clang pragma directive to allow specialized section names.
The semantics of it could be as follows. The pragma section name is declared in global
scope. All global variables and functions get assigned to the corresponding specialized
section name if one is present. With this feature, the following code:

// foo.c
#pragma bss_section(".bss.alpha")
#pragma data_section(".data.beta")
#pragma code_section(".code.gamma")
#pragma const_section(".const.delta")
int a;
int b=2;
const int d = 5;
int c(){
  return d;
}

..will emit llvm-ir as:

target triple = "armv7-arm-none-eabi"
@a = global i32 0, section ".bss.alpha", align 4
@b = global i32 2, section ".data.beta", align 4
@d = constant i32 5, section ".const.delta", align 4

; Function Attrs: noinline nounwind
define i32 @c() #0 section ".code.gamma" {
entry:
  ret i32 5
}

This pragma will be very useful for embedded code which
need to control where the different sections are placed in memory.

Microsoft -fms-extension provides similar feature, but our proposal is for a
general use.  Attributes are an alternative that is also currently available,
but attributes are applicable only to specific declarations and not entire
file. Many real embedded users prefer the pragma option.
This will be a welcome enabler for them. Also, AUTOSAR, which is an
automotive standard mandates use of a #pragma solution over an attribute one

Looking forward to comments and suggestions.
Best Regards
Javed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170302/43718d14/attachment.html>


More information about the llvm-dev mailing list