summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/File.h
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/File.h')
-rw-r--r--lld/lib/ReaderWriter/MachO/File.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/File.h b/lld/lib/ReaderWriter/MachO/File.h
index 0101350cdaf..d50e3ff0a61 100644
--- a/lld/lib/ReaderWriter/MachO/File.h
+++ b/lld/lib/ReaderWriter/MachO/File.h
@@ -15,6 +15,9 @@
#include "Atoms.h"
#include "lld/Core/Simple.h"
+#include "lld/Core/SharedLibraryFile.h"
+
+#include <unordered_map>
namespace lld {
namespace mach_o {
@@ -156,7 +159,60 @@ private:
NameToAtom _undefAtoms;
};
+class MachODylibFile : public SharedLibraryFile {
+public:
+ MachODylibFile(StringRef path) : SharedLibraryFile(path), _dylib_name(path) {}
+
+ virtual const SharedLibraryAtom *exports(StringRef name,
+ bool dataSymbolOnly) const {
+ // FIXME: we obviously need to record code/data if we're going to make
+ // proper use of dataSymbolOnly.
+ auto sym = _nameToAtom.find(name);
+
+ if (sym == _nameToAtom.end())
+ return nullptr;
+
+ if (!sym->second)
+ sym->second =
+ new (_allocator) MachOSharedLibraryAtom(*this, name, _dylib_name);
+
+ return sym->second;
+ }
+
+ const atom_collection<DefinedAtom> &defined() const override {
+ return _definedAtoms;
+ }
+
+ const atom_collection<UndefinedAtom> &undefined() const override {
+ return _undefinedAtoms;
+ }
+
+ const atom_collection<SharedLibraryAtom> &sharedLibrary() const override {
+ return _sharedLibraryAtoms;
+ }
+
+ const atom_collection<AbsoluteAtom> &absolute() const override {
+ return _absoluteAtoms;
+ }
+
+ void addSharedLibraryAtom(StringRef name, bool copyRefs) {
+ if (copyRefs) {
+ name = name.copy(_allocator);
+ }
+
+ _nameToAtom[name] = nullptr;
+ }
+private:
+ StringRef _dylib_name;
+ atom_collection_vector<DefinedAtom> _definedAtoms;
+ atom_collection_vector<UndefinedAtom> _undefinedAtoms;
+ atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+
+ mutable std::unordered_map<StringRef, SharedLibraryAtom *> _nameToAtom;
+ mutable llvm::BumpPtrAllocator _allocator;
+};
} // end namespace mach_o
} // end namespace lld
OpenPOWER on IntegriCloud