[lld] r250190 - [ELF2] Ensure strict weak ordering in section sorting (v2)

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 11:05:01 PDT 2015


On Tue, Oct 13, 2015 at 10:57 AM, Hal Finkel via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: hfinkel
> Date: Tue Oct 13 12:57:46 2015
> New Revision: 250190
>
> URL: http://llvm.org/viewvc/llvm-project?rev=250190&view=rev
> Log:
> [ELF2] Ensure strict weak ordering in section sorting (v2)
>
> The fix in r250109 to ensure a strict weak ordering in the section sorting
> was
> a bit overzealous. We only use the NOBITS comparison if either A or B is a
> NOBITS section. Otherwise, we fall through to the target-specific ranking
> function. Failure to do this causes the sorting to fail in cases where, for
> example, a .dynamic section happens to end up in between .got and .toc,
> etc. in
> the initial ordering (.dynamic has a type SHT_DYNAMIC, compared to
> SHT_PROGBITS
> or SHT_NOBITS).
>
> Modified:
>     lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250190&r1=250189&r2=250190&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Tue Oct 13 12:57:46 2015
> @@ -312,13 +312,14 @@ static bool compareOutputSections(Output
>    if (AIsExec != BIsExec)
>      return BIsExec;
>
> -  // If we got here we know that both A and B and in the same PT_LOAD.
> +  // If we got here we know that both A and B are in the same PT_LOAD.
>    // The last requirement we have is to put nobits section last. The
>    // reason is that the only thing the dynamic linker will see about
>    // them is a p_memsz that is larger than p_filesz. Seeing that it
>    // zeros the end of the PT_LOAD, so that has to correspond to the
>    // nobits sections.
> -  if (A->getType() != B->getType())
> +  if ((A->getType() == SHT_NOBITS || B->getType() == SHT_NOBITS) &&
> +      A->getType() != B->getType())
>      return A->getType() != SHT_NOBITS && B->getType() == SHT_NOBITS;
>

If A != B, and both A and B are either X or !X, then

  return A != X && B == X;

and

  return A != X;

are the same.


>
>    return getPPC64SectionRank(A->getName()) <
> getPPC64SectionRank(B->getName());
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151013/cb283c12/attachment.html>


More information about the llvm-commits mailing list