[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).

llvm-svn: 250190
This commit is contained in:
Hal Finkel 2015-10-13 17:57:46 +00:00
parent ed2146d235
commit 0d7e83bbc4
1 changed files with 3 additions and 2 deletions

View File

@ -312,13 +312,14 @@ static bool compareOutputSections(OutputSectionBase<ELFT::Is64Bits> *A,
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;
return getPPC64SectionRank(A->getName()) < getPPC64SectionRank(B->getName());