[Pass][Layout] Fix bug and add debug printing.

Fix a bug where if two atoms had the same index in the override map,
the compare would return false. It now goes to the next check when
they are equal.

No test because it currently can't be tested. An upcomming patch will test it.

llvm-svn: 176073
This commit is contained in:
Michael J. Spencer 2013-02-26 01:35:30 +00:00
parent c33b6ac7c9
commit 7f09a3d54e
1 changed files with 21 additions and 2 deletions

View File

@ -8,8 +8,12 @@
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "LayoutPass"
#include "lld/Passes/LayoutPass.h"
#include "llvm/Support/Debug.h"
using namespace lld;
/// The function compares atoms by sorting atoms in the following order
@ -21,15 +25,20 @@ using namespace lld;
/// f) Sorts atoms on how they appear within the File
bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
const DefinedAtom *right) {
DEBUG(llvm::dbgs() << "Sorting " << left->name() << " " << right->name() << "\n");
if (left == right)
return false;
DEBUG(llvm::dbgs() << "Sorting by perms\n");
// Sort same permissions together.
DefinedAtom::ContentPermissions leftPerms = left->permissions();
DefinedAtom::ContentPermissions rightPerms = right->permissions();
if (leftPerms != rightPerms)
return leftPerms < rightPerms;
DEBUG(llvm::dbgs() << "Sorting by contentType\n");
// Sort same content types together.
DefinedAtom::ContentType leftType = left->contentType();
DefinedAtom::ContentType rightType = right->contentType();
@ -38,6 +47,8 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
// TO DO: Sort atoms in customs sections together.
DEBUG(llvm::dbgs() << "Sorting by sectionPos\n");
// Sort by section position preference.
DefinedAtom::SectionPosition leftPos = left->sectionPosition();
DefinedAtom::SectionPosition rightPos = right->sectionPosition();
@ -48,12 +59,15 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
return leftPos < rightPos;
}
DEBUG(llvm::dbgs() << "Sorting by override\n");
AtomToOrdinalT::const_iterator lPos = _layout._ordinalOverrideMap.find(left);
AtomToOrdinalT::const_iterator rPos = _layout._ordinalOverrideMap.find(right);
AtomToOrdinalT::const_iterator end = _layout._ordinalOverrideMap.end();
if (lPos != end) {
if (rPos != end) {
// both left and right are overridden, so compare overridden ordinals
if (lPos->second != rPos->second)
return lPos->second < rPos->second;
} else {
// left is overridden and right is not, so left < right
@ -69,18 +83,24 @@ bool LayoutPass::CompareAtoms::operator()(const DefinedAtom *left,
}
}
DEBUG(llvm::dbgs() << "Sorting by .o order\n");
// Sort by .o order.
const File *leftFile = &left->file();
const File *rightFile = &right->file();
if (leftFile != rightFile)
return leftFile->ordinal() < rightFile->ordinal();
DEBUG(llvm::dbgs() << "Sorting by ordinal\n");
// Sort by atom order with .o file.
uint64_t leftOrdinal = left->ordinal();
uint64_t rightOrdinal = right->ordinal();
if (leftOrdinal != rightOrdinal)
return leftOrdinal < rightOrdinal;
DEBUG(llvm::dbgs() << "Unordered\n");
return false;
}
@ -366,7 +386,6 @@ void LayoutPass::buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range) {
/// Perform the actual pass
void LayoutPass::perform(MutableFile &mergedFile) {
MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
// Build follow on tables