[lld] r202079 - [lld] Include reference kind in cycle detector debug output
Nico Rieck
nico.rieck at gmail.com
Mon Feb 24 13:14:38 PST 2014
Author: nrieck
Date: Mon Feb 24 15:14:37 2014
New Revision: 202079
URL: http://llvm.org/viewvc/llvm-project?rev=202079&view=rev
Log:
[lld] Include reference kind in cycle detector debug output
This restores the debug output to how it was before r197727 broke it. This
went undetected because the corresponding test was never run due to broken
feature detection.
Modified:
lld/trunk/include/lld/Passes/LayoutPass.h
lld/trunk/lib/Passes/LayoutPass.cpp
lld/trunk/lib/ReaderWriter/CoreLinkingContext.cpp
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
lld/trunk/test/core/layout-error-test.objtxt
Modified: lld/trunk/include/lld/Passes/LayoutPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Passes/LayoutPass.h?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/include/lld/Passes/LayoutPass.h (original)
+++ lld/trunk/include/lld/Passes/LayoutPass.h Mon Feb 24 15:14:37 2014
@@ -12,6 +12,7 @@
#include "lld/Core/File.h"
#include "lld/Core/Pass.h"
+#include "lld/ReaderWriter/Reader.h"
#include "llvm/ADT/DenseMap.h"
@@ -38,6 +39,8 @@ public:
uint64_t _override;
};
+ LayoutPass(const Registry ®istry);
+
/// Sorts atoms in mergedFile by content type then by command line order.
virtual void perform(std::unique_ptr<MutableFile> &mergedFile);
@@ -59,6 +62,8 @@ private:
// Build a map of Atoms to ordinals for sorting the atoms
void buildOrdinalOverrideMap(MutableFile::DefinedAtomRange &range);
+ const Registry &_registry;
+
typedef llvm::DenseMap<const DefinedAtom *, const DefinedAtom *> AtomToAtomT;
typedef llvm::DenseMap<const DefinedAtom *, uint64_t> AtomToOrdinalT;
Modified: lld/trunk/lib/Passes/LayoutPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/LayoutPass.cpp?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/lib/Passes/LayoutPass.cpp (original)
+++ lld/trunk/lib/Passes/LayoutPass.cpp Mon Feb 24 15:14:37 2014
@@ -63,14 +63,21 @@ static std::string atomToDebugString(con
return str;
}
-static void showCycleDetectedError(AtomToAtomT &followOnNexts,
+static void showCycleDetectedError(const Registry ®istry,
+ AtomToAtomT &followOnNexts,
const DefinedAtom *atom) {
const DefinedAtom *start = atom;
llvm::dbgs() << "There's a cycle in a follow-on chain!\n";
do {
llvm::dbgs() << " " << atomToDebugString(atom) << "\n";
for (const Reference *ref : *atom) {
- llvm::dbgs() << " " << atomToDebugString(ref->target()) << "\n";
+ StringRef kindValStr;
+ if (!registry.referenceKindToString(ref->kindNamespace(), ref->kindArch(),
+ ref->kindValue(), kindValStr)) {
+ kindValStr = "<unknown>";
+ }
+ llvm::dbgs() << " " << kindValStr
+ << ": " << atomToDebugString(ref->target()) << "\n";
}
atom = followOnNexts[atom];
} while (atom != start);
@@ -80,7 +87,8 @@ static void showCycleDetectedError(AtomT
/// Exit if there's a cycle in a followon chain reachable from the
/// given root atom. Uses the tortoise and hare algorithm to detect a
/// cycle.
-static void checkNoCycleInFollowonChain(AtomToAtomT &followOnNexts,
+static void checkNoCycleInFollowonChain(const Registry ®istry,
+ AtomToAtomT &followOnNexts,
const DefinedAtom *root) {
const DefinedAtom *tortoise = root;
const DefinedAtom *hare = followOnNexts[root];
@@ -88,7 +96,7 @@ static void checkNoCycleInFollowonChain(
if (!tortoise || !hare)
return;
if (tortoise == hare)
- showCycleDetectedError(followOnNexts, tortoise);
+ showCycleDetectedError(registry, followOnNexts, tortoise);
tortoise = followOnNexts[tortoise];
hare = followOnNexts[followOnNexts[hare]];
}
@@ -138,7 +146,7 @@ void LayoutPass::checkFollowonChain(Muta
for (const auto &ai : _followOnRoots)
roots.insert(ai.second);
for (const DefinedAtom *root : roots)
- checkNoCycleInFollowonChain(_followOnNexts, root);
+ checkNoCycleInFollowonChain(_registry, _followOnNexts, root);
// Verify that all the atoms in followOnNexts have references to
// their roots.
@@ -247,6 +255,8 @@ static bool compareAtoms(const LayoutPas
return result;
}
+LayoutPass::LayoutPass(const Registry ®istry) : _registry(registry) {}
+
// Returns the atom immediately followed by the given atom in the followon
// chain.
const DefinedAtom *LayoutPass::findAtomFollowedBy(
Modified: lld/trunk/lib/ReaderWriter/CoreLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/CoreLinkingContext.cpp?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/CoreLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/CoreLinkingContext.cpp Mon Feb 24 15:14:37 2014
@@ -262,7 +262,7 @@ bool CoreLinkingContext::validateImpl(ra
void CoreLinkingContext::addPasses(PassManager &pm) {
for (StringRef name : _passNames) {
if (name.equals("layout"))
- pm.add(std::unique_ptr<Pass>((new LayoutPass())));
+ pm.add(std::unique_ptr<Pass>(new LayoutPass(registry())));
else if (name.equals("GOT"))
pm.add(std::unique_ptr<Pass>(new TestingGOTPass(*this)));
else if (name.equals("stubs"))
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Mon Feb 24 15:14:37 2014
@@ -54,7 +54,7 @@ bool ELFLinkingContext::isLittleEndian()
void ELFLinkingContext::addPasses(PassManager &pm) {
if (_runLayoutPass)
- pm.add(std::unique_ptr<Pass>(new LayoutPass()));
+ pm.add(std::unique_ptr<Pass>(new LayoutPass(registry())));
pm.add(std::unique_ptr<Pass>(new elf::ArrayOrderPass()));
}
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Mon Feb 24 15:14:37 2014
@@ -295,7 +295,7 @@ void MachOLinkingContext::addPasses(Pass
pm.add(std::unique_ptr<Pass>(new mach_o::GOTPass));
pm.add(std::unique_ptr<Pass>(new mach_o::StubsPass(*this)));
}
- pm.add(std::unique_ptr<Pass>(new LayoutPass()));
+ pm.add(std::unique_ptr<Pass>(new LayoutPass(registry())));
}
Writer &MachOLinkingContext::writer() const {
Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Mon Feb 24 15:14:37 2014
@@ -262,7 +262,7 @@ void PECOFFLinkingContext::addPasses(Pas
pm.add(std::unique_ptr<Pass>(new pecoff::SetSubsystemPass(*this)));
pm.add(std::unique_ptr<Pass>(new pecoff::EdataPass(*this)));
pm.add(std::unique_ptr<Pass>(new pecoff::IdataPass(*this)));
- pm.add(std::unique_ptr<Pass>(new LayoutPass()));
+ pm.add(std::unique_ptr<Pass>(new LayoutPass(registry())));
pm.add(std::unique_ptr<Pass>(new pecoff::GroupedSectionsPass()));
}
Modified: lld/trunk/test/core/layout-error-test.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/core/layout-error-test.objtxt?rev=202079&r1=202078&r2=202079&view=diff
==============================================================================
--- lld/trunk/test/core/layout-error-test.objtxt (original)
+++ lld/trunk/test/core/layout-error-test.objtxt Mon Feb 24 15:14:37 2014
@@ -2,9 +2,6 @@
# RUN: not lld -core --add-pass layout -mllvm -debug-only=LayoutPass \
# RUN: %s 2> %t.err
# RUN: FileCheck %s -check-prefix=CHECK < %t.err
-# FIXME: This test broke because it was never run, and lld's debug output is
-# now missing the kind of the references.
-# XFAIL: *
---
defined-atoms:
More information about the llvm-commits
mailing list