1 //===- Core/SharedLibraryFile.h - Models shared libraries as Atoms --------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLD_CORE_SHARED_LIBRARY_FILE_H 10 #define LLD_CORE_SHARED_LIBRARY_FILE_H 11 12 #include "lld/Core/File.h" 13 14 namespace lld { 15 16 /// 17 /// The SharedLibraryFile subclass of File is used to represent dynamic 18 /// shared libraries being linked against. 19 /// 20 class SharedLibraryFile : public File { 21 public: classof(const File * f)22 static bool classof(const File *f) { 23 return f->kind() == kindSharedLibrary; 24 } 25 26 /// Check if the shared library exports a symbol with the specified name. 27 /// If so, return a SharedLibraryAtom which represents that exported 28 /// symbol. Otherwise return nullptr. 29 virtual OwningAtomPtr<SharedLibraryAtom> exports(StringRef name) const = 0; 30 31 // Returns the install name. 32 virtual StringRef getDSOName() const = 0; 33 defined()34 const AtomRange<DefinedAtom> defined() const override { 35 return _definedAtoms; 36 } 37 undefined()38 const AtomRange<UndefinedAtom> undefined() const override { 39 return _undefinedAtoms; 40 } 41 sharedLibrary()42 const AtomRange<SharedLibraryAtom> sharedLibrary() const override { 43 return _sharedLibraryAtoms; 44 } 45 absolute()46 const AtomRange<AbsoluteAtom> absolute() const override { 47 return _absoluteAtoms; 48 } 49 clearAtoms()50 void clearAtoms() override { 51 _definedAtoms.clear(); 52 _undefinedAtoms.clear(); 53 _sharedLibraryAtoms.clear(); 54 _absoluteAtoms.clear(); 55 } 56 57 protected: 58 /// only subclasses of SharedLibraryFile can be instantiated SharedLibraryFile(StringRef path)59 explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {} 60 61 AtomVector<DefinedAtom> _definedAtoms; 62 AtomVector<UndefinedAtom> _undefinedAtoms; 63 AtomVector<SharedLibraryAtom> _sharedLibraryAtoms; 64 AtomVector<AbsoluteAtom> _absoluteAtoms; 65 }; 66 67 } // namespace lld 68 69 #endif // LLD_CORE_SHARED_LIBRARY_FILE_H 70