[lld] r221301 - [mach-o] remove __compact_unwind atoms once __unwind_info has been generated
Tim Northover
tnorthover at apple.com
Tue Nov 4 13:57:33 PST 2014
Author: tnorthover
Date: Tue Nov 4 15:57:32 2014
New Revision: 221301
URL: http://llvm.org/viewvc/llvm-project?rev=221301&view=rev
Log:
[mach-o] remove __compact_unwind atoms once __unwind_info has been generated
The job of the CompactUnwind pass is to turn __compact_unwind data (and
__eh_frame) into the compressed final form in __unwind_info. After it's done,
the original atoms are no longer relevant and should be deleted (they cause
problems during actual execution, quite apart from the fact that they're not
needed).
Modified:
lld/trunk/include/lld/Core/File.h
lld/trunk/include/lld/Core/Resolver.h
lld/trunk/include/lld/Core/Simple.h
lld/trunk/lib/Core/Resolver.cpp
lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/trunk/test/mach-o/unwind-info-simple-x86_64.yaml
lld/trunk/test/mach-o/write-final-sections.yaml
Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Tue Nov 4 15:57:32 2014
@@ -17,6 +17,7 @@
#include "lld/Core/UndefinedAtom.h"
#include "lld/Core/range.h"
#include "llvm/Support/ErrorHandling.h"
+#include <functional>
#include <vector>
namespace lld {
@@ -222,6 +223,9 @@ public:
typedef range<std::vector<const DefinedAtom *>::iterator> DefinedAtomRange;
virtual DefinedAtomRange definedAtoms() = 0;
+ virtual void
+ removeDefinedAtomsIf(std::function<bool(const DefinedAtom *)> pred) = 0;
+
protected:
/// \brief only subclasses of MutableFile can be instantiated
MutableFile(StringRef p) : File(p, kindObject) {}
Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Tue Nov 4 15:57:32 2014
@@ -89,8 +89,12 @@ private:
void addAtoms(std::vector<const Atom*>& atoms);
void addAtom(const Atom& atom) override;
+
DefinedAtomRange definedAtoms() override;
+ void removeDefinedAtomsIf(
+ std::function<bool(const DefinedAtom *)> pred) override;
+
private:
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Tue Nov 4 15:57:32 2014
@@ -40,6 +40,12 @@ public:
}
}
+ void removeDefinedAtomsIf(std::function<bool(const DefinedAtom *)> pred) {
+ auto &atoms = _definedAtoms._atoms;
+ auto newEnd = std::remove_if(atoms.begin(), atoms.end(), pred);
+ atoms.erase(newEnd, atoms.end());
+ }
+
const atom_collection<DefinedAtom> &defined() const override {
return _definedAtoms;
}
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Tue Nov 4 15:57:32 2014
@@ -445,6 +445,13 @@ MutableFile::DefinedAtomRange Resolver::
_definedAtoms._atoms.begin(), _definedAtoms._atoms.end());
}
+void Resolver::MergedFile::removeDefinedAtomsIf(
+ std::function<bool(const DefinedAtom *)> pred) {
+ auto &atoms = _definedAtoms._atoms;
+ auto newEnd = std::remove_if(atoms.begin(), atoms.end(), pred);
+ atoms.erase(newEnd, atoms.end());
+}
+
void Resolver::MergedFile::addAtoms(std::vector<const Atom *> &all) {
ScopedTask task(getDefaultDomain(), "addAtoms");
DEBUG_WITH_TYPE("resolver", llvm::dbgs() << "Resolver final atom list:\n");
Modified: lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/CompactUnwindPass.cpp Tue Nov 4 15:57:32 2014
@@ -337,11 +337,15 @@ private:
<< " has " << entriesInPage << " entries\n");
} while (pageStart < unwindInfos.size());
- // FIXME: we should also erase all compact-unwind atoms; their job is done.
UnwindInfoAtom *unwind = new (_file.allocator())
UnwindInfoAtom(_archHandler, _file, _isBig, std::vector<uint32_t>(),
personalities, pages, numLSDAs);
mergedFile->addAtom(*unwind);
+
+ // Finally, remove all __compact_unwind atoms now that we've processed them.
+ mergedFile->removeDefinedAtomsIf([](const DefinedAtom *atom) {
+ return atom->contentType() == DefinedAtom::typeCompactUnwindInfo;
+ });
}
void collectCompactUnwindEntries(
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Tue Nov 4 15:57:32 2014
@@ -231,12 +231,6 @@ const MachOFinalSectionFromAtomType sect
ENTRY("__DATA", "___got", S_NON_LAZY_SYMBOL_POINTERS,
typeGOT),
ENTRY("__DATA", "___bss", S_ZEROFILL, typeZeroFill),
-
- // FIXME: __compact_unwind actually needs to be processed by a pass and put
- // into __TEXT,__unwind_info. For now, forwarding it back to
- // __LD,__compact_unwind is harmless (it's ignored by the unwinder, which then
- // proceeds to process __TEXT,__eh_frame for its instructions).
- ENTRY("__LD", "__compact_unwind", S_REGULAR, typeCompactUnwindInfo),
};
#undef ENTRY
Modified: lld/trunk/test/mach-o/unwind-info-simple-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/unwind-info-simple-x86_64.yaml?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/test/mach-o/unwind-info-simple-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/unwind-info-simple-x86_64.yaml Tue Nov 4 15:57:32 2014
@@ -24,6 +24,7 @@
# CHECK: [2]: function offset=0x00000efd, encoding=0x04000018
# CHECK: [3]: function offset=0x00000efe, encoding=0x04000040
# CHECK: [4]: function offset=0x00000eff, encoding=0x00000000
+# CHECK-NOT: Contents of __compact_unwind section
--- !native
path: '<linker-internal>'
Modified: lld/trunk/test/mach-o/write-final-sections.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/write-final-sections.yaml?rev=221301&r1=221300&r2=221301&view=diff
==============================================================================
--- lld/trunk/test/mach-o/write-final-sections.yaml (original)
+++ lld/trunk/test/mach-o/write-final-sections.yaml Tue Nov 4 15:57:32 2014
@@ -140,17 +140,9 @@ defined-atoms:
# CHECK-NEXT: 0000: 0D000000 00000000
# CHECK-NEXT: )
-# FIXME: this should really end up in __TEXT,__unwind_info after being
-# processed. Most important fact here is that its presence doesn't trigger an
-# assert, but __LD,__compact_unwind is a harmless enough place to stash it.
-
- type: compact-unwind
content: [ 0E, 00, 00, 00, 00, 00, 00, 00 ]
-# CHECK: Name: __compact_unwind
-# CHECK: Segment: __LD
-# CHECK: SectionData (
-# CHECK-NEXT: 0000: 0E000000 00000000
-# CHECK-NEXT: )
+# CHECK-NOT: Name: __compact_unwind
--- !mach-o
More information about the llvm-commits
mailing list