<div dir="ltr">That does the trick. Thanks for the quick help, everyone!</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 4, 2017 at 6:18 PM, Keane, Erich <span dir="ltr"><<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="m_576234931840896357WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Elizabeth gave me a patch, submitted it with a test in r314939<u></u><u></u></span></p>
<p class="MsoNormal"><a name="m_576234931840896357__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"> Andrews, Elizabeth
<br>
<b>Sent:</b> Wednesday, October 4, 2017 1:54 PM<br>
<b>To:</b> Friedman, Eli <<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>>; Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>>; Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> RE: r314262 - Emit section information for extern variables.<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Alright. Will do. Thanks!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"> Friedman, Eli [<a href="mailto:efriedma@codeaurora.org" target="_blank">mailto:efriedma@codeaurora.<wbr>org</a>]
<br>
<b>Sent:</b> Wednesday, October 4, 2017 4:51 PM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>>; Andrews, Elizabeth <<a href="mailto:elizabeth.andrews@intel.com" target="_blank">elizabeth.andrews@intel.com</a>>; Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> Re: r314262 - Emit section information for extern variables.<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On 10/4/2017 1:48 PM, Keane, Erich wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Ah, cool!  I didn’t realize that, and that is actually exactly what Elizabeth is looking into now. 
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Elizabeth, if you send me a diff, I’ll commit it as review-after-commit if Eli is alright with this.  It should be something like changing:</span><u></u><u></u></p>
<p class="MsoNormal">+      if (VD-><wbr>isThisDeclarationADefinition() != VarDecl::Definition) {<u></u><u></u></p>
<p class="MsoNormal">To<u></u><u></u></p>
<p class="MsoNormal">+      if (VD-><wbr>isThisDeclarationADefinition() != VarDecl::Definition && VD-><wbr>isThsDeclarationADefinition() != VarDecl::TentativeDefinition) {<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Right?</span><u></u><u></u></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
I'd probably just write it "if (VD-><wbr>isThisDeclarationADefinition() == VarDecl::DeclarationOnly)", but yes.  (And don't forget a testcase.)<br>
<br>
-Eli<br>
<br>
<u></u><u></u></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"> Friedman, Eli [<a href="mailto:efriedma@codeaurora.org" target="_blank">mailto:efriedma@codeaurora.<wbr>org</a>]
<br>
<b>Sent:</b> Wednesday, October 4, 2017 1:46 PM<br>
<b>To:</b> Andrews, Elizabeth <a href="mailto:elizabeth.andrews@intel.com" target="_blank"><elizabeth.andrews@intel.com></a>; Nico Weber
<a href="mailto:thakis@chromium.org" target="_blank"><thakis@chromium.org></a><br>
<b>Cc:</b> cfe-commits <a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><cfe-commits@lists.llvm.org></a>; Keane, Erich
<a href="mailto:erich.keane@intel.com" target="_blank"><erich.keane@intel.com></a><br>
<b>Subject:</b> Re: r314262 - Emit section information for extern variables.</span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Oh, that's easy to explain; sorry, I didn't think of it when I was reviewing.<br>
<br>
DefinitionKind has three possible values: DeclarationOnly, TentativeDefinition, and Definition.  (Tentative definitions are C weirdness that allows you to write "int x; int x = 10;".)<br>
<br>
For the purpose of this warning, a TentativeDefinition should count as a definition.<br>
<br>
-Eli<br>
<br>
On 10/4/2017 1:38 PM, Andrews, Elizabeth wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hello,
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I just spoke to Erich. The warning isn’t supposed to be emitted when the section attribute is specified
 on a definition. I’m not sure why </span>struct r_debug _r_debug __attribute__((nocommon, section(".r_debug")));
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">failed the isThisDeclarationADefiniton check. I need to look into it.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Thanks,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Elizabeth</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a> [<a href="mailto:thakis@google.com" target="_blank">mailto:thakis@google.com</a>]
<b>On Behalf Of </b>Nico Weber<br>
<b>Sent:</b> Wednesday, October 4, 2017 4:29 PM<br>
<b>To:</b> Keane, Erich <a href="mailto:erich.keane@intel.com" target="_blank"><erich.keane@intel.com></a><br>
<b>Cc:</b> Andrews, Elizabeth <a href="mailto:elizabeth.andrews@intel.com" target="_blank"><elizabeth.andrews@intel.com></a>; Friedman, Eli
<a href="mailto:efriedma@codeaurora.org" target="_blank"><efriedma@codeaurora.org></a>; cfe-commits
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><cfe-commits@lists.llvm.org></a><br>
<b>Subject:</b> Re: r314262 - Emit section information for extern variables.</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">All I know about this code that it used to build (and still builds with gcc) and now it doesn't, sorry :-) What that code does seems somewhat questionable, but also somewhat useful, and it feels like the behavior change from this change
 here for that code might have been unintentional.<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Your suggestion sounds reasonable to me.<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Wed, Oct 4, 2017 at 4:18 PM, Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I saw that… I don’t see where it prevents the same change from being made in link.h.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">As I mentioned, there is a solution to make this Warning less aggressive (in the lib/Sema/SemaDecl.cpp
 changes, add a condition that Old->isUsed() before the warning.  I’m wondering if that solves your issue.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">It would result in
</span><u></u><u></u></p>
<p class="MsoNormal">extern struct r_debug _r_debug;<br>
struct r_debug _r_debug __attribute__((nocommon, section(".r_debug")));<u></u><u></u></p>
<p class="MsoNormal">Compiling, but :<u></u><u></u></p>
<p class="MsoNormal">extern struct r_debug _r_debug;<br>
r_debug = something();<br>
struct r_debug _r_debug __attribute__((nocommon, section(".r_debug")));<u></u><u></u></p>
<p class="MsoNormal">NOT compiling (which is almost definitely a bug).<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><a name="m_576234931840896357_m_-973596532105170196__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span></a><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
</span><a href="mailto:thakis@google.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">thakis@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> [mailto:</span><a href="mailto:thakis@google.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">thakis@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">]
<b>On Behalf Of </b>Nico Weber<br>
<b>Sent:</b> Wednesday, October 4, 2017 1:14 PM<br>
<b>To:</b> Keane, Erich <</span><a href="mailto:erich.keane@intel.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">erich.keane@intel.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Cc:</b> Andrews, Elizabeth <</span><a href="mailto:elizabeth.andrews@intel.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">elizabeth.andrews@intel.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">>;
 Friedman, Eli <</span><a href="mailto:efriedma@codeaurora.org" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">efriedma@codeaurora.org</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">>; cfe-commits
 <</span><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">cfe-commits@lists.llvm.org</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">></span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>Subject:</b> Re: r314262 - Emit section information for extern variables.<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">For why, here's the comment from the code I linked to:<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">/*<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * GDB looks for this symbol name when it cannot find PT_DYNAMIC->DT_DEBUG.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * We don't have a PT_DYNAMIC, so it will find this.  Now all we have to do<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * is arrange for this space to be filled in with the dynamic linker's<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * _r_debug contents after they're initialized.  That way, attaching GDB to<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * this process or examining its core file will find the PIE we loaded, the<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> * dynamic linker, and all the shared libraries, making debugging pleasant.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> */<u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Wed, Oct 4, 2017 at 4:11 PM, Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><a name="m_576234931840896357_m_-973596532105170196_m_-376296071852859"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I’ve added Elizabeth, who is the original patch
 author.  Hopefully she can help out here.  Additionally, Eli did the original review, so hopefully he can chime in as well.</span></a><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><br>
I believe the necessity for this warning came out of the discussion on fixing the section behavior.  The issue here is that redeclaring with a different ‘section’ can cause some pretty nasty issues, since it isn’t terribly clear what happens if the variable
 is used in the meantime.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">There is 1 change that I can think of that Elizabeth and I discussed, which was to only warn in the
 case where there was a USAGE between these two redeclarations.  I’m not sure that will allow na_cl to compile, however it is my belief that if there IS a usage between link.h:64 and nacl_bootstrap.c:434, that this is a bug in nacl that is simply being uncovered
 thanks to this new warning.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Is there a good/reasonable reason the source of nacl wants to redeclare this with a different ‘section’?</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
</span><a href="mailto:thakis@google.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">thakis@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> [mailto:</span><a href="mailto:thakis@google.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">thakis@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">]
<b>On Behalf Of </b>Nico Weber<br>
<b>Sent:</b> Wednesday, October 4, 2017 12:59 PM<br>
<b>To:</b> Keane, Erich <</span><a href="mailto:erich.keane@intel.com" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">erich.keane@intel.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Cc:</b> cfe-commits <</span><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">cfe-commits@lists.llvm.org</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Subject:</b> Re: r314262 - Emit section information for extern variables.</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hi Erich,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">this breaks existing code. NaCl does this:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">#include <link.h><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">struct r_debug _r_debug __attribute__((nocommon, section(".r_debug")));<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">(There's a lengthy-ish comment for why in
<a href="https://cs.chromium.org/chromium/src/native_client/src/trusted/service_runtime/linux/nacl_bootstrap.c?q=nacl_bootstrap.c&sq=package:chromium&dr&l=424" target="_blank">
https://cs.chromium.org/<wbr>chromium/src/native_client/<wbr>src/trusted/service_runtime/<wbr>linux/nacl_bootstrap.c?q=nacl_<wbr>bootstrap.c&sq=package:<wbr>chromium&dr&l=424</a>)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">link.h in e.g. the debian jessie sysroot says:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">extern struct r_debug _r_debug;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">After this change, clang complains:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">../../native_client/src/<wbr>trusted/service_runtime/linux/<wbr>nacl_bootstrap.c:434:16: error: section attribute is specified on redeclared variable [-Werror,-Wsection]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">struct r_debug _r_debug __attribute__((nocommon, section(".r_debug")));<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">               ^<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">../../build/linux/debian_<wbr>jessie_amd64-sysroot/usr/<wbr>include/link.h:67:23: note: previous declaration is here<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">extern struct r_debug _r_debug;<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">This code used to work in clang, and continues to work in gcc. So this patch probably isn't quite the right approach. Ideas?<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Tue, Sep 26, 2017 at 7:42 PM, Erich Keane via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal">Author: erichkeane<br>
Date: Tue Sep 26 16:42:34 2017<br>
New Revision: 314262<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=314262&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-<wbr>project?rev=314262&view=rev</a><br>
Log:<br>
Emit section information for extern variables.<br>
<br>
Currently, if _attribute_((section())) is used for extern variables,<br>
section information is not emitted in generated IR when the variables are used.<br>
This is expected since sections are not generated for external linkage objects.<br>
However NiosII requires this information as it uses special GP-relative accesses<br>
for any objects that use attribute section (.sdata). GCC keeps this attribute in<br>
  middle-end.<br>
<br>
This change emits the section information for all targets.<br>
<br>
Patch By: Elizabeth Andrews<br>
<br>
Differential Revision:<a href="https://reviews.llvm.org/D36487" target="_blank">https://reviews.llvm.<wbr>org/D36487</a><br>
<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
    cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
    cfe/trunk/test/Sema/attr-<wbr>section.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=314262&r1=314261&r2=314262&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/<wbr>DiagnosticSemaKinds.td?rev=<wbr>314262&r1=314261&r2=314262&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>DiagnosticSemaKinds.td Tue Sep 26 16:42:34 2017<br>
@@ -2620,6 +2620,8 @@ def err_attribute_section_invalid_<wbr>for_ta<br>
   "argument to 'section' attribute is not valid for this target: %0">;<br>
 def warn_mismatched_section : Warning<<br>
   "section does not match previous declaration">, InGroup<Section>;<br>
+def warn_attribute_section_on_<wbr>redeclaration : Warning<<br>
+  "section attribute is specified on redeclared variable">, InGroup<Section>;<br>
<br>
 def err_anonymous_property: Error<<br>
   "anonymous property is not supported">;<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=314262&r1=314261&r2=314262&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp?rev=314262&<wbr>r1=314261&r2=314262&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp Tue Sep 26 16:42:34 2017<br>
@@ -2432,6 +2432,12 @@ CodeGenModule::<wbr>GetOrCreateLLVMGlobal(Str<br>
       EmitGlobalVarDefinition(D);<br>
     }<br>
<br>
+    // Emit section information for extern variables.<br>
+    if (D->hasExternalStorage()) {<br>
+      if (const SectionAttr *SA = D->getAttr<SectionAttr>())<br>
+        GV->setSection(SA->getName());<br>
+    }<br>
+<br>
     // Handle XCore specific ABI requirements.<br>
     if (getTriple().getArch() == llvm::Triple::xcore &&<br>
         D->getLanguageLinkage() == CLanguageLinkage &&<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=314262&r1=314261&r2=314262&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=314262&r1=<wbr>314261&r2=314262&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Tue Sep 26 16:42:34 2017<br>
@@ -2607,6 +2607,16 @@ void Sema::mergeDeclAttributes(<wbr>NamedDecl<br>
     }<br>
   }<br>
<br>
+  // This redeclaration adds a section attribute.<br>
+  if (New->hasAttr<SectionAttr>() && !Old->hasAttr<SectionAttr>()) {<br>
+    if (auto *VD = dyn_cast<VarDecl>(New)) {<br>
+      if (VD-><wbr>isThisDeclarationADefinition() != VarDecl::Definition) {<br>
+        Diag(New->getLocation(), diag::warn_attribute_section_<wbr>on_redeclaration);<br>
+        Diag(Old->getLocation(), diag::note_previous_<wbr>declaration);<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
   if (!Old->hasAttrs())<br>
     return;<br>
<br>
<br>
Modified: cfe/trunk/test/Sema/attr-<wbr>section.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-section.c?rev=314262&r1=314261&r2=314262&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/Sema/<wbr>attr-section.c?rev=314262&r1=<wbr>314261&r2=314262&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/attr-<wbr>section.c (original)<br>
+++ cfe/trunk/test/Sema/attr-<wbr>section.c Tue Sep 26 16:42:34 2017<br>
@@ -19,3 +19,7 @@ void __attribute__((section("foo,<wbr>zed")))<br>
 void __attribute__((section("bar,<wbr>zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}<br>
<br>
 enum __attribute__((section("NEAR,<wbr>x"))) e { one }; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}<br>
+<br>
+extern int a; // expected-note {{previous declaration is here}}<br>
+int *b = &a;<br>
+extern int a __attribute__((section("foo,<wbr>zed"))); // expected-warning {{section attribute is specified on redeclared variable}}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</blockquote>
<p> <u></u><u></u></p>
<pre>-- <u></u><u></u></pre>
<pre>Employee of Qualcomm Innovation Center, Inc.<u></u><u></u></pre>
<pre>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<u></u><u></u></pre>
</blockquote>
<p><u></u> <u></u></p>
<pre>-- <u></u><u></u></pre>
<pre>Employee of Qualcomm Innovation Center, Inc.<u></u><u></u></pre>
<pre>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<u></u><u></u></pre>
</div></div></div>
</div>

</blockquote></div><br></div>