<div dir="ltr"><div>Hi Reid,</div><div><br></div><div>Thanks for your comments. In truth, we don't have a particular requirement for behaviour under LTO or pushability/poppability, so we can define this in terms of what's best for Clang.</div><div><br></div><div>As context is always useful, the goal of this proposed feature is to provide a migration path toward Clang for developers in the automotive domain. As Javed has mentioned, AUTOSAR which is an automotive standard, mandates the use of a #pragma in header files to determine in which sections initialized and uninitialized data get put.</div><div><br></div><div>This feature is implemented in our legacy ARM Compiler 5 toolchain and we're also aware of GCC forks used across the automotive space that have this feature implemented compatible with the ARM Compiler 5 implementation.</div><div><br></div><div>The documentation is here: <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472m/chr1359124985290.html">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472m/chr1359124985290.html</a></div><div><br></div><div>We do not aim for or anticipate syntax-level compatibility; merely the ability to do something similar in Clang. In particular Clang can't support the "section_type" specifier without significant rewrite, as LLVM decides the section type (NOBITS/PROGBITS) by textual matching on the section name (gross, but the fix is well beyond our scope).</div><div><br></div><div>Given that documentation, you can also see why the Microsoft compatibility option *almost* met our requirements - all except the behaviour in this case:</div><div><br></div><div>#pragma bss_seg('.bss.mybss')</div><div>int i; // Microsoft extension will put i in .bss.mybss</div><div>int j = 0; // Microsoft extension will put j in .data, whereas we really need it in .bss.mybss</div><div><br></div><div>So to specifically answer your questions:</div><div><br></div><div>In ARM Compiler 5, all pragmas are pushable and poppable. Clang doesn't have this feature generally yet, but when/if it does, I don't see why this pragma shouldn't be affected. So yes, we should consider it pushable and poppable.</div><div><br></div><div>I think the only reasonable behaviour under LTO must be that the two TUs (may) have different bss and data sections. Anything else would be very strange behaviour from the user's perspective.</div><div><br></div><div>Your example of a static global migrating from .data into .bss after optimization is interesting. With our proposal to explicitly name sections in IR, this optimization would be inhibited. I personally think that's fine :)</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 2 Mar 2017 at 21:42 Reid Kleckner via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Would these pragmas be translation-unit global or could they be pushed and popped like the MSVC pragmas?<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">If two TUs are combined through LTO, can the two TUs have different bss and data sections?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Here is a C++ example where, after optimization, a global may end up in .bss instead of .data:</div><div class="gmail_msg">// c++</div><div class="gmail_msg"><div class="gmail_msg">static int f() { return 0; }</div><div class="gmail_msg">static int x = f();</div><div class="gmail_msg">int *g() { return &x; }</div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">After global opt we get this:</div><div class="gmail_msg"><div class="gmail_msg">@_ZL1x = internal global i32 0, align 4</div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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.</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Thu, Mar 2, 2017 at 11:35 AM, Javed Absar via cfe-dev <span dir="ltr" class="gmail_msg"><<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-GB" link="#0563C1" vlink="#954F72" class="gmail_msg">
<div class="m_3187848934551112840m_3527854597707582817WordSection1 gmail_msg">
<p class="MsoNormal gmail_msg"><span style="color:black" class="gmail_msg">Hi all:<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="color:black" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="color:black" class="gmail_msg">We would like to propose a clang pragma directive to allow specialized section names.<br class="gmail_msg">
The semantics of it could be as follows. The pragma section name is declared in global<br class="gmail_msg">
scope. All global variables and functions get assigned to the corresponding specialized<br class="gmail_msg">
section name if one is present. With this feature, the following code:<br class="gmail_msg">
<br class="gmail_msg">
// foo.c<br class="gmail_msg">
#pragma bss_section(".bss.alpha")<br class="gmail_msg">
#pragma data_section(".data.beta")<br class="gmail_msg">
#pragma code_section(".code.gamma")<br class="gmail_msg">
#pragma const_section(".const.delta")<br class="gmail_msg">
int a;<br class="gmail_msg">
int b=2;<br class="gmail_msg">
const int d = 5;<br class="gmail_msg">
int c(){<br class="gmail_msg">
  return d;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
..will emit llvm-ir as:<br class="gmail_msg">
<br class="gmail_msg">
target triple = "armv7-arm-none-eabi"<br class="gmail_msg">
@a = global i32 0, section ".bss.alpha", align 4<br class="gmail_msg">
@b = global i32 2, section ".data.beta", align 4<br class="gmail_msg">
@d = constant i32 5, section ".const.delta", align 4<br class="gmail_msg">
<br class="gmail_msg">
; Function Attrs: noinline nounwind<br class="gmail_msg">
define i32 @c() #0 section ".code.gamma" {<br class="gmail_msg">
entry:<br class="gmail_msg">
  ret i32 5<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
This pragma will be very useful for embedded code which<br class="gmail_msg">
need to control where the different sections are placed in memory.<br class="gmail_msg">
<br class="gmail_msg">
Microsoft -fms-extension provides similar feature, but our proposal is for a <br class="gmail_msg">
general use.  Attributes are an alternative that is also currently available,<br class="gmail_msg">
but attributes are applicable only to specific declarations and not entire<br class="gmail_msg">
file. Many real embedded users prefer the pragma option.<br class="gmail_msg">
This will be a welcome enabler for them. Also, </span>AUTOSAR, which is an<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">automotive standard mandates use of a #pragma solution over an attribute one<span style="color:black" class="gmail_msg"><br class="gmail_msg">
<br class="gmail_msg">
Looking forward to comments and suggestions.<br class="gmail_msg">
</span>Best Regards<span class="m_3187848934551112840HOEnZb gmail_msg"><font color="#888888" class="gmail_msg"><u class="gmail_msg"></u><u class="gmail_msg"></u></font></span></p><span class="m_3187848934551112840HOEnZb gmail_msg"><font color="#888888" class="gmail_msg">
<p class="MsoNormal gmail_msg">Javed<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</font></span></div>
</div>

<br class="gmail_msg">_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div>