From b7ec8ae2ab27524dd7c49e201c56b8007b940958 Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Fri, 5 Dec 2014 22:03:26 +0000 Subject: [PATCH] [mach-o] Switch MachOFile and MachODylibFile to use BumpPtr in lld::File llvm-svn: 223529 --- lld/lib/ReaderWriter/MachO/File.h | 52 ++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h index fff6ef8..9f3979b 100644 --- a/lld/lib/ReaderWriter/MachO/File.h +++ b/lld/lib/ReaderWriter/MachO/File.h @@ -36,15 +36,15 @@ public: contentSize); if (copyRefs) { // Make a copy of the atom's name and content that is owned by this file. - name = name.copy(_allocator); - content = content.copy(_allocator); + name = name.copy(allocator()); + content = content.copy(allocator()); } DefinedAtom::Alignment align( inSection->alignment, sectionOffset % ((uint64_t)1 << inSection->alignment)); MachODefinedAtom *atom = - new (_allocator) MachODefinedAtom(*this, name, scope, type, merge, - thumb, noDeadStrip, content, align); + new (allocator()) MachODefinedAtom(*this, name, scope, type, merge, + thumb, noDeadStrip, content, align); addAtomForSection(inSection, atom, sectionOffset); } @@ -58,15 +58,15 @@ public: contentSize); if (copyRefs) { // Make a copy of the atom's name and content that is owned by this file. - name = name.copy(_allocator); - content = content.copy(_allocator); - sectionName = sectionName.copy(_allocator); + name = name.copy(allocator()); + content = content.copy(allocator()); + sectionName = sectionName.copy(allocator()); } DefinedAtom::Alignment align( inSection->alignment, sectionOffset % ((uint64_t)1 << inSection->alignment)); MachODefinedCustomSectionAtom *atom = - new (_allocator) MachODefinedCustomSectionAtom(*this, name, scope, type, + new (allocator()) MachODefinedCustomSectionAtom(*this, name, scope, type, merge, thumb, noDeadStrip, content, sectionName, align); @@ -79,24 +79,24 @@ public: const Section *inSection) { if (copyRefs) { // Make a copy of the atom's name and content that is owned by this file. - name = name.copy(_allocator); + name = name.copy(allocator()); } DefinedAtom::Alignment align( inSection->alignment, sectionOffset % ((uint64_t)1 << inSection->alignment)); MachODefinedAtom *atom = - new (_allocator) MachODefinedAtom(*this, name, scope, size, noDeadStrip, - align); + new (allocator()) MachODefinedAtom(*this, name, scope, size, noDeadStrip, + align); addAtomForSection(inSection, atom, sectionOffset); } void addUndefinedAtom(StringRef name, bool copyRefs) { if (copyRefs) { // Make a copy of the atom's name that is owned by this file. - name = name.copy(_allocator); + name = name.copy(allocator()); } SimpleUndefinedAtom *atom = - new (_allocator) SimpleUndefinedAtom(*this, name); + new (allocator()) SimpleUndefinedAtom(*this, name); addAtom(*atom); _undefAtoms[name] = atom; } @@ -105,10 +105,10 @@ public: DefinedAtom::Alignment align, bool copyRefs) { if (copyRefs) { // Make a copy of the atom's name that is owned by this file. - name = name.copy(_allocator); + name = name.copy(allocator()); } MachOTentativeDefAtom *atom = - new (_allocator) MachOTentativeDefAtom(*this, name, scope, size, align); + new (allocator()) MachOTentativeDefAtom(*this, name, scope, size, align); addAtom(*atom); _undefAtoms[name] = atom; } @@ -172,7 +172,6 @@ public: visitor(offAndAtom.atom, offAndAtom.offset); } - llvm::BumpPtrAllocator &allocator() { return _allocator; } private: struct SectionOffsetAndAtom { uint64_t offset; MachODefinedAtom *atom; }; @@ -191,7 +190,6 @@ private: std::vector> SectionToAtoms; typedef llvm::StringMap NameToAtom; - llvm::BumpPtrAllocator _allocator; SectionToAtoms _sectionAtoms; NameToAtom _undefAtoms; }; @@ -204,13 +202,12 @@ public: _currentVersion(currentVersion), _compatVersion(compatVersion) { } - const SharedLibraryAtom *exports(StringRef name, - bool isData) const override { - // Pass down _installName and _allocator so that if this requested symbol + const SharedLibraryAtom *exports(StringRef name, bool isData) const override { + // Pass down _installName so that if this requested symbol // is re-exported through this dylib, the SharedLibraryAtom's loadName() // is this dylib installName and not the implementation dylib's. // NOTE: isData is not needed for dylibs (it matters for static libs). - return exports(name, _installName, _allocator); + return exports(name, _installName); } const atom_collection &defined() const override { @@ -233,7 +230,7 @@ public: /// SharedLibraryAtom is created lazily (since most symbols are not used). void addExportedSymbol(StringRef name, bool weakDef, bool copyRefs) { if (copyRefs) { - name = name.copy(_allocator); + name = name.copy(allocator()); } AtomAndFlags info(weakDef); _nameToAtom[name] = info; @@ -258,16 +255,16 @@ public: } private: - const SharedLibraryAtom *exports(StringRef name, StringRef installName, - llvm::BumpPtrAllocator &allocator) const { + const SharedLibraryAtom *exports(StringRef name, + StringRef installName) const { // First, check if requested symbol is directly implemented by this dylib. auto entry = _nameToAtom.find(name); if (entry != _nameToAtom.end()) { if (!entry->second.atom) { // Lazily create SharedLibraryAtom. entry->second.atom = - new (allocator) MachOSharedLibraryAtom(*this, name, installName, - entry->second.weakDef); + new (allocator()) MachOSharedLibraryAtom(*this, name, installName, + entry->second.weakDef); } return entry->second.atom; } @@ -275,7 +272,7 @@ private: // Next, check if symbol is implemented in some re-exported dylib. for (const ReExportedDylib &dylib : _reExportedDylibs) { assert(dylib.file); - auto atom = dylib.file->exports(name, installName, allocator); + auto atom = dylib.file->exports(name, installName); if (atom) return atom; } @@ -307,7 +304,6 @@ private: atom_collection_vector _absoluteAtoms; std::vector _reExportedDylibs; mutable std::unordered_map _nameToAtom; - mutable llvm::BumpPtrAllocator _allocator; }; } // end namespace mach_o -- 2.7.4