Use owning pointers instead of raw pointers for Atom's to fix leaks.
authorPete Cooper <peter_cooper@apple.com>
Tue, 22 Mar 2016 17:15:50 +0000 (17:15 +0000)
committerPete Cooper <peter_cooper@apple.com>
Tue, 22 Mar 2016 17:15:50 +0000 (17:15 +0000)
commit8ad55fb2d0f6cda53415c09ceb59dd06da16b21a
tree4d64d9d572254cdb97399c666d3e37c7da3eef23
parent7c31434ec3d41bb6198df89d3a902cd60be74b2e
Use owning pointers instead of raw pointers for Atom's to fix leaks.

This is a re-commit of r264022 with a fix for MSVC.  The issue there was
that the code was running DefinedAtom::~Atom() for some value and instead
needed to cast to Atom before running ~Atom.  Original commit message follows.

Currently each File contains an BumpPtrAllocator in which Atom's are
allocated.  Some Atom's contain data structures like std::vector which
leak as we don't run ~Atom when they are BumpPtrAllocate'd.

Now each File actually owns its Atom's using an OwningAtomPtr.  This
is analygous to std::unique_ptr and may be replaced by it if possible.

An Atom can therefore only be owned by a single File, so the Resolver now
moves them from one File to another.  The MachOLinkingContext owns the File's
and so clears all the Atom's in ~MachOLinkingContext, then delete's all the
File's.  This makes sure all Atom's have been destructed before any of the
BumpPtrAllocator's in which they run have gone away.

Should hopefully fix the remaining leaks.  Will keep an eye on the bots to
make sure.

llvm-svn: 264067
27 files changed:
lld/include/lld/Core/Atom.h
lld/include/lld/Core/DefinedAtom.h
lld/include/lld/Core/File.h
lld/include/lld/Core/Resolver.h
lld/include/lld/Core/SharedLibraryAtom.h
lld/include/lld/Core/SharedLibraryFile.h
lld/include/lld/Core/Simple.h
lld/include/lld/Core/UndefinedAtom.h
lld/lib/Core/File.cpp
lld/lib/Core/Resolver.cpp
lld/lib/Driver/DarwinLdDriver.cpp
lld/lib/ReaderWriter/FileArchive.cpp
lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
lld/lib/ReaderWriter/MachO/Atoms.h
lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp
lld/lib/ReaderWriter/MachO/ExecutableAtoms.h
lld/lib/ReaderWriter/MachO/File.h
lld/lib/ReaderWriter/MachO/FlatNamespaceFile.h
lld/lib/ReaderWriter/MachO/GOTPass.cpp
lld/lib/ReaderWriter/MachO/LayoutPass.cpp
lld/lib/ReaderWriter/MachO/LayoutPass.h
lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/lib/ReaderWriter/MachO/ObjCPass.cpp
lld/lib/ReaderWriter/MachO/SectCreateFile.h
lld/lib/ReaderWriter/MachO/StubsPass.cpp
lld/lib/ReaderWriter/MachO/TLVPass.cpp
lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp