<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p id="reply-intro">On 2020-09-16 00:18, Fangrui Song wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"><span style="white-space: nowrap;">Usually it is because nobody has noticed the problem or nobody is</span><br /><span style="white-space: nowrap;">motivated enough to fix the problems, not that they intentionally leave</span><br /><span style="white-space: nowrap;">a problem open:) I took some time to look at the problem and conclude</span><br /><span style="white-space: nowrap;">that clang should do nothing on this. Actually, with the clang behavior,</span><br /><span style="white-space: nowrap;">you can discard "Unused" if you use LLD. Read on.</span></div>
</blockquote>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"><span style="font-family: verdana, geneva, sans-serif;">Sorry if I misspoke, I was not suggesting that the bug was known and voluntary not fixed by laziness ;-). I am sure there is a valid reason and wanted to know about it. Just like you explained, it appears that LLVM rely on LLD to do that instead of enforcing it in the middle-end which is a different approach to GCC.</span></div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"><span style="white-space: nowrap;">In GCC, -O turns on -fmerge-constants. Clang does not implement this</span><br /><span style="white-space: nowrap;">option, but implement the level 2 -fmerge-all-constants, which is non-conforming ("Languages like C or C++</span><br /><span style="white-space: nowrap;">require each variable, including multiple instances of the same variable</span><br /><span style="white-space: nowrap;">in recursive calls, to have distinct locations, so using this option</span><br /><span style="white-space: nowrap;">results in non-conforming behavior.").</span></div>
</blockquote>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"><span style="font-family: verdana, geneva, sans-serif;">Non-confirming in the sense of C/C++ standard? How is it related to the -fdata-sections implementation?</span></div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"><span style="white-space: nowrap;">With (-fmerge-constants or -fmerge-all-constants) & -fdata-sections, string literals are placed in .rodata.xxx.str1.1</span><br /><span style="white-space: nowrap;"><a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192#c16" target="_blank" rel="noopener noreferrer">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192#c16</a></span><br /><span style="white-space: nowrap;">This is, however, suboptimal because the cost of a section header</span><br /><span style="white-space: nowrap;">(sizeof(Elf64_Shdr)=64) + a section name (".rodata.xxx.str1.1") is quite large.</span><br /><span style="white-space: nowrap;">I have replied on <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192#c19" target="_blank" rel="noopener noreferrer">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=192#c19</a> and</span><br /><span style="white-space: nowrap;">created a GNU ld feature request</span><br /><span style="white-space: nowrap;">(<a href="https://sourceware.org/bugzilla/show_bug.cgi?id=26622" target="_blank" rel="noopener noreferrer">https://sourceware.org/bugzilla/show_bug.cgi?id=26622</a>)</span></div>
</blockquote>
<p>In my example, LLVM/Clang already put both pointer "test" and "unused" in different data section because of "-fdata-sections" as seen below.</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p class="p1"><strong><span class="Apple-converted-space">        </span>; Segment unnamed segment<br /></strong><strong><span class="Apple-converted-space">        </span>; Range: [0x5c; 0x64[ (8 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; File offset : [144; 152[ (8 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; Permissions:<span class="Apple-converted-space">  </span>- </strong></p>
<p class="p1"><strong><span class="Apple-converted-space">        </span>; Section .data.test<br /></strong><strong><span class="Apple-converted-space">        </span>; Range: [0x5c; 0x60[ (4 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; File offset : [144; 148[ (4 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; Flags: 0x3<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHT_PROGBITS<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHF_WRITE<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHF_ALLOC</strong></p>
<p class="p3"><span class="Apple-converted-space">             </span><span class="s1">test</span>:</p>
<p class="p3"><span class="s2">0000005c</span> <span class="Apple-converted-space">        </span><strong>dd</strong> <span class="Apple-converted-space">        </span><span class="s2">0x00000063</span></p>
<p class="p1"><strong><span class="Apple-converted-space">        </span>; Section .data.unused<br /></strong><strong><span class="Apple-converted-space">        </span>; Range: [0x60; 0x64[ (4 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; File offset : [148; 153[ (4 bytes)<br /></strong><strong><span class="Apple-converted-space">        </span>; Flags: 0x3<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHT_PROGBITS<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHF_WRITE<br /></strong><strong><span class="Apple-converted-space">        </span>; <span class="Apple-converted-space">  </span>SHF_ALLOC</strong></p>
<p class="p3"><span class="Apple-converted-space">             </span><span class="s1">unused</span>:</p>
<p class="p3"><span class="s2">00000060</span> <span class="Apple-converted-space">        </span><strong>dw</strong> <span class="Apple-converted-space">       <span class="s2">0x00000070</span></span></p>
</blockquote>
<p><span style="font-family: verdana, geneva, sans-serif;">So I am not sure to understand the point about sub-optimality here since it is already the case for the .data section where each variable imply a suboptimal cost in term of section header. How the c-string like datas are different ? I mean, the concept of -fdata-section/-ffunction-section ("one section for each data/functions") should be the same for every kind of data, no? </span></p>

</body></html>