summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/ReaderWriter/PECOFF/Atoms.cpp22
-rw-r--r--lld/lib/ReaderWriter/PECOFF/Atoms.h2
-rw-r--r--lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h9
-rw-r--r--lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp21
4 files changed, 23 insertions, 31 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.cpp b/lld/lib/ReaderWriter/PECOFF/Atoms.cpp
index 13c58f7ee60..2fb1aa19aec 100644
--- a/lld/lib/ReaderWriter/PECOFF/Atoms.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/Atoms.cpp
@@ -19,12 +19,30 @@ void addEdge(COFFDefinedAtom *a, COFFDefinedAtom *b,
ref->setTarget(b);
a->addReference(std::unique_ptr<COFFReference>(ref));
}
-}
-void connectAtomsWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b) {
+void connectWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b) {
addEdge(a, b, lld::Reference::kindLayoutAfter);
addEdge(b, a, lld::Reference::kindLayoutBefore);
}
+} // anonymous namespace
+
+/// Connect atoms with layout-{before,after} edges. It usually serves two
+/// purposes.
+///
+/// - To prevent atoms from being GC'ed (aka dead-stripped) if there is a
+/// reference to one of the atoms. In that case we want to emit all the
+/// atoms appeared in the same section, because the referenced "live" atom
+/// may reference other atoms in the same section. If we don't add layout
+/// edges between atoms, unreferenced atoms in the same section would be
+/// GC'ed.
+/// - To preserve the order of atmos. We want to emit the atoms in the
+/// same order as they appeared in the input object file.
+void connectAtomsWithLayoutEdge(std::vector<COFFDefinedAtom *> atoms) {
+ if (atoms.size() < 2)
+ return;
+ for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)
+ connectWithLayoutEdge(*it, *(it + 1));
+}
} // namespace coff
} // namespace lld
diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.h b/lld/lib/ReaderWriter/PECOFF/Atoms.h
index 749dd970880..5d20d210587 100644
--- a/lld/lib/ReaderWriter/PECOFF/Atoms.h
+++ b/lld/lib/ReaderWriter/PECOFF/Atoms.h
@@ -21,7 +21,7 @@ using llvm::object::COFFObjectFile;
using llvm::object::coff_section;
using llvm::object::coff_symbol;
-void connectAtomsWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b);
+void connectAtomsWithLayoutEdge(std::vector<COFFDefinedAtom *>);
/// A COFFReference represents relocation information for an atom. For
/// example, if atom X has a reference to atom Y with offsetInAtom=8, that
diff --git a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
index 883dc823b29..d29c71b5fc7 100644
--- a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
+++ b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
@@ -66,7 +66,7 @@ public:
std::vector<std::vector<COFFDefinedAtom *>> groupedAtomsList(
groupBySectionName(sectionToHeadAtoms));
for (auto &groupedAtoms : groupedAtomsList)
- connectAtoms(groupedAtoms);
+ connectAtomsWithLayoutEdge(groupedAtoms);
}
private:
@@ -107,13 +107,6 @@ private:
vec.push_back(std::move(i.second));
return std::move(vec);
}
-
- void connectAtoms(std::vector<COFFDefinedAtom *> atoms) const {
- if (atoms.size() < 2)
- return;
- for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)
- connectAtomsWithLayoutEdge(*it, *(it + 1));
- }
};
} // namespace pecoff
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
index 32f967e11ca..86f0985f6cc 100644
--- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
@@ -227,25 +227,6 @@ private:
return error_code::success();
}
- /// Connect atoms appeared in the same section with layout-{before,after}
- /// edges. It has two purposes.
- ///
- /// - To prevent atoms from being GC'ed (aka dead-stripped) if there is a
- /// reference to one of the atoms. In that case we want to emit all the
- /// atoms appeared in the same section, because the referenced "live"
- /// atom may reference other atoms in the same section. If we don't add
- /// edges between atoms, unreferenced atoms in the same section would be
- /// GC'ed.
- /// - To preserve the order of atmos. We want to emit the atoms in the
- /// same order as they appeared in the input object file.
- void addLayoutEdges(vector<COFFDefinedAtom *> &definedAtoms) const {
- if (definedAtoms.size() <= 1)
- return;
- for (auto it = definedAtoms.begin(), e = definedAtoms.end(); it + 1 != e;
- ++it)
- connectAtomsWithLayoutEdge(*it, *(it + 1));
- }
-
error_code AtomizeDefinedSymbols(SectionToSymbolsT &definedSymbols,
vector<const DefinedAtom *> &definedAtoms,
SymbolNameToAtomT &symbolToAtom,
@@ -261,7 +242,7 @@ private:
return ec;
// Connect atoms with layout-before/layout-after edges.
- addLayoutEdges(atoms);
+ connectAtomsWithLayoutEdge(atoms);
for (COFFDefinedAtom *atom : atoms) {
if (!atom->name().empty())
OpenPOWER on IntegriCloud