[PATCH] D17817: [ELF] do not allow .bss to occupy the file space when producing relocatable output.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 11:50:53 PST 2016


On Thu, Mar 3, 2016 at 11:32 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 2 March 2016 at 12:26, Rui Ueyama <ruiu at google.com> wrote:
> > ruiu added inline comments.
> >
> > ================
> > Comment at: ELF/Writer.cpp:1325
> > @@ -1324,1 +1324,3 @@
> > +      FileOff = alignTo(FileOff, Sec->getAlign());
> >      Sec->setFileOffset(FileOff);
> > +    if (Sec->getType() != SHT_NOBITS)
> > ----------------
> > Do you have to set file offsets to bss sections?
>
>
> The spec says:
>
> ----------------------------------------
> One section type, SHT_NOBITS described below, occupies no space in the
> file, and its sh_offset member locates the conceptual placement in the
> file.
> ----------------------------------------
>
> As far as I can tell every producer of .o files does it. I tested gas,
> llvm-mc, "ld.bfd -r" and "ld.gold -r", so I think we should set it
> too.


The spec is pretty much vague at this point -- it is not clear what "the
conceptual placement" means and what it should be.

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?

  for (OutputSectionBase<ELFT> *Sec : OutputSections) {
    FileOff = alignTo(FileOff, Sec->getAlign());
    Sec->setFileOffset(FileOff);
    FileOff += Sec->getSize();
  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160303/b2d52c85/attachment.html>


More information about the llvm-commits mailing list