From f98b1c99603d7da0e7d3700e446fe864506294f8 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 4 Nov 2014 21:57:32 +0000 Subject: [PATCH] [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). llvm-svn: 221301 --- lld/include/lld/Core/File.h | 4 ++++ lld/include/lld/Core/Resolver.h | 4 ++++ lld/include/lld/Core/Simple.h | 6 ++++++ lld/lib/Core/Resolver.cpp | 7 +++++++ lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp | 6 +++++- lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | 6 ------ lld/test/mach-o/unwind-info-simple-x86_64.yaml | 1 + lld/test/mach-o/write-final-sections.yaml | 10 +--------- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index 2e9dbaa..8ab4452 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -17,6 +17,7 @@ #include "lld/Core/UndefinedAtom.h" #include "lld/Core/range.h" #include "llvm/Support/ErrorHandling.h" +#include #include namespace lld { @@ -222,6 +223,9 @@ public: typedef range::iterator> DefinedAtomRange; virtual DefinedAtomRange definedAtoms() = 0; + virtual void + removeDefinedAtomsIf(std::function pred) = 0; + protected: /// \brief only subclasses of MutableFile can be instantiated MutableFile(StringRef p) : File(p, kindObject) {} diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index 64f962e..e001b49 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -89,8 +89,12 @@ private: void addAtoms(std::vector& atoms); void addAtom(const Atom& atom) override; + DefinedAtomRange definedAtoms() override; + void removeDefinedAtomsIf( + std::function pred) override; + private: atom_collection_vector _definedAtoms; atom_collection_vector _undefinedAtoms; diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h index ee29f5b..a8282d1 100644 --- a/lld/include/lld/Core/Simple.h +++ b/lld/include/lld/Core/Simple.h @@ -40,6 +40,12 @@ public: } } + void removeDefinedAtomsIf(std::function pred) { + auto &atoms = _definedAtoms._atoms; + auto newEnd = std::remove_if(atoms.begin(), atoms.end(), pred); + atoms.erase(newEnd, atoms.end()); + } + const atom_collection &defined() const override { return _definedAtoms; } diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 1657866..e4a1b53 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -445,6 +445,13 @@ MutableFile::DefinedAtomRange Resolver::MergedFile::definedAtoms() { _definedAtoms._atoms.begin(), _definedAtoms._atoms.end()); } +void Resolver::MergedFile::removeDefinedAtomsIf( + std::function 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 &all) { ScopedTask task(getDefaultDomain(), "addAtoms"); DEBUG_WITH_TYPE("resolver", llvm::dbgs() << "Resolver final atom list:\n"); diff --git a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp index f440ced..9280ec4 100644 --- a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp +++ b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp @@ -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(), 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( diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 4a4ba79..dc015c5 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -231,12 +231,6 @@ const MachOFinalSectionFromAtomType sectsToAtomType[] = { 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 diff --git a/lld/test/mach-o/unwind-info-simple-x86_64.yaml b/lld/test/mach-o/unwind-info-simple-x86_64.yaml index 2c42ada..8886e52 100644 --- a/lld/test/mach-o/unwind-info-simple-x86_64.yaml +++ b/lld/test/mach-o/unwind-info-simple-x86_64.yaml @@ -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: '' diff --git a/lld/test/mach-o/write-final-sections.yaml b/lld/test/mach-o/write-final-sections.yaml index 8701f40..b8b8cc6 100644 --- a/lld/test/mach-o/write-final-sections.yaml +++ b/lld/test/mach-o/write-final-sections.yaml @@ -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 -- 2.7.4