summaryrefslogtreecommitdiffstats
path: root/lld/lib/Core/SymbolTable.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-03-04 21:40:46 +0000
committerRui Ueyama <ruiu@google.com>2015-03-04 21:40:46 +0000
commit77a4da19914c84e07a82dc22bbbf28540f90ca31 (patch)
treed8e42d1a0196e871b33467a3c329b0704ea501e7 /lld/lib/Core/SymbolTable.cpp
parent00fb6c9da0b8f9ed6b46f8c71a0f7c73bda177f2 (diff)
downloadbcm5719-llvm-77a4da19914c84e07a82dc22bbbf28540f90ca31.tar.gz
bcm5719-llvm-77a4da19914c84e07a82dc22bbbf28540f90ca31.zip
Define DefinedAtom::sectionSize.
Merge::mergeByLargestSection is half-baked since it's defined in terms of section size, there's no way to get the section size of an atom. Currently we work around the issue by traversing the layout edges to both directions and calculate the sum of all atoms reachable. I wrote that code but I knew it's hacky. It's even not guaranteed to work. If you add layout edges before the core linking, it miscalculates a size. Also it's of course slow. It's basically a linked list traversal. In this patch I added DefinedAtom::sectionSize so that we can use that for mergeByLargestSection. I'm not very happy to add a new field to DefinedAtom base class, but I think it's legitimate since mergeByLargestSection is defined for section size, and the section size is currently just missing. http://reviews.llvm.org/D7966 llvm-svn: 231290
Diffstat (limited to 'lld/lib/Core/SymbolTable.cpp')
-rw-r--r--lld/lib/Core/SymbolTable.cpp38
1 files changed, 4 insertions, 34 deletions
diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp
index b06cdec472f..d264cb78d95 100644
--- a/lld/lib/Core/SymbolTable.cpp
+++ b/lld/lib/Core/SymbolTable.cpp
@@ -133,36 +133,6 @@ static MergeResolution mergeSelect(DefinedAtom::Merge first,
return mergeCases[first][second];
}
-static const DefinedAtom *followReference(const DefinedAtom *atom,
- uint32_t kind) {
- for (const Reference *r : *atom)
- if (r->kindNamespace() == Reference::KindNamespace::all &&
- r->kindArch() == Reference::KindArch::all &&
- r->kindValue() == kind)
- return cast<const DefinedAtom>(r->target());
- return nullptr;
-}
-
-static uint64_t getSizeFollowReferences(const DefinedAtom *atom,
- uint32_t kind) {
- uint64_t size = 0;
- for (;;) {
- atom = followReference(atom, kind);
- if (!atom)
- return size;
- size += atom->size();
- }
-}
-
-// Returns the size of the section containing the given atom. Atoms in the same
-// section are connected by layout-before and layout-after edges, so this
-// function traverses them to get the total size of atoms in the same section.
-static uint64_t sectionSize(const DefinedAtom *atom) {
- return atom->size()
- + getSizeFollowReferences(atom, lld::Reference::kindLayoutBefore)
- + getSizeFollowReferences(atom, lld::Reference::kindLayoutAfter);
-}
-
bool SymbolTable::addByName(const Atom &newAtom) {
StringRef name = newAtom.name();
assert(!name.empty());
@@ -198,14 +168,14 @@ bool SymbolTable::addByName(const Atom &newAtom) {
useNew = true;
break;
case MCR_Largest: {
- uint64_t existingSize = sectionSize(existingDef);
- uint64_t newSize = sectionSize(newDef);
+ uint64_t existingSize = existingDef->sectionSize();
+ uint64_t newSize = newDef->sectionSize();
useNew = (newSize >= existingSize);
break;
}
case MCR_SameSize: {
- uint64_t existingSize = sectionSize(existingDef);
- uint64_t newSize = sectionSize(newDef);
+ uint64_t existingSize = existingDef->sectionSize();
+ uint64_t newSize = newDef->sectionSize();
if (existingSize == newSize) {
useNew = true;
break;
OpenPOWER on IntegriCloud