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

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 2 13:42:25 PST 2017


Would these pragmas be translation-unit global or could they be pushed and
popped like the MSVC pragmas?

If two TUs are combined through LTO, can the two TUs have different bss and
data sections?

If the answer to both is "no", then I think we should use a module flag
instead of manually setting the section from the frontend.

Here is a C++ example where, after optimization, a global may end up in
.bss instead of .data:
// c++
static int f() { return 0; }
static int x = f();
int *g() { return &x; }

After global opt we get this:
@_ZL1x = internal global i32 0, align 4

Normally LLVM will put this in .bss or use .lcomm for it. Your proposal
will put it in the user's data section instead of their bss section. If
that's important, we should use a module flag for this.

On Thu, Mar 2, 2017 at 11:35 AM, Javed Absar via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170302/55ece6de/attachment.html>


More information about the cfe-dev mailing list