<div dir="ltr"><div>On Thu, Mar 3, 2016 at 11:32 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 2 March 2016 at 12:26, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> ruiu added inline comments.<br>
><br>
> ================<br>
> Comment at: ELF/Writer.cpp:1325<br>
> @@ -1324,1 +1324,3 @@<br>
> + FileOff = alignTo(FileOff, Sec->getAlign());<br>
> Sec->setFileOffset(FileOff);<br>
> + if (Sec->getType() != SHT_NOBITS)<br>
> ----------------<br>
> Do you have to set file offsets to bss sections?<br>
<br>
<br>
</span>The spec says:<br>
<br>
----------------------------------------<br>
One section type, SHT_NOBITS described below, occupies no space in the<br>
file, and its sh_offset member locates the conceptual placement in the<br>
file.<br>
----------------------------------------<br>
<br>
As far as I can tell every producer of .o files does it. I tested gas,<br>
llvm-mc, "ld.bfd -r" and "ld.gold -r", so I think we should set it<br>
too.</blockquote><div><br></div><div>The spec is pretty much vague at this point -- it is not clear what "the conceptual placement" means and what it should be.</div><div><br></div><div>That being said, I'm not entirely against setting a file offset to the bss section. But the two if's don't look good. It probably needs some explanation, but the explanation is that "bss section should point to its conceptual placement", which doesn't really explain the reason that much. So, how about this?</div><div><br></div><div><div> for (OutputSectionBase<ELFT> *Sec : OutputSections) {</div><div> FileOff = alignTo(FileOff, Sec->getAlign());</div><div> Sec->setFileOffset(FileOff);</div><div> FileOff += Sec->getSize();</div><div> }</div></div></div></div></div>