[lld] r176073 - [Pass][Layout] Fix bug and add debug printing.
Michael J. Spencer
bigcheesegs at gmail.com
Mon Feb 25 17:35:30 PST 2013
Author: mspencer
Date: Mon Feb 25 19:35:30 2013
New Revision: 176073
URL: http://llvm.org/viewvc/llvm-project?rev=176073&view=rev
Log:
[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.
Modified:
lld/trunk/lib/Passes/LayoutPass.cpp
Modified: lld/trunk/lib/Passes/LayoutPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/LayoutPass.cpp?rev=176073&r1=176072&r2=176073&view=diff
==============================================================================
--- lld/trunk/lib/Passes/LayoutPass.cpp (original)
+++ lld/trunk/lib/Passes/LayoutPass.cpp Mon Feb 25 19:35:30 2013
@@ -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(
// 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,13 +59,16 @@ bool LayoutPass::CompareAtoms::operator(
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
- return lPos->second < rPos->second;
+ if (lPos->second != rPos->second)
+ return lPos->second < rPos->second;
} else {
// left is overridden and right is not, so left < right
return true;
@@ -69,18 +83,24 @@ bool LayoutPass::CompareAtoms::operator(
}
}
+ 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
/// Perform the actual pass
void LayoutPass::perform(MutableFile &mergedFile) {
-
MutableFile::DefinedAtomRange atomRange = mergedFile.definedAtoms();
// Build follow on tables
More information about the llvm-commits
mailing list