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