<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello Bruno,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you for bringing up those points.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
On the first issue, clang indeed seems to be disregarding the initialization value of the variable when determining its section type.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The problem is related to the "PSF_ZeroInit" flag you mentioned. Clang is currently not taking the declaration's init value into consideration to flag its section as ZeroInit.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I'd need to take a deeper look into it to make sure it is safe to have the flag set in this scenario.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
There are multiple ways to define sections - clang pragmas, attributes, ms pragmas, etc - and the interactions between them might be a bit unclear sometimes.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regarding the mixing of different variable types into the same section, I'd say it might not be safe for all scenarios.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In fact, prior to those changes, clang was creating a single section when facing this, and defining the section type based only on the first variable declaration found after the pragma. Depending on the scatter file and target being used, this could cause RW
 variables to end up in RO memory.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Kind regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Lucas<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Bruno De Fraine <Bruno.DeFraine@synopsys.com><br>
<b>Sent:</b> Tuesday, June 9, 2020 1:05 PM<br>
<b>To:</b> Lucas Prates <Lucas.Prates@arm.com><br>
<b>Cc:</b> Jeroen Dobbelaere <Jeroen.Dobbelaere@synopsys.com>; clang Development List (cfe-dev@lists.llvm.org) <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Recent changes regarding section type conflicts and #pragma clang section</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
span.x_EmailStyle17
        {font-family:"Calibri",sans-serif;
        color:windowtext}
span.x_blob-code-inner
        {}
.x_MsoChpDefault
        {font-family:"Calibri",sans-serif}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="x_WordSection1">
<p class="x_MsoNormal">Hello Lucas,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">We observe two issues regarding your commits “[Clang][Sema] Capturing section type conflicts between #pragma clang section”:</p>
<p class="x_MsoNormal"><a href="https://github.com/llvm/llvm-project/commit/0dac639f285a53dffe3239ec5561fa0fc2da0daf">https://github.com/llvm/llvm-project/commit/0dac639f285a53dffe3239ec5561fa0fc2da0daf</a></p>
<p class="x_MsoNormal"><a href="https://github.com/llvm/llvm-project/commit/9d39df03a984ff4bed7d441a110d44976a8ab21b">https://github.com/llvm/llvm-project/commit/9d39df03a984ff4bed7d441a110d44976a8ab21b</a></p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">A first observation is that once a section has been used as bss argument in a #pragma clang section, it is no longer possible to use this section in an explicit section annotation on a variable, even if this variable is zero-initialized:</p>
<p class="x_MsoNormal"><a href="https://godbolt.org/z/oiNHk3">https://godbolt.org/z/oiNHk3</a></p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">[ In contrast, for a section used as the rodata argument, you *can* still do this, provided that the variable is “const”:</p>
<p class="x_MsoNormal"><a href="https://godbolt.org/z/wJvYiW">https://godbolt.org/z/wJvYiW</a> ]</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">The problem for bss sections seems to be related to the newly introduced “<span class="x_blob-code-inner">PSF_ZeroInit</span>” flag?</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">A second issue is that #pragma clang section provided a way to assign multiple variables to the same data section, mixing const, non-const and zero-initialized variables. When using an explicit section attribute, clang and gcc disallow
 to use the same section for const and non-const variables: <a href="https://godbolt.org/z/S76vKm">
https://godbolt.org/z/S76vKm</a> (but you can mix zero-initialized and non-zero-initialized variables)</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">An implicit section annotation using #pragma clang section allowed to work around this, by specifying the same data section in the pragma:</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">              #pragma clang section data=”mydata” bss=”mydata” rodata=”mydata”</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">This is an example using clang-10: <a href="https://godbolt.org/z/vxty7T">
https://godbolt.org/z/vxty7T</a></p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">This is now rejected, and granted, it was an abuse of the #pragma clang section. But is it not valid to assign both const and non-const variables to the same data section? Either with an explicit annotation or implicit?</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Regards,</p>
<p class="x_MsoNormal">Bruno De Fraine</p>
<p class="x_MsoNormal"> </p>
</div>
</div>
</body>
</html>