Lang Hames | b1b67f4 | 2015-10-24 08:20:51 +0000 | [diff] [blame^] | 1 | //===---- lib/ReaderWriter/MachO/SectCreateFile.h ---------------*- c++ -*-===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H |
| 11 | #define LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H |
| 12 | |
| 13 | #include "lld/Core/DefinedAtom.h" |
| 14 | #include "lld/Core/Simple.h" |
| 15 | #include "lld/ReaderWriter/MachOLinkingContext.h" |
| 16 | |
| 17 | namespace lld { |
| 18 | namespace mach_o { |
| 19 | |
| 20 | // |
| 21 | // A FlateNamespaceFile instance may be added as a resolution source of last |
| 22 | // resort, depending on how -flat_namespace and -undefined are set. |
| 23 | // |
| 24 | class SectCreateFile : public File { |
| 25 | public: |
| 26 | |
| 27 | class SectCreateAtom : public SimpleDefinedAtom { |
| 28 | public: |
| 29 | SectCreateAtom(const File &file, StringRef segName, StringRef sectName, |
| 30 | std::unique_ptr<MemoryBuffer> content) |
| 31 | : SimpleDefinedAtom(file), |
| 32 | _combinedName((segName + "/" + sectName).str()), |
| 33 | _content(std::move(content)) {} |
| 34 | |
| 35 | uint64_t size() const override { return _content->getBufferSize(); } |
| 36 | |
| 37 | Scope scope() const override { return scopeGlobal; } |
| 38 | |
| 39 | ContentType contentType() const override { return typeSectCreate; } |
| 40 | |
| 41 | SectionChoice sectionChoice() const override { return sectionCustomRequired; } |
| 42 | |
| 43 | StringRef customSectionName() const override { return _combinedName; } |
| 44 | |
| 45 | DeadStripKind deadStrip() const override { return deadStripNever; } |
| 46 | |
| 47 | ArrayRef<uint8_t> rawContent() const override { |
| 48 | const uint8_t *data = |
| 49 | reinterpret_cast<const uint8_t*>(_content->getBufferStart()); |
| 50 | return ArrayRef<uint8_t>(data, _content->getBufferSize()); |
| 51 | } |
| 52 | |
| 53 | StringRef segmentName() const { return _segName; } |
| 54 | StringRef sectionName() const { return _sectName; } |
| 55 | |
| 56 | private: |
| 57 | std::string _combinedName; |
| 58 | StringRef _segName; |
| 59 | StringRef _sectName; |
| 60 | std::unique_ptr<MemoryBuffer> _content; |
| 61 | }; |
| 62 | |
| 63 | SectCreateFile() : File("sectcreate", kindObject) {} |
| 64 | |
| 65 | void addSection(StringRef seg, StringRef sect, |
| 66 | std::unique_ptr<MemoryBuffer> content) { |
| 67 | _definedAtoms.push_back( |
| 68 | new (allocator()) SectCreateAtom(*this, seg, sect, std::move(content))); |
| 69 | } |
| 70 | |
| 71 | const AtomVector<DefinedAtom> &defined() const { |
| 72 | return _definedAtoms; |
| 73 | } |
| 74 | |
| 75 | const AtomVector<UndefinedAtom> &undefined() const { |
| 76 | return _noUndefinedAtoms; |
| 77 | } |
| 78 | |
| 79 | const AtomVector<SharedLibraryAtom> &sharedLibrary() const { |
| 80 | return _noSharedLibraryAtoms; |
| 81 | } |
| 82 | |
| 83 | const AtomVector<AbsoluteAtom> &absolute() const { |
| 84 | return _noAbsoluteAtoms; |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | AtomVector<DefinedAtom> _definedAtoms; |
| 89 | }; |
| 90 | |
| 91 | } // namespace mach_o |
| 92 | } // namespace lld |
| 93 | |
| 94 | #endif // LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H |