From 7be81b2b4dadd87ad169419309a8da86f51a8ab0 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 22 Jun 2013 23:14:51 +0000 Subject: [PATCH] [PECOFF] Moves a utility function to Atoms.cpp to remove duplicate code. llvm-svn: 184653 --- lld/lib/ReaderWriter/PECOFF/Atoms.cpp | 22 +++++++++++++++++-- lld/lib/ReaderWriter/PECOFF/Atoms.h | 2 +- .../ReaderWriter/PECOFF/GroupedSectionsPass.h | 9 +------- lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp | 21 +----------------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.cpp b/lld/lib/ReaderWriter/PECOFF/Atoms.cpp index 13c58f7ee609..2fb1aa19aece 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(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 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 749dd970880a..5d20d2105873 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); /// 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 883dc823b29b..d29c71b5fc77 100644 --- a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h +++ b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h @@ -66,7 +66,7 @@ public: std::vector> 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 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 32f967e11ca8..86f0985f6cca 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 &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 &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()) -- 2.34.1