#include "lld/Core/UndefinedAtom.h"
#include "lld/Core/range.h"
#include "llvm/Support/ErrorHandling.h"
+#include <functional>
#include <vector>
namespace lld {
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) {}
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;
}
}
+ 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;
}
_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");
<< " 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(
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
# 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>'
# 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