Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1 | //===- lib/ReaderWriter/Native/ReaderNative.cpp ---------------------------===// |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 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 | |
Michael J. Spencer | 64afcb4 | 2013-01-23 01:18:43 +0000 | [diff] [blame] | 10 | #include "lld/ReaderWriter/Reader.h" |
Rui Ueyama | e5416ec | 2013-09-12 19:14:05 +0000 | [diff] [blame] | 11 | #include "lld/ReaderWriter/Simple.h" |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 12 | |
Michael J. Spencer | cfd029f | 2012-03-28 19:04:02 +0000 | [diff] [blame] | 13 | #include "lld/Core/Atom.h" |
| 14 | #include "lld/Core/Error.h" |
| 15 | #include "lld/Core/File.h" |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 16 | |
| 17 | #include "llvm/ADT/ArrayRef.h" |
| 18 | #include "llvm/ADT/OwningPtr.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Format.h" |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | |
| 26 | #include "NativeFileFormat.h" |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 27 | |
Michael J. Spencer | cfd029f | 2012-03-28 19:04:02 +0000 | [diff] [blame] | 28 | #include <vector> |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 29 | #include <memory> |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 30 | |
| 31 | namespace lld { |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 32 | namespace native { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 33 | |
| 34 | // forward reference |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 35 | class File; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 36 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 37 | // |
| 38 | // An object of this class is instantied for each NativeDefinedAtomIvarsV1 |
| 39 | // struct in the NCS_DefinedAtomsV1 chunk. |
| 40 | // |
| 41 | class NativeDefinedAtomV1 : public DefinedAtom { |
| 42 | public: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 43 | NativeDefinedAtomV1(const File& f, |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 44 | const NativeDefinedAtomIvarsV1* ivarData) |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 45 | : _file(&f), _ivarData(ivarData) { } |
| 46 | |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 47 | virtual const lld::File& file() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 48 | |
| 49 | virtual uint64_t ordinal() const; |
| 50 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 51 | virtual StringRef name() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 52 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 53 | virtual uint64_t size() const { |
| 54 | return _ivarData->contentSize; |
| 55 | } |
| 56 | |
| 57 | virtual DefinedAtom::Scope scope() const { |
| 58 | return (DefinedAtom::Scope)(attributes().scope); |
| 59 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 60 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 61 | virtual DefinedAtom::Interposable interposable() const { |
| 62 | return (DefinedAtom::Interposable)(attributes().interposable); |
| 63 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 64 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 65 | virtual DefinedAtom::Merge merge() const { |
| 66 | return (DefinedAtom::Merge)(attributes().merge); |
| 67 | } |
| 68 | |
| 69 | virtual DefinedAtom::ContentType contentType() const { |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 70 | const NativeAtomAttributesV1& attr = attributes(); |
| 71 | return (DefinedAtom::ContentType)(attr.contentType); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 72 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 73 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 74 | virtual DefinedAtom::Alignment alignment() const { |
| 75 | return DefinedAtom::Alignment(attributes().align2, attributes().alignModulus); |
| 76 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 77 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 78 | virtual DefinedAtom::SectionChoice sectionChoice() const { |
Nick Kledzik | 36293f6 | 2013-01-23 22:32:56 +0000 | [diff] [blame] | 79 | return (DefinedAtom::SectionChoice)( |
| 80 | attributes().sectionChoiceAndPosition >> 4); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 83 | virtual StringRef customSectionName() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 84 | |
Nick Kledzik | 36293f6 | 2013-01-23 22:32:56 +0000 | [diff] [blame] | 85 | virtual SectionPosition sectionPosition() const { |
| 86 | return (DefinedAtom::SectionPosition)( |
| 87 | attributes().sectionChoiceAndPosition & 0xF); |
| 88 | } |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 89 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 90 | virtual DefinedAtom::DeadStripKind deadStrip() const { |
| 91 | return (DefinedAtom::DeadStripKind)(attributes().deadStrip); |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 92 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 93 | |
Michael J. Spencer | b8ab9f5 | 2013-11-08 21:04:20 +0000 | [diff] [blame] | 94 | virtual DynamicExport dynamicExport() const { |
| 95 | return (DynamicExport)attributes().dynamicExport; |
| 96 | } |
| 97 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 98 | virtual DefinedAtom::ContentPermissions permissions() const { |
| 99 | return (DefinedAtom::ContentPermissions)(attributes().permissions); |
| 100 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 101 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 102 | virtual bool isAlias() const { |
| 103 | return (attributes().alias != 0); |
| 104 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 105 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 106 | virtual ArrayRef<uint8_t> rawContent() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 107 | |
Nick Kledzik | 062a98c | 2012-04-08 23:52:13 +0000 | [diff] [blame] | 108 | virtual reference_iterator begin() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 109 | |
Nick Kledzik | 062a98c | 2012-04-08 23:52:13 +0000 | [diff] [blame] | 110 | virtual reference_iterator end() const; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 111 | |
| 112 | virtual const Reference* derefIterator(const void*) const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 113 | |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 114 | virtual void incrementIterator(const void*& it) const; |
| 115 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 116 | private: |
| 117 | const NativeAtomAttributesV1& attributes() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 118 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 119 | const File *_file; |
| 120 | const NativeDefinedAtomIvarsV1 *_ivarData; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | |
| 124 | |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 125 | // |
| 126 | // An object of this class is instantied for each NativeUndefinedAtomIvarsV1 |
| 127 | // struct in the NCS_UndefinedAtomsV1 chunk. |
| 128 | // |
| 129 | class NativeUndefinedAtomV1 : public UndefinedAtom { |
| 130 | public: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 131 | NativeUndefinedAtomV1(const File& f, |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 132 | const NativeUndefinedAtomIvarsV1* ivarData) |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 133 | : _file(&f), _ivarData(ivarData) { } |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 134 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 135 | virtual const lld::File& file() const; |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 136 | virtual StringRef name() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 137 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 138 | virtual CanBeNull canBeNull() const { |
| 139 | return (CanBeNull)(_ivarData->flags & 0x3); |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 140 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 141 | |
Rui Ueyama | e5416ec | 2013-09-12 19:14:05 +0000 | [diff] [blame] | 142 | virtual const UndefinedAtom *fallback() const; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 143 | |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 144 | private: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 145 | const File *_file; |
| 146 | const NativeUndefinedAtomIvarsV1 *_ivarData; |
Rui Ueyama | e5416ec | 2013-09-12 19:14:05 +0000 | [diff] [blame] | 147 | mutable std::unique_ptr<const SimpleUndefinedAtom> _fallback; |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 151 | // |
| 152 | // An object of this class is instantied for each NativeUndefinedAtomIvarsV1 |
| 153 | // struct in the NCS_SharedLibraryAtomsV1 chunk. |
| 154 | // |
| 155 | class NativeSharedLibraryAtomV1 : public SharedLibraryAtom { |
| 156 | public: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 157 | NativeSharedLibraryAtomV1(const File& f, |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 158 | const NativeSharedLibraryAtomIvarsV1* ivarData) |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 159 | : _file(&f), _ivarData(ivarData) { } |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 160 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 161 | virtual const lld::File& file() const; |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 162 | virtual StringRef name() const; |
| 163 | virtual StringRef loadName() const; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 164 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 165 | virtual bool canBeNullAtRuntime() const { |
| 166 | return (_ivarData->flags & 0x1); |
| 167 | } |
| 168 | |
Michael J. Spencer | 4355bb9 | 2013-09-26 22:08:43 +0000 | [diff] [blame] | 169 | virtual Type type() const { |
| 170 | return (Type)_ivarData->type; |
| 171 | } |
| 172 | |
| 173 | virtual uint64_t size() const { |
| 174 | return _ivarData->size; |
| 175 | } |
| 176 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 177 | private: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 178 | const File *_file; |
| 179 | const NativeSharedLibraryAtomIvarsV1 *_ivarData; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | |
| 183 | // |
| 184 | // An object of this class is instantied for each NativeAbsoluteAtomIvarsV1 |
| 185 | // struct in the NCS_AbsoluteAtomsV1 chunk. |
| 186 | // |
| 187 | class NativeAbsoluteAtomV1 : public AbsoluteAtom { |
| 188 | public: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 189 | NativeAbsoluteAtomV1(const File& f, |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 190 | const NativeAbsoluteAtomIvarsV1* ivarData) |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 191 | : _file(&f), _ivarData(ivarData) { } |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 192 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 193 | virtual const lld::File& file() const; |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 194 | virtual StringRef name() const; |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 195 | virtual Scope scope() const { |
| 196 | const NativeAtomAttributesV1& attr = absAttributes(); |
| 197 | return (Scope)(attr.scope); |
| 198 | } |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 199 | virtual uint64_t value() const { |
| 200 | return _ivarData->value; |
| 201 | } |
| 202 | |
| 203 | private: |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 204 | const NativeAtomAttributesV1& absAttributes() const; |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 205 | const File *_file; |
| 206 | const NativeAbsoluteAtomIvarsV1 *_ivarData; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 210 | // |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 211 | // An object of this class is instantied for each NativeReferenceIvarsV1 |
| 212 | // struct in the NCS_ReferencesArrayV1 chunk. |
| 213 | // |
| 214 | class NativeReferenceV1 : public Reference { |
| 215 | public: |
Michael J. Spencer | fa40527 | 2013-03-20 18:57:52 +0000 | [diff] [blame] | 216 | NativeReferenceV1(const File& f, const NativeReferenceIvarsV1* ivarData) |
| 217 | : _file(&f), _ivarData(ivarData) { |
| 218 | setKind(ivarData->kind); |
| 219 | } |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 220 | |
| 221 | virtual uint64_t offsetInAtom() const { |
| 222 | return _ivarData->offsetInAtom; |
| 223 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 224 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 225 | virtual const Atom* target() const; |
| 226 | virtual Addend addend() const; |
| 227 | virtual void setTarget(const Atom* newAtom); |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 228 | virtual void setAddend(Addend a); |
Nick Kledzik | f4e2c73 | 2012-03-15 23:36:24 +0000 | [diff] [blame] | 229 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 230 | private: |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 231 | const File *_file; |
| 232 | const NativeReferenceIvarsV1 *_ivarData; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 236 | // |
| 237 | // An object of this class is instantied for each NativeReferenceIvarsV1 |
| 238 | // struct in the NCS_ReferencesArrayV1 chunk. |
| 239 | // |
| 240 | class NativeReferenceV2 : public Reference { |
| 241 | public: |
| 242 | NativeReferenceV2(const File& f, const NativeReferenceIvarsV2* ivarData) |
| 243 | : _file(&f), _ivarData(ivarData) { |
| 244 | setKind(ivarData->kind); |
| 245 | } |
| 246 | |
| 247 | virtual uint64_t offsetInAtom() const { |
| 248 | return _ivarData->offsetInAtom; |
| 249 | } |
| 250 | |
| 251 | virtual const Atom* target() const; |
| 252 | virtual Addend addend() const; |
| 253 | virtual void setTarget(const Atom* newAtom); |
| 254 | virtual void setAddend(Addend a); |
| 255 | |
| 256 | private: |
| 257 | const File *_file; |
| 258 | const NativeReferenceIvarsV2 *_ivarData; |
| 259 | }; |
| 260 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 261 | |
| 262 | // |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 263 | // lld::File object for native llvm object file |
| 264 | // |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 265 | class File : public lld::File { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 266 | public: |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 267 | |
| 268 | /// Instantiates a File object from a native object file. Ownership |
| 269 | /// of the MemoryBuffer is transfered to the resulting File object. |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 270 | static error_code make(const LinkingContext &context, |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 271 | std::unique_ptr<MemoryBuffer> mb, |
| 272 | std::vector<std::unique_ptr<lld::File> > &result) { |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 273 | const uint8_t *const base = |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 274 | reinterpret_cast<const uint8_t *>(mb->getBufferStart()); |
| 275 | StringRef path(mb->getBufferIdentifier()); |
| 276 | const NativeFileHeader *const header = |
| 277 | reinterpret_cast<const NativeFileHeader *>(base); |
Michael J. Spencer | b2bd733 | 2012-01-31 21:45:53 +0000 | [diff] [blame] | 278 | const NativeChunk *const chunks = |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 279 | reinterpret_cast<const NativeChunk *>(base + sizeof(NativeFileHeader)); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 280 | // make sure magic matches |
Rui Ueyama | a3ada6b | 2013-11-16 01:31:24 +0000 | [diff] [blame] | 281 | if (memcmp(header->magic, NATIVE_FILE_HEADER_MAGIC, |
| 282 | sizeof(header->magic)) != 0) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 283 | return make_error_code(NativeReaderError::unknown_file_format); |
Michael J. Spencer | 7aba895 | 2012-01-31 21:47:13 +0000 | [diff] [blame] | 284 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 285 | // make sure mapped file contains all needed data |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 286 | const size_t fileSize = mb->getBufferSize(); |
| 287 | if (header->fileSize > fileSize) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 288 | return make_error_code(NativeReaderError::file_too_short); |
Michael J. Spencer | 7aba895 | 2012-01-31 21:47:13 +0000 | [diff] [blame] | 289 | |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 290 | DEBUG_WITH_TYPE("ReaderNative", |
| 291 | llvm::dbgs() << " Native File Header:" << " fileSize=" |
| 292 | << header->fileSize << " chunkCount=" |
| 293 | << header->chunkCount << "\n"); |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 294 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 295 | // instantiate NativeFile object and add values to it as found |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 296 | std::unique_ptr<File> file(new File(context, std::move(mb), path)); |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 297 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 298 | // process each chunk |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 299 | for (uint32_t i = 0; i < header->chunkCount; ++i) { |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 300 | error_code ec; |
Michael J. Spencer | b2bd733 | 2012-01-31 21:45:53 +0000 | [diff] [blame] | 301 | const NativeChunk* chunk = &chunks[i]; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 302 | // sanity check chunk is within file |
Michael J. Spencer | 7aba895 | 2012-01-31 21:47:13 +0000 | [diff] [blame] | 303 | if ( chunk->fileOffset > fileSize ) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 304 | return make_error_code(NativeReaderError::file_malformed); |
Michael J. Spencer | 7aba895 | 2012-01-31 21:47:13 +0000 | [diff] [blame] | 305 | if ( (chunk->fileOffset + chunk->fileSize) > fileSize) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 306 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 307 | // process chunk, based on signature |
| 308 | switch ( chunk->signature ) { |
| 309 | case NCS_DefinedAtomsV1: |
| 310 | ec = file->processDefinedAtomsV1(base, chunk); |
| 311 | break; |
| 312 | case NCS_AttributesArrayV1: |
| 313 | ec = file->processAttributesV1(base, chunk); |
| 314 | break; |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 315 | case NCS_UndefinedAtomsV1: |
| 316 | ec = file->processUndefinedAtomsV1(base, chunk); |
| 317 | break; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 318 | case NCS_SharedLibraryAtomsV1: |
| 319 | ec = file->processSharedLibraryAtomsV1(base, chunk); |
| 320 | break; |
| 321 | case NCS_AbsoluteAtomsV1: |
| 322 | ec = file->processAbsoluteAtomsV1(base, chunk); |
| 323 | break; |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 324 | case NCS_AbsoluteAttributesV1: |
| 325 | ec = file->processAbsoluteAttributesV1(base, chunk); |
| 326 | break; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 327 | case NCS_ReferencesArrayV1: |
| 328 | ec = file->processReferencesV1(base, chunk); |
| 329 | break; |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 330 | case NCS_ReferencesArrayV2: |
| 331 | ec = file->processReferencesV2(base, chunk); |
| 332 | break; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 333 | case NCS_TargetsTable: |
| 334 | ec = file->processTargetsTable(base, chunk); |
| 335 | break; |
| 336 | case NCS_AddendsTable: |
| 337 | ec = file->processAddendsTable(base, chunk); |
| 338 | break; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 339 | case NCS_Content: |
| 340 | ec = file->processContent(base, chunk); |
| 341 | break; |
| 342 | case NCS_Strings: |
| 343 | ec = file->processStrings(base, chunk); |
| 344 | break; |
| 345 | default: |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 346 | return make_error_code(NativeReaderError::unknown_chunk_type); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 347 | } |
| 348 | if ( ec ) { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 349 | return ec; |
| 350 | } |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 351 | } |
| 352 | // TO DO: validate enough chunks were used |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 353 | |
Rui Ueyama | b37c431 | 2013-11-16 01:41:47 +0000 | [diff] [blame] | 354 | DEBUG_WITH_TYPE("ReaderNative", { |
| 355 | llvm::dbgs() << " ReaderNative DefinedAtoms:\n"; |
| 356 | for (const DefinedAtom *a : file->defined()) { |
| 357 | llvm::dbgs() << llvm::format(" 0x%09lX", a) |
| 358 | << ", name=" << a->name() |
| 359 | << ", size=" << a->size() << "\n"; |
| 360 | for (const Reference *r : *a) { |
| 361 | llvm::dbgs() << " offset=" |
| 362 | << llvm::format("0x%03X", r->offsetInAtom()) |
| 363 | << ", kind=" << r->kind() |
| 364 | << ", target=" << r->target() << "\n"; |
| 365 | } |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 366 | } |
Rui Ueyama | b37c431 | 2013-11-16 01:41:47 +0000 | [diff] [blame] | 367 | }); |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 368 | result.push_back(std::move(file)); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 369 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 370 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 371 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 372 | virtual ~File() { |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 373 | // _buffer is automatically deleted because of OwningPtr<> |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 374 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 375 | // All other ivar pointers are pointers into the MemoryBuffer, except |
| 376 | // the _definedAtoms array which was allocated to contain an array |
| 377 | // of Atom objects. The atoms have empty destructors, so it is ok |
| 378 | // to just delete the memory. |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 379 | delete _definedAtoms._arrayStart; |
| 380 | delete _undefinedAtoms._arrayStart; |
| 381 | delete _sharedLibraryAtoms._arrayStart; |
| 382 | delete _absoluteAtoms._arrayStart; |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 383 | delete _referencesV1.arrayStart; |
| 384 | delete _referencesV2.arrayStart; |
Michael J. Spencer | 20231f1 | 2013-01-26 12:26:56 +0000 | [diff] [blame] | 385 | delete [] _targetsTable; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 386 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 387 | |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 388 | virtual const atom_collection<DefinedAtom>& defined() const { |
| 389 | return _definedAtoms; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 390 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 391 | virtual const atom_collection<UndefinedAtom>& undefined() const { |
| 392 | return _undefinedAtoms; |
| 393 | } |
| 394 | virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const { |
| 395 | return _sharedLibraryAtoms; |
| 396 | } |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 397 | virtual const atom_collection<AbsoluteAtom> &absolute() const { |
| 398 | return _absoluteAtoms; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 399 | } |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 400 | virtual const LinkingContext &getLinkingContext() const { return _context; } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 401 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 402 | private: |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 403 | friend NativeDefinedAtomV1; |
| 404 | friend NativeUndefinedAtomV1; |
| 405 | friend NativeSharedLibraryAtomV1; |
| 406 | friend NativeAbsoluteAtomV1; |
| 407 | friend NativeReferenceV1; |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 408 | friend NativeReferenceV2; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 409 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 410 | // instantiate array of DefinedAtoms from v1 ivar data in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 411 | error_code processDefinedAtomsV1(const uint8_t *base, |
| 412 | const NativeChunk *chunk) { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 413 | const size_t atomSize = sizeof(NativeDefinedAtomV1); |
| 414 | size_t atomsArraySize = chunk->elementCount * atomSize; |
| 415 | uint8_t* atomsStart = reinterpret_cast<uint8_t*> |
| 416 | (operator new(atomsArraySize, std::nothrow)); |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 417 | if (atomsStart == nullptr) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 418 | return make_error_code(NativeReaderError::memory_error); |
Michael J. Spencer | 7aba895 | 2012-01-31 21:47:13 +0000 | [diff] [blame] | 419 | const size_t ivarElementSize = chunk->fileSize |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 420 | / chunk->elementCount; |
| 421 | if ( ivarElementSize != sizeof(NativeDefinedAtomIvarsV1) ) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 422 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 423 | uint8_t* atomsEnd = atomsStart + atomsArraySize; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 424 | const NativeDefinedAtomIvarsV1* ivarData = |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 425 | reinterpret_cast<const NativeDefinedAtomIvarsV1*> |
| 426 | (base + chunk->fileOffset); |
| 427 | for(uint8_t* s = atomsStart; s != atomsEnd; s += atomSize) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 428 | NativeDefinedAtomV1* atomAllocSpace = |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 429 | reinterpret_cast<NativeDefinedAtomV1*>(s); |
| 430 | new (atomAllocSpace) NativeDefinedAtomV1(*this, ivarData); |
| 431 | ++ivarData; |
| 432 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 433 | this->_definedAtoms._arrayStart = atomsStart; |
| 434 | this->_definedAtoms._arrayEnd = atomsEnd; |
| 435 | this->_definedAtoms._elementSize = atomSize; |
| 436 | this->_definedAtoms._elementCount = chunk->elementCount; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 437 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 438 | << " chunk DefinedAtomsV1: " |
| 439 | << " count=" << chunk->elementCount |
| 440 | << " chunkSize=" << chunk->fileSize |
| 441 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 442 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 443 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 444 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 445 | |
| 446 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 447 | // set up pointers to attributes array |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 448 | error_code processAttributesV1(const uint8_t *base, |
| 449 | const NativeChunk *chunk) { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 450 | this->_attributes = base + chunk->fileOffset; |
| 451 | this->_attributesMaxOffset = chunk->fileSize; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 452 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 453 | << " chunk AttributesV1: " |
| 454 | << " count=" << chunk->elementCount |
| 455 | << " chunkSize=" << chunk->fileSize |
| 456 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 457 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 458 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 459 | |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 460 | // set up pointers to attributes array |
| 461 | error_code processAbsoluteAttributesV1(const uint8_t *base, |
| 462 | const NativeChunk *chunk) { |
| 463 | this->_absAttributes = base + chunk->fileOffset; |
| 464 | this->_absAbsoluteMaxOffset = chunk->fileSize; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 465 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 466 | << " chunk AbsoluteAttributesV1: " |
| 467 | << " count=" << chunk->elementCount |
| 468 | << " chunkSize=" << chunk->fileSize |
| 469 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 470 | return make_error_code(NativeReaderError::success); |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 473 | // instantiate array of UndefinedAtoms from v1 ivar data in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 474 | error_code processUndefinedAtomsV1(const uint8_t *base, |
| 475 | const NativeChunk *chunk) { |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 476 | const size_t atomSize = sizeof(NativeUndefinedAtomV1); |
| 477 | size_t atomsArraySize = chunk->elementCount * atomSize; |
| 478 | uint8_t* atomsStart = reinterpret_cast<uint8_t*> |
| 479 | (operator new(atomsArraySize, std::nothrow)); |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 480 | if (atomsStart == nullptr) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 481 | return make_error_code(NativeReaderError::memory_error); |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 482 | const size_t ivarElementSize = chunk->fileSize |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 483 | / chunk->elementCount; |
| 484 | if ( ivarElementSize != sizeof(NativeUndefinedAtomIvarsV1) ) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 485 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 486 | uint8_t* atomsEnd = atomsStart + atomsArraySize; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 487 | const NativeUndefinedAtomIvarsV1* ivarData = |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 488 | reinterpret_cast<const NativeUndefinedAtomIvarsV1*> |
| 489 | (base + chunk->fileOffset); |
| 490 | for(uint8_t* s = atomsStart; s != atomsEnd; s += atomSize) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 491 | NativeUndefinedAtomV1* atomAllocSpace = |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 492 | reinterpret_cast<NativeUndefinedAtomV1*>(s); |
| 493 | new (atomAllocSpace) NativeUndefinedAtomV1(*this, ivarData); |
| 494 | ++ivarData; |
| 495 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 496 | this->_undefinedAtoms._arrayStart = atomsStart; |
| 497 | this->_undefinedAtoms._arrayEnd = atomsEnd; |
| 498 | this->_undefinedAtoms._elementSize = atomSize; |
| 499 | this->_undefinedAtoms._elementCount = chunk->elementCount; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 500 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 501 | << " chunk UndefinedAtomsV1:" |
| 502 | << " count=" << chunk->elementCount |
| 503 | << " chunkSize=" << chunk->fileSize |
| 504 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 505 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 506 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 507 | |
| 508 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 509 | // instantiate array of ShareLibraryAtoms from v1 ivar data in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 510 | error_code processSharedLibraryAtomsV1(const uint8_t *base, |
| 511 | const NativeChunk *chunk) { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 512 | const size_t atomSize = sizeof(NativeSharedLibraryAtomV1); |
| 513 | size_t atomsArraySize = chunk->elementCount * atomSize; |
| 514 | uint8_t* atomsStart = reinterpret_cast<uint8_t*> |
| 515 | (operator new(atomsArraySize, std::nothrow)); |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 516 | if (atomsStart == nullptr) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 517 | return make_error_code(NativeReaderError::memory_error); |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 518 | const size_t ivarElementSize = chunk->fileSize |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 519 | / chunk->elementCount; |
| 520 | if ( ivarElementSize != sizeof(NativeSharedLibraryAtomIvarsV1) ) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 521 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 522 | uint8_t* atomsEnd = atomsStart + atomsArraySize; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 523 | const NativeSharedLibraryAtomIvarsV1* ivarData = |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 524 | reinterpret_cast<const NativeSharedLibraryAtomIvarsV1*> |
| 525 | (base + chunk->fileOffset); |
| 526 | for(uint8_t* s = atomsStart; s != atomsEnd; s += atomSize) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 527 | NativeSharedLibraryAtomV1* atomAllocSpace = |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 528 | reinterpret_cast<NativeSharedLibraryAtomV1*>(s); |
| 529 | new (atomAllocSpace) NativeSharedLibraryAtomV1(*this, ivarData); |
| 530 | ++ivarData; |
| 531 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 532 | this->_sharedLibraryAtoms._arrayStart = atomsStart; |
| 533 | this->_sharedLibraryAtoms._arrayEnd = atomsEnd; |
| 534 | this->_sharedLibraryAtoms._elementSize = atomSize; |
| 535 | this->_sharedLibraryAtoms._elementCount = chunk->elementCount; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 536 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 537 | << " chunk SharedLibraryAtomsV1:" |
| 538 | << " count=" << chunk->elementCount |
| 539 | << " chunkSize=" << chunk->fileSize |
| 540 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 541 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 542 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 543 | |
| 544 | |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 545 | // instantiate array of AbsoluteAtoms from v1 ivar data in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 546 | error_code processAbsoluteAtomsV1(const uint8_t *base, |
| 547 | const NativeChunk *chunk) { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 548 | const size_t atomSize = sizeof(NativeAbsoluteAtomV1); |
| 549 | size_t atomsArraySize = chunk->elementCount * atomSize; |
| 550 | uint8_t* atomsStart = reinterpret_cast<uint8_t*> |
| 551 | (operator new(atomsArraySize, std::nothrow)); |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 552 | if (atomsStart == nullptr) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 553 | return make_error_code(NativeReaderError::memory_error); |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 554 | const size_t ivarElementSize = chunk->fileSize |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 555 | / chunk->elementCount; |
| 556 | if ( ivarElementSize != sizeof(NativeAbsoluteAtomIvarsV1) ) |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 557 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 558 | uint8_t* atomsEnd = atomsStart + atomsArraySize; |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 559 | const NativeAbsoluteAtomIvarsV1* ivarData = |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 560 | reinterpret_cast<const NativeAbsoluteAtomIvarsV1*> |
| 561 | (base + chunk->fileOffset); |
| 562 | for(uint8_t* s = atomsStart; s != atomsEnd; s += atomSize) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 563 | NativeAbsoluteAtomV1* atomAllocSpace = |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 564 | reinterpret_cast<NativeAbsoluteAtomV1*>(s); |
| 565 | new (atomAllocSpace) NativeAbsoluteAtomV1(*this, ivarData); |
| 566 | ++ivarData; |
| 567 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 568 | this->_absoluteAtoms._arrayStart = atomsStart; |
| 569 | this->_absoluteAtoms._arrayEnd = atomsEnd; |
| 570 | this->_absoluteAtoms._elementSize = atomSize; |
| 571 | this->_absoluteAtoms._elementCount = chunk->elementCount; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 572 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 573 | << " chunk AbsoluteAtomsV1: " |
| 574 | << " count=" << chunk->elementCount |
| 575 | << " chunkSize=" << chunk->fileSize |
| 576 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 577 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 578 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 579 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 580 | template<class T, class U> |
| 581 | error_code processReferences(const uint8_t *base, const NativeChunk *chunk, |
| 582 | uint8_t *&refsStart, uint8_t *&refsEnd) const { |
| 583 | if (chunk->elementCount == 0) |
| 584 | return make_error_code(NativeReaderError::success); |
| 585 | size_t refsArraySize = chunk->elementCount * sizeof(T); |
| 586 | refsStart = reinterpret_cast<uint8_t *>( |
| 587 | operator new(refsArraySize, std::nothrow)); |
| 588 | if (refsStart == nullptr) |
| 589 | return make_error_code(NativeReaderError::memory_error); |
| 590 | const size_t ivarElementSize = chunk->fileSize / chunk->elementCount; |
| 591 | if (ivarElementSize != sizeof(U)) |
| 592 | return make_error_code(NativeReaderError::file_malformed); |
| 593 | refsEnd = refsStart + refsArraySize; |
| 594 | const U* ivarData = reinterpret_cast<const U *>(base + chunk->fileOffset); |
| 595 | for (uint8_t *s = refsStart; s != refsEnd; s += sizeof(T), ++ivarData) { |
| 596 | T *atomAllocSpace = reinterpret_cast<T *>(s); |
| 597 | new (atomAllocSpace) T(*this, ivarData); |
| 598 | } |
| 599 | return make_error_code(NativeReaderError::success); |
| 600 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 601 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 602 | // instantiate array of Referemces from v1 ivar data in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 603 | error_code processReferencesV1(const uint8_t *base, |
| 604 | const NativeChunk *chunk) { |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 605 | uint8_t *refsStart, *refsEnd; |
| 606 | if (error_code ec |
| 607 | = processReferences<NativeReferenceV1, NativeReferenceIvarsV1>( |
| 608 | base, chunk, refsStart, refsEnd)) |
| 609 | return ec; |
| 610 | this->_referencesV1.arrayStart = refsStart; |
| 611 | this->_referencesV1.arrayEnd = refsEnd; |
| 612 | this->_referencesV1.elementSize = sizeof(NativeReferenceV1); |
| 613 | this->_referencesV1.elementCount = chunk->elementCount; |
| 614 | DEBUG_WITH_TYPE("ReaderNative", { |
| 615 | llvm::dbgs() << " chunk ReferencesV1: " |
| 616 | << " count=" << chunk->elementCount |
| 617 | << " chunkSize=" << chunk->fileSize << "\n"; |
| 618 | }); |
| 619 | return make_error_code(NativeReaderError::success); |
| 620 | } |
| 621 | |
| 622 | // instantiate array of Referemces from v2 ivar data in file |
| 623 | error_code processReferencesV2(const uint8_t *base, |
| 624 | const NativeChunk *chunk) { |
| 625 | uint8_t *refsStart, *refsEnd; |
| 626 | if (error_code ec |
| 627 | = processReferences<NativeReferenceV2, NativeReferenceIvarsV2>( |
| 628 | base, chunk, refsStart, refsEnd)) |
| 629 | return ec; |
| 630 | this->_referencesV2.arrayStart = refsStart; |
| 631 | this->_referencesV2.arrayEnd = refsEnd; |
| 632 | this->_referencesV2.elementSize = sizeof(NativeReferenceV2); |
| 633 | this->_referencesV2.elementCount = chunk->elementCount; |
| 634 | DEBUG_WITH_TYPE("ReaderNative", { |
| 635 | llvm::dbgs() << " chunk ReferencesV2: " |
| 636 | << " count=" << chunk->elementCount |
| 637 | << " chunkSize=" << chunk->fileSize << "\n"; |
| 638 | }); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 639 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 640 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 641 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 642 | // set up pointers to target table |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 643 | error_code processTargetsTable(const uint8_t *base, |
| 644 | const NativeChunk *chunk) { |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 645 | const uint32_t* targetIndexes = reinterpret_cast<const uint32_t*> |
| 646 | (base + chunk->fileOffset); |
| 647 | this->_targetsTableCount = chunk->elementCount; |
| 648 | this->_targetsTable = new const Atom*[chunk->elementCount]; |
| 649 | for (uint32_t i=0; i < chunk->elementCount; ++i) { |
| 650 | const uint32_t index = targetIndexes[i]; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 651 | if ( index < _definedAtoms._elementCount ) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 652 | const uint8_t* p = _definedAtoms._arrayStart |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 653 | + index * _definedAtoms._elementSize; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 654 | this->_targetsTable[i] = reinterpret_cast<const DefinedAtom*>(p); |
| 655 | continue; |
| 656 | } |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 657 | const uint32_t undefIndex = index - _definedAtoms._elementCount; |
| 658 | if ( undefIndex < _undefinedAtoms._elementCount ) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 659 | const uint8_t* p = _undefinedAtoms._arrayStart |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 660 | + undefIndex * _undefinedAtoms._elementSize; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 661 | this->_targetsTable[i] = reinterpret_cast<const UndefinedAtom*>(p); |
| 662 | continue; |
| 663 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 664 | const uint32_t slIndex = index - _definedAtoms._elementCount |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 665 | - _undefinedAtoms._elementCount; |
| 666 | if ( slIndex < _sharedLibraryAtoms._elementCount ) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 667 | const uint8_t* p = _sharedLibraryAtoms._arrayStart |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 668 | + slIndex * _sharedLibraryAtoms._elementSize; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 669 | this->_targetsTable[i] = reinterpret_cast<const SharedLibraryAtom*>(p); |
| 670 | continue; |
| 671 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 672 | const uint32_t abIndex = index - _definedAtoms._elementCount |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 673 | - _undefinedAtoms._elementCount |
| 674 | - _sharedLibraryAtoms._elementCount; |
| 675 | if ( abIndex < _absoluteAtoms._elementCount ) { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 676 | const uint8_t* p = _absoluteAtoms._arrayStart |
Simon Atanasyan | 8ef39b5 | 2013-11-04 19:40:02 +0000 | [diff] [blame] | 677 | + abIndex * _absoluteAtoms._elementSize; |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 678 | this->_targetsTable[i] = reinterpret_cast<const AbsoluteAtom*>(p); |
| 679 | continue; |
| 680 | } |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 681 | return make_error_code(NativeReaderError::file_malformed); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 682 | } |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 683 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 684 | << " chunk Targets Table: " |
| 685 | << " count=" << chunk->elementCount |
| 686 | << " chunkSize=" << chunk->fileSize |
| 687 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 688 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 689 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 690 | |
| 691 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 692 | // set up pointers to addend pool in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 693 | error_code processAddendsTable(const uint8_t *base, |
| 694 | const NativeChunk *chunk) { |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 695 | this->_addends = reinterpret_cast<const Reference::Addend*> |
| 696 | (base + chunk->fileOffset); |
| 697 | this->_addendsMaxIndex = chunk->elementCount; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 698 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 699 | << " chunk Addends: " |
| 700 | << " count=" << chunk->elementCount |
| 701 | << " chunkSize=" << chunk->fileSize |
| 702 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 703 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 704 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 705 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 706 | // set up pointers to string pool in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 707 | error_code processStrings(const uint8_t *base, |
| 708 | const NativeChunk *chunk) { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 709 | this->_strings = reinterpret_cast<const char*>(base + chunk->fileOffset); |
| 710 | this->_stringsMaxOffset = chunk->fileSize; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 711 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 712 | << " chunk Strings: " |
| 713 | << " chunkSize=" << chunk->fileSize |
| 714 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 715 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 716 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 717 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 718 | // set up pointers to content area in file |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 719 | error_code processContent(const uint8_t *base, |
| 720 | const NativeChunk *chunk) { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 721 | this->_contentStart = base + chunk->fileOffset; |
| 722 | this->_contentEnd = base + chunk->fileOffset + chunk->fileSize; |
Shankar Easwaran | 8962feb | 2013-03-14 16:09:49 +0000 | [diff] [blame] | 723 | DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 724 | << " chunk content: " |
| 725 | << " chunkSize=" << chunk->fileSize |
| 726 | << "\n"); |
Rui Ueyama | c6015f6 | 2013-10-09 00:57:22 +0000 | [diff] [blame] | 727 | return make_error_code(NativeReaderError::success); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 728 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 729 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 730 | StringRef string(uint32_t offset) const { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 731 | assert(offset < _stringsMaxOffset); |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 732 | return StringRef(&_strings[offset]); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 733 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 734 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 735 | Reference::Addend addend(uint32_t index) const { |
| 736 | if ( index == 0 ) |
| 737 | return 0; // addend index zero is used to mean "no addend" |
| 738 | assert(index <= _addendsMaxIndex); |
| 739 | return _addends[index-1]; // one-based indexing |
| 740 | } |
| 741 | |
| 742 | const NativeAtomAttributesV1& attribute(uint32_t off) const { |
| 743 | assert(off < _attributesMaxOffset); |
| 744 | return *reinterpret_cast<const NativeAtomAttributesV1*>(_attributes + off); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 747 | const NativeAtomAttributesV1& absAttribute(uint32_t off) const { |
| 748 | assert(off < _absAbsoluteMaxOffset); |
| 749 | return *reinterpret_cast<const NativeAtomAttributesV1*>(_absAttributes + off); |
| 750 | } |
| 751 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 752 | const uint8_t* content(uint32_t offset, uint32_t size) const { |
| 753 | const uint8_t* result = _contentStart + offset; |
| 754 | assert((result+size) <= _contentEnd); |
| 755 | return result; |
| 756 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 757 | |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 758 | const Reference* referenceByIndex(uintptr_t index) const { |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 759 | if (index < _referencesV1.elementCount) { |
| 760 | return reinterpret_cast<const NativeReferenceV1*>( |
| 761 | _referencesV1.arrayStart + index * _referencesV1.elementSize); |
| 762 | } |
| 763 | assert(index < _referencesV2.elementCount); |
| 764 | return reinterpret_cast<const NativeReferenceV2*>( |
| 765 | _referencesV2.arrayStart + index * _referencesV2.elementSize); |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 768 | const Atom* targetV1(uint16_t index) const { |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 769 | if ( index == NativeReferenceIvarsV1::noTarget ) |
| 770 | return nullptr; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 771 | assert(index < _targetsTableCount); |
| 772 | return _targetsTable[index]; |
| 773 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 774 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 775 | void setTargetV1(uint16_t index, const Atom* newAtom) const { |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 776 | assert(index != NativeReferenceIvarsV1::noTarget); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 777 | assert(index > _targetsTableCount); |
| 778 | _targetsTable[index] = newAtom; |
| 779 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 780 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 781 | const Atom* targetV2(uint32_t index) const { |
| 782 | if (index == NativeReferenceIvarsV2::noTarget) |
| 783 | return nullptr; |
| 784 | assert(index < _targetsTableCount); |
| 785 | return _targetsTable[index]; |
| 786 | } |
| 787 | |
| 788 | void setTargetV2(uint32_t index, const Atom* newAtom) const { |
| 789 | assert(index != NativeReferenceIvarsV2::noTarget); |
| 790 | assert(index > _targetsTableCount); |
| 791 | _targetsTable[index] = newAtom; |
| 792 | } |
| 793 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 794 | // private constructor, only called by make() |
Rui Ueyama | c1800be | 2013-11-05 01:37:40 +0000 | [diff] [blame] | 795 | File(const LinkingContext &context, std::unique_ptr<MemoryBuffer> mb, |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 796 | StringRef path) |
Michael J. Spencer | 0f3dd61 | 2013-03-20 18:57:27 +0000 | [diff] [blame] | 797 | : lld::File(path, kindObject), |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 798 | _buffer(std::move(mb)), // Reader now takes ownership of buffer |
| 799 | _header(nullptr), _targetsTable(nullptr), _targetsTableCount(0), |
| 800 | _strings(nullptr), _stringsMaxOffset(0), _addends(nullptr), |
| 801 | _addendsMaxIndex(0), _contentStart(nullptr), _contentEnd(nullptr), |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 802 | _context(context) { |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 803 | _header = |
| 804 | reinterpret_cast<const NativeFileHeader *>(_buffer->getBufferStart()); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 807 | template <typename T> |
| 808 | class AtomArray : public File::atom_collection<T> { |
| 809 | public: |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 810 | AtomArray() : _arrayStart(nullptr), _arrayEnd(nullptr), |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 811 | _elementSize(0), _elementCount(0) { } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 812 | |
| 813 | virtual atom_iterator<T> begin() const { |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 814 | return atom_iterator<T>(*this, reinterpret_cast<const void*>(_arrayStart)); |
| 815 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 816 | virtual atom_iterator<T> end() const{ |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 817 | return atom_iterator<T>(*this, reinterpret_cast<const void*>(_arrayEnd)); |
| 818 | } |
| 819 | virtual const T* deref(const void* it) const { |
| 820 | return reinterpret_cast<const T*>(it); |
| 821 | } |
| 822 | virtual void next(const void*& it) const { |
| 823 | const uint8_t* p = reinterpret_cast<const uint8_t*>(it); |
| 824 | p += _elementSize; |
| 825 | it = reinterpret_cast<const void*>(p); |
| 826 | } |
Shankar Easwaran | cc06891 | 2013-04-29 04:10:42 +0000 | [diff] [blame] | 827 | virtual uint64_t size() const { return _elementCount; } |
| 828 | const uint8_t *_arrayStart; |
| 829 | const uint8_t *_arrayEnd; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 830 | uint32_t _elementSize; |
| 831 | uint32_t _elementCount; |
| 832 | }; |
| 833 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 834 | struct IvarArray { |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 835 | IvarArray() : |
Michael J. Spencer | c9d2506 | 2012-03-29 19:39:14 +0000 | [diff] [blame] | 836 | arrayStart(nullptr), |
| 837 | arrayEnd(nullptr), |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 838 | elementSize(0), |
| 839 | elementCount(0) { } |
| 840 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 841 | const uint8_t* arrayStart; |
| 842 | const uint8_t* arrayEnd; |
| 843 | uint32_t elementSize; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 844 | uint32_t elementCount; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 845 | }; |
| 846 | |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 847 | |
Rui Ueyama | c1800be | 2013-11-05 01:37:40 +0000 | [diff] [blame] | 848 | std::unique_ptr<MemoryBuffer> _buffer; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 849 | const NativeFileHeader* _header; |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 850 | AtomArray<DefinedAtom> _definedAtoms; |
| 851 | AtomArray<UndefinedAtom> _undefinedAtoms; |
| 852 | AtomArray<SharedLibraryAtom> _sharedLibraryAtoms; |
| 853 | AtomArray<AbsoluteAtom> _absoluteAtoms; |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 854 | const uint8_t* _absAttributes; |
| 855 | uint32_t _absAbsoluteMaxOffset; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 856 | const uint8_t* _attributes; |
| 857 | uint32_t _attributesMaxOffset; |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 858 | IvarArray _referencesV1; |
| 859 | IvarArray _referencesV2; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 860 | const Atom** _targetsTable; |
| 861 | uint32_t _targetsTableCount; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 862 | const char* _strings; |
| 863 | uint32_t _stringsMaxOffset; |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 864 | const Reference::Addend* _addends; |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 865 | uint32_t _addendsMaxIndex; |
| 866 | const uint8_t *_contentStart; |
| 867 | const uint8_t *_contentEnd; |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 868 | const LinkingContext &_context; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 869 | }; |
| 870 | |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 871 | inline const lld::File &NativeDefinedAtomV1::file() const { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 872 | return *_file; |
| 873 | } |
| 874 | |
| 875 | inline uint64_t NativeDefinedAtomV1:: ordinal() const { |
| 876 | const uint8_t* p = reinterpret_cast<const uint8_t*>(_ivarData); |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 877 | return p - _file->_definedAtoms._arrayStart; |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 880 | inline StringRef NativeDefinedAtomV1::name() const { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 881 | return _file->string(_ivarData->nameOffset); |
| 882 | } |
| 883 | |
| 884 | inline const NativeAtomAttributesV1& NativeDefinedAtomV1::attributes() const { |
| 885 | return _file->attribute(_ivarData->attributesOffset); |
| 886 | } |
| 887 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 888 | inline ArrayRef<uint8_t> NativeDefinedAtomV1::rawContent() const { |
Shankar Easwaran | d17ba4b | 2013-08-23 20:03:21 +0000 | [diff] [blame] | 889 | if (!occupiesDiskSpace()) |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 890 | return ArrayRef<uint8_t>(); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 891 | const uint8_t* p = _file->content(_ivarData->contentOffset, |
| 892 | _ivarData->contentSize); |
Shankar Easwaran | d17ba4b | 2013-08-23 20:03:21 +0000 | [diff] [blame] | 893 | return ArrayRef<uint8_t>(p, _ivarData->contentSize); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 896 | inline StringRef NativeDefinedAtomV1::customSectionName() const { |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 897 | uint32_t offset = attributes().sectionNameOffset; |
| 898 | return _file->string(offset); |
| 899 | } |
| 900 | |
Nick Kledzik | 062a98c | 2012-04-08 23:52:13 +0000 | [diff] [blame] | 901 | DefinedAtom::reference_iterator NativeDefinedAtomV1::begin() const { |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 902 | uintptr_t index = _ivarData->referencesStartIndex; |
| 903 | const void* it = reinterpret_cast<const void*>(index); |
| 904 | return reference_iterator(*this, it); |
| 905 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 906 | |
Nick Kledzik | 062a98c | 2012-04-08 23:52:13 +0000 | [diff] [blame] | 907 | DefinedAtom::reference_iterator NativeDefinedAtomV1::end() const { |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 908 | uintptr_t index = _ivarData->referencesStartIndex+_ivarData->referencesCount; |
| 909 | const void* it = reinterpret_cast<const void*>(index); |
| 910 | return reference_iterator(*this, it); |
| 911 | } |
| 912 | |
| 913 | const Reference* NativeDefinedAtomV1::derefIterator(const void* it) const { |
| 914 | uintptr_t index = reinterpret_cast<uintptr_t>(it); |
| 915 | return _file->referenceByIndex(index); |
| 916 | } |
Michael J. Spencer | 765792d | 2012-04-03 18:40:27 +0000 | [diff] [blame] | 917 | |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 918 | void NativeDefinedAtomV1::incrementIterator(const void*& it) const { |
| 919 | uintptr_t index = reinterpret_cast<uintptr_t>(it); |
| 920 | ++index; |
| 921 | it = reinterpret_cast<const void*>(index); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 922 | } |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 923 | |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 924 | inline const lld::File& NativeUndefinedAtomV1::file() const { |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 925 | return *_file; |
| 926 | } |
| 927 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 928 | inline StringRef NativeUndefinedAtomV1::name() const { |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 929 | return _file->string(_ivarData->nameOffset); |
| 930 | } |
| 931 | |
Rui Ueyama | e5416ec | 2013-09-12 19:14:05 +0000 | [diff] [blame] | 932 | inline const UndefinedAtom *NativeUndefinedAtomV1::fallback() const { |
| 933 | if (!_ivarData->fallbackNameOffset) |
| 934 | return nullptr; |
| 935 | if (!_fallback) |
| 936 | _fallback.reset(new SimpleUndefinedAtom( |
| 937 | *_file, _file->string(_ivarData->fallbackNameOffset))); |
| 938 | return _fallback.get(); |
| 939 | } |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 940 | |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 941 | inline const lld::File& NativeSharedLibraryAtomV1::file() const { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 942 | return *_file; |
| 943 | } |
| 944 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 945 | inline StringRef NativeSharedLibraryAtomV1::name() const { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 946 | return _file->string(_ivarData->nameOffset); |
| 947 | } |
| 948 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 949 | inline StringRef NativeSharedLibraryAtomV1::loadName() const { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 950 | return _file->string(_ivarData->loadNameOffset); |
| 951 | } |
| 952 | |
| 953 | |
| 954 | |
Rui Ueyama | 7b7b0b9 | 2013-06-21 19:59:15 +0000 | [diff] [blame] | 955 | inline const lld::File& NativeAbsoluteAtomV1::file() const { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 956 | return *_file; |
| 957 | } |
| 958 | |
Michael J. Spencer | e6203a5 | 2012-04-03 18:39:40 +0000 | [diff] [blame] | 959 | inline StringRef NativeAbsoluteAtomV1::name() const { |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 960 | return _file->string(_ivarData->nameOffset); |
| 961 | } |
| 962 | |
Sid Manning | 2a59024 | 2012-10-18 17:16:19 +0000 | [diff] [blame] | 963 | inline const NativeAtomAttributesV1& NativeAbsoluteAtomV1::absAttributes() const { |
| 964 | return _file->absAttribute(_ivarData->attributesOffset); |
| 965 | } |
Nick Kledzik | 6bc04c6 | 2012-02-22 21:56:59 +0000 | [diff] [blame] | 966 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 967 | inline const Atom* NativeReferenceV1::target() const { |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 968 | return _file->targetV1(_ivarData->targetIndex); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | inline Reference::Addend NativeReferenceV1::addend() const { |
| 972 | return _file->addend(_ivarData->addendIndex); |
| 973 | } |
| 974 | |
| 975 | inline void NativeReferenceV1::setTarget(const Atom* newAtom) { |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 976 | return _file->setTargetV1(_ivarData->targetIndex, newAtom); |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame] | 977 | } |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 978 | |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 979 | inline void NativeReferenceV1::setAddend(Addend a) { |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 980 | // Do nothing if addend value is not being changed. |
Michael J. Spencer | 64afcb4 | 2013-01-23 01:18:43 +0000 | [diff] [blame] | 981 | if (addend() == a) |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 982 | return; |
Michael J. Spencer | 64afcb4 | 2013-01-23 01:18:43 +0000 | [diff] [blame] | 983 | llvm_unreachable("setAddend() not supported"); |
Nick Kledzik | b334be1 | 2012-04-07 01:31:00 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Rui Ueyama | e05b629 | 2013-11-20 20:54:18 +0000 | [diff] [blame^] | 986 | inline const Atom* NativeReferenceV2::target() const { |
| 987 | return _file->targetV2(_ivarData->targetIndex); |
| 988 | } |
| 989 | |
| 990 | inline Reference::Addend NativeReferenceV2::addend() const { |
| 991 | return _ivarData->addend; |
| 992 | } |
| 993 | |
| 994 | inline void NativeReferenceV2::setTarget(const Atom* newAtom) { |
| 995 | return _file->setTargetV2(_ivarData->targetIndex, newAtom); |
| 996 | } |
| 997 | |
| 998 | inline void NativeReferenceV2::setAddend(Addend a) { |
| 999 | // Do nothing if addend value is not being changed. |
| 1000 | if (addend() == a) |
| 1001 | return; |
| 1002 | llvm_unreachable("setAddend() not supported"); |
| 1003 | } |
| 1004 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1005 | class Reader : public lld::Reader { |
| 1006 | public: |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 1007 | Reader(const LinkingContext &context) : lld::Reader(context) {} |
Shankar Easwaran | 3256d4f | 2013-01-25 07:39:18 +0000 | [diff] [blame] | 1008 | |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 1009 | virtual error_code |
Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 1010 | parseFile(std::unique_ptr<MemoryBuffer> &mb, |
| 1011 | std::vector<std::unique_ptr<lld::File> > &result) const { |
| 1012 | return File::make(_context, std::move(mb), result); |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1013 | } |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1014 | }; |
Michael J. Spencer | 64afcb4 | 2013-01-23 01:18:43 +0000 | [diff] [blame] | 1015 | } // end namespace native |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1016 | |
Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 1017 | std::unique_ptr<Reader> createReaderNative(const LinkingContext &context) { |
| 1018 | return std::unique_ptr<Reader>(new lld::native::Reader(context)); |
Nick Kledzik | 55fd6be | 2012-01-16 22:03:44 +0000 | [diff] [blame] | 1019 | } |
Michael J. Spencer | 64afcb4 | 2013-01-23 01:18:43 +0000 | [diff] [blame] | 1020 | } // end namespace lld |