llvm.org GIT mirror llvm / 86bfc78
[Object] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300779 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 3 years ago
10 changed file(s) with 261 addition(s) and 143 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_OBJECT_ARCHIVE_H
1414 #define LLVM_OBJECT_ARCHIVE_H
1515
16 #include "llvm/ADT/iterator_range.h"
1617 #include "llvm/ADT/Optional.h"
1718 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/iterator_range.h"
1919 #include "llvm/Object/Binary.h"
2020 #include "llvm/Support/Chrono.h"
2121 #include "llvm/Support/Error.h"
22 #include "llvm/Support/ErrorHandling.h"
2322 #include "llvm/Support/FileSystem.h"
2423 #include "llvm/Support/MemoryBuffer.h"
24 #include
25 #include
26 #include
27 #include
28 #include
29 #include
2530
2631 namespace llvm {
2732 namespace object {
3136 class ArchiveMemberHeader {
3237 public:
3338 friend class Archive;
39
3440 ArchiveMemberHeader(Archive const *Parent, const char *RawHeaderPtr,
3541 uint64_t Size, Error *Err);
3642 // ArchiveMemberHeader() = default;
3743
3844 /// Get the name without looking up long names.
39 Expected<llvm::StringRef> getRawName() const;
45 Expected<StringRef> getRawName() const;
4046
4147 /// Get the name looking up long names.
42 Expected<llvm::StringRef> getName(uint64_t Size) const;
48 Expected<StringRef> getName(uint64_t Size) const;
4349
4450 /// Members are not larger than 4GB.
4551 Expected getSize() const;
4652
4753 Expected getAccessMode() const;
4854 Expected> getLastModified() const;
49 llvm::StringRef getRawLastModified() const {
55
56 StringRef getRawLastModified() const {
5057 return StringRef(ArMemHdr->LastModified,
5158 sizeof(ArMemHdr->LastModified)).rtrim(' ');
5259 }
60
5361 Expected getUID() const;
5462 Expected getGID() const;
5563
7482
7583 class Archive : public Binary {
7684 virtual void anchor();
85
7786 public:
7887 class Child {
7988 friend Archive;
89 friend ArchiveMemberHeader;
90
8091 const Archive *Parent;
81 friend ArchiveMemberHeader;
8292 ArchiveMemberHeader Header;
8393 /// \brief Includes header but not padding byte.
8494 StringRef Data;
102112 Expected getName() const;
103113 Expected getFullName() const;
104114 Expected getRawName() const { return Header.getRawName(); }
115
105116 Expected> getLastModified() const {
106117 return Header.getLastModified();
107118 }
119
108120 StringRef getRawLastModified() const {
109121 return Header.getRawLastModified();
110122 }
123
111124 Expected getUID() const { return Header.getUID(); }
112125 Expected getGID() const { return Header.getGID(); }
126
113127 Expected getAccessMode() const {
114128 return Header.getAccessMode();
115129 }
130
116131 /// \return the size of the archive member without the header or padding.
117132 Expected getSize() const;
118133 /// \return the size in the archive header for this member.
129144
130145 class child_iterator {
131146 Child C;
132 Error *E;
133
134 public:
135 child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {}
147 Error *E = nullptr;
148
149 public:
150 child_iterator() : C(Child(nullptr, nullptr, nullptr)) {}
136151 child_iterator(const Child &C, Error *E) : C(C), E(E) {}
152
137153 const Child *operator->() const { return &C; }
138154 const Child &operator*() const { return C; }
139155
170186 uint32_t StringIndex; // Extra index to the string.
171187
172188 public:
173 bool operator ==(const Symbol &other) const {
174 return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
175 }
176
177189 Symbol(const Archive *p, uint32_t symi, uint32_t stri)
178190 : Parent(p)
179191 , SymbolIndex(symi)
180192 , StringIndex(stri) {}
193
194 bool operator ==(const Symbol &other) const {
195 return (Parent == other.Parent) && (SymbolIndex == other.SymbolIndex);
196 }
197
181198 StringRef getName() const;
182199 Expected getMember() const;
183200 Symbol getNext() const;
185202
186203 class symbol_iterator {
187204 Symbol symbol;
205
188206 public:
189207 symbol_iterator(const Symbol &s) : symbol(s) {}
208
190209 const Symbol *operator->() const { return &symbol; }
191210 const Symbol &operator*() const { return symbol; }
192211
263282 mutable std::vector> ThinBuffers;
264283 };
265284
266 }
267 }
268
269 #endif
285 } // end namespace object
286 } // end namespace llvm
287
288 #endif // LLVM_OBJECT_ARCHIVE_H
1414 #define LLVM_OBJECT_BINARY_H
1515
1616 #include "llvm/ADT/Triple.h"
17 #include "llvm/Object/Error.h"
18 #include "llvm/Support/ErrorOr.h"
19 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/Error.h"
2018 #include "llvm/Support/MemoryBuffer.h"
19 #include
20 #include
21 #include
2122
2223 namespace llvm {
2324
2829
2930 class Binary {
3031 private:
31 Binary() = delete;
32 Binary(const Binary &other) = delete;
33
3432 unsigned int TypeID;
3533
3634 protected:
7977 }
8078
8179 public:
80 Binary() = delete;
81 Binary(const Binary &other) = delete;
8282 virtual ~Binary();
8383
8484 StringRef getData() const;
172172 std::unique_ptr Buf)
173173 : Bin(std::move(Bin)), Buf(std::move(Buf)) {}
174174
175 template OwningBinary::OwningBinary() {}
175 template OwningBinary::OwningBinary() = default;
176176
177177 template
178178 OwningBinary::OwningBinary(OwningBinary &&Other)
200200 }
201201
202202 Expected> createBinary(StringRef Path);
203 }
204 }
205
206 #endif
203
204 } // end namespace object
205
206 } // end namespace llvm
207
208 #endif // LLVM_OBJECT_BINARY_H
1313 #ifndef LLVM_OBJECT_COFF_H
1414 #define LLVM_OBJECT_COFF_H
1515
16 #include "llvm/ADT/PointerUnion.h"
16 #include "llvm/ADT/iterator_range.h"
1717 #include "llvm/DebugInfo/CodeView/CVDebugRecord.h"
18 #include "llvm/MC/SubtargetFeature.h"
19 #include "llvm/Object/Binary.h"
20 #include "llvm/Object/Error.h"
1821 #include "llvm/Object/ObjectFile.h"
1922 #include "llvm/Support/COFF.h"
2023 #include "llvm/Support/Endian.h"
24 #include "llvm/Support/ErrorHandling.h"
2125 #include "llvm/Support/ErrorOr.h"
26 #include
27 #include
28 #include
29 #include
2230
2331 namespace llvm {
32
2433 template class ArrayRef;
2534
2635 namespace object {
27 class ImportDirectoryEntryRef;
36
37 class BaseRelocRef;
2838 class DelayImportDirectoryEntryRef;
2939 class ExportDirectoryEntryRef;
40 class ImportDirectoryEntryRef;
3041 class ImportedSymbolRef;
31 class BaseRelocRef;
32 typedef content_iterator import_directory_iterator;
33 typedef content_iterator
34 delay_import_directory_iterator;
35 typedef content_iterator export_directory_iterator;
36 typedef content_iterator imported_symbol_iterator;
37 typedef content_iterator base_reloc_iterator;
42
43 using import_directory_iterator = content_iterator;
44 using delay_import_directory_iterator =
45 content_iterator;
46 using export_directory_iterator = content_iterator;
47 using imported_symbol_iterator = content_iterator;
48 using base_reloc_iterator = content_iterator;
3849
3950 /// The DOS compatible header at the front of all PE/COFF executables.
4051 struct dos_header {
189200 }
190201 };
191202
192 typedef import_lookup_table_entry
193 import_lookup_table_entry32;
194 typedef import_lookup_table_entry
195 import_lookup_table_entry64;
203 using import_lookup_table_entry32 =
204 import_lookup_table_entry;
205 using import_lookup_table_entry64 =
206 import_lookup_table_entry;
196207
197208 struct delay_import_directory_table_entry {
198209 // dumpbin reports this field as "Characteristics" instead of "Attributes".
225236 support::ulittle32_t ForwarderRVA;
226237 };
227238
228 typedef support::ulittle32_t export_name_pointer_table_entry;
229 typedef support::ulittle16_t export_ordinal_table_entry;
239 using export_name_pointer_table_entry = support::ulittle32_t;
240 using export_ordinal_table_entry = support::ulittle16_t;
230241
231242 struct StringTableOffset {
232243 support::ulittle32_t Zeroes;
249260 uint8_t NumberOfAuxSymbols;
250261 };
251262
252 typedef coff_symbol coff_symbol16;
253 typedef coff_symbol coff_symbol32;
263 using coff_symbol16 = coff_symbol;
264 using coff_symbol32 = coff_symbol;
254265
255266 // Contains only common parts of coff_symbol16 and coff_symbol32.
256267 struct coff_symbol_generic {
263274
264275 class COFFSymbolRef {
265276 public:
266 COFFSymbolRef(const coff_symbol16 *CS) : CS16(CS), CS32(nullptr) {}
267 COFFSymbolRef(const coff_symbol32 *CS) : CS16(nullptr), CS32(CS) {}
268 COFFSymbolRef() : CS16(nullptr), CS32(nullptr) {}
277 COFFSymbolRef() = default;
278 COFFSymbolRef(const coff_symbol16 *CS) : CS16(CS) {}
279 COFFSymbolRef(const coff_symbol32 *CS) : CS32(CS) {}
269280
270281 const void *getRawPtr() const {
271282 return CS16 ? static_cast(CS16) : CS32;
395406 private:
396407 bool isSet() const { return CS16 || CS32; }
397408
398 const coff_symbol16 *CS16;
399 const coff_symbol32 *CS32;
409 const coff_symbol16 *CS16 = nullptr;
410 const coff_symbol32 *CS32 = nullptr;
400411 };
401412
402413 struct coff_section {
417428 return (Characteristics & COFF::IMAGE_SCN_LNK_NRELOC_OVFL) &&
418429 NumberOfRelocations == UINT16_MAX;
419430 }
431
420432 uint32_t getAlignment() const {
421433 // The IMAGE_SCN_TYPE_NO_PAD bit is a legacy way of getting to
422434 // IMAGE_SCN_ALIGN_1BYTES.
507519 support::ulittle32_t SizeOfData;
508520 support::ulittle16_t OrdinalHint;
509521 support::ulittle16_t TypeInfo;
522
510523 int getType() const { return TypeInfo & 0x3; }
511524 int getNameType() const { return (TypeInfo >> 2) & 0x7; }
512525 };
517530 support::ulittle32_t ForwarderChain;
518531 support::ulittle32_t NameRVA;
519532 support::ulittle32_t ImportAddressTableRVA;
533
520534 bool isNull() const {
521535 return ImportLookupTableRVA == 0 && TimeDateStamp == 0 &&
522536 ForwarderChain == 0 && NameRVA == 0 && ImportAddressTableRVA == 0;
531545 IntTy AddressOfCallBacks;
532546 support::ulittle32_t SizeOfZeroFill;
533547 support::ulittle32_t Characteristics;
548
534549 uint32_t getAlignment() const {
535550 // Bit [20:24] contains section alignment.
536551 uint32_t Shift = (Characteristics & 0x00F00000) >> 20;
540555 }
541556 };
542557
543 typedef coff_tls_directory coff_tls_directory32;
544 typedef coff_tls_directory coff_tls_directory64;
558 using coff_tls_directory32 = coff_tls_directory;
559 using coff_tls_directory64 = coff_tls_directory;
545560
546561 struct coff_load_configuration32 {
547562 support::ulittle32_t Characteristics;
602617
603618 struct coff_base_reloc_block_entry {
604619 support::ulittle16_t Data;
620
605621 int getType() const { return Data >> 12; }
606622 int getOffset() const { return Data & ((1 << 12) - 1); }
607623 };
651667 return reinterpret_cast(SymbolTable32);
652668 return uintptr_t(0);
653669 }
670
654671 uint16_t getMachine() const {
655672 if (COFFHeader)
656673 return COFFHeader->Machine;
658675 return COFFBigObjHeader->Machine;
659676 llvm_unreachable("no COFF header!");
660677 }
678
661679 uint16_t getSizeOfOptionalHeader() const {
662680 if (COFFHeader)
663681 return COFFHeader->isImportLibrary() ? 0
667685 return 0;
668686 llvm_unreachable("no COFF header!");
669687 }
688
670689 uint16_t getCharacteristics() const {
671690 if (COFFHeader)
672691 return COFFHeader->isImportLibrary() ? 0 : COFFHeader->Characteristics;
676695 return 0;
677696 llvm_unreachable("no COFF header!");
678697 }
698
679699 uint32_t getTimeDateStamp() const {
680700 if (COFFHeader)
681701 return COFFHeader->TimeDateStamp;
683703 return COFFBigObjHeader->TimeDateStamp;
684704 llvm_unreachable("no COFF header!");
685705 }
706
686707 uint32_t getNumberOfSections() const {
687708 if (COFFHeader)
688709 return COFFHeader->isImportLibrary() ? 0 : COFFHeader->NumberOfSections;
690711 return COFFBigObjHeader->NumberOfSections;
691712 llvm_unreachable("no COFF header!");
692713 }
714
693715 uint32_t getPointerToSymbolTable() const {
694716 if (COFFHeader)
695717 return COFFHeader->isImportLibrary() ? 0
698720 return COFFBigObjHeader->PointerToSymbolTable;
699721 llvm_unreachable("no COFF header!");
700722 }
723
701724 uint32_t getRawNumberOfSymbols() const {
702725 if (COFFHeader)
703726 return COFFHeader->isImportLibrary() ? 0 : COFFHeader->NumberOfSymbols;
705728 return COFFBigObjHeader->NumberOfSymbols;
706729 llvm_unreachable("no COFF header!");
707730 }
731
708732 uint32_t getNumberOfSymbols() const {
709733 if (!SymbolTable16 && !SymbolTable32)
710734 return 0;
711735 return getRawNumberOfSymbols();
712736 }
737
713738 protected:
714739 void moveSymbolNext(DataRefImpl &Symb) const override;
715740 Expected getSymbolName(DataRefImpl Symb) const override;
745770
746771 public:
747772 COFFObjectFile(MemoryBufferRef Object, std::error_code &EC);
773
748774 basic_symbol_iterator symbol_begin() const override;
749775 basic_symbol_iterator symbol_end() const override;
750776 section_iterator section_begin() const override;
796822 std::error_code getDataDirectory(uint32_t index,
797823 const data_directory *&Res) const;
798824 std::error_code getSection(int32_t index, const coff_section *&Res) const;
825
799826 template
800827 std::error_code getSymbol(uint32_t Index,
801828 const coff_symbol_type *&Res) const {
820847 }
821848 return object_error::parse_failed;
822849 }
850
823851 template
824852 std::error_code getAuxSymbol(uint32_t index, const T *&Res) const {
825853 ErrorOr s = getSymbol(index);
828856 Res = reinterpret_cast(s->getRawPtr());
829857 return std::error_code();
830858 }
859
831860 std::error_code getSymbolName(COFFSymbolRef Symbol, StringRef &Res) const;
832861 std::error_code getSymbolName(const coff_symbol_generic *Symbol,
833862 StringRef &Res) const;
884913 // The iterator for the import directory table.
885914 class ImportDirectoryEntryRef {
886915 public:
887 ImportDirectoryEntryRef() : OwningObject(nullptr) {}
916 ImportDirectoryEntryRef() = default;
888917 ImportDirectoryEntryRef(const coff_import_directory_table_entry *Table,
889918 uint32_t I, const COFFObjectFile *Owner)
890919 : ImportTable(Table), Index(I), OwningObject(Owner) {}
910939 private:
911940 const coff_import_directory_table_entry *ImportTable;
912941 uint32_t Index;
913 const COFFObjectFile *OwningObject;
942 const COFFObjectFile *OwningObject = nullptr;
914943 };
915944
916945 class DelayImportDirectoryEntryRef {
917946 public:
918 DelayImportDirectoryEntryRef() : OwningObject(nullptr) {}
947 DelayImportDirectoryEntryRef() = default;
919948 DelayImportDirectoryEntryRef(const delay_import_directory_table_entry *T,
920949 uint32_t I, const COFFObjectFile *Owner)
921950 : Table(T), Index(I), OwningObject(Owner) {}
935964 private:
936965 const delay_import_directory_table_entry *Table;
937966 uint32_t Index;
938 const COFFObjectFile *OwningObject;
967 const COFFObjectFile *OwningObject = nullptr;
939968 };
940969
941970 // The iterator for the export directory table entry.
942971 class ExportDirectoryEntryRef {
943972 public:
944 ExportDirectoryEntryRef() : OwningObject(nullptr) {}
973 ExportDirectoryEntryRef() = default;
945974 ExportDirectoryEntryRef(const export_directory_table_entry *Table, uint32_t I,
946975 const COFFObjectFile *Owner)
947976 : ExportTable(Table), Index(I), OwningObject(Owner) {}
961990 private:
962991 const export_directory_table_entry *ExportTable;
963992 uint32_t Index;
964 const COFFObjectFile *OwningObject;
993 const COFFObjectFile *OwningObject = nullptr;
965994 };
966995
967996 class ImportedSymbolRef {
968997 public:
969 ImportedSymbolRef() : OwningObject(nullptr) {}
998 ImportedSymbolRef() = default;
970999 ImportedSymbolRef(const import_lookup_table_entry32 *Entry, uint32_t I,
9711000 const COFFObjectFile *Owner)
9721001 : Entry32(Entry), Entry64(nullptr), Index(I), OwningObject(Owner) {}
9861015 const import_lookup_table_entry32 *Entry32;
9871016 const import_lookup_table_entry64 *Entry64;
9881017 uint32_t Index;
989 const COFFObjectFile *OwningObject;
1018 const COFFObjectFile *OwningObject = nullptr;
9901019 };
9911020
9921021 class BaseRelocRef {
9931022 public:
994 BaseRelocRef() : OwningObject(nullptr) {}
1023 BaseRelocRef() = default;
9951024 BaseRelocRef(const coff_base_reloc_block_header *Header,
9961025 const COFFObjectFile *Owner)
9971026 : Header(Header), Index(0), OwningObject(Owner) {}
10051034 private:
10061035 const coff_base_reloc_block_header *Header;
10071036 uint32_t Index;
1008 const COFFObjectFile *OwningObject;
1037 const COFFObjectFile *OwningObject = nullptr;
10091038 };
10101039
10111040 // Corresponds to `_FPO_DATA` structure in the PE/COFF spec.
10331062 };
10341063
10351064 } // end namespace object
1065
10361066 } // end namespace llvm
10371067
1038 #endif
1068 #endif // LLVM_OBJECT_COFF_H
1313 #ifndef LLVM_OBJECT_OBJECTFILE_H
1414 #define LLVM_OBJECT_OBJECTFILE_H
1515
16 #include "llvm/ADT/iterator_range.h"
1617 #include "llvm/ADT/StringRef.h"
1718 #include "llvm/MC/SubtargetFeature.h"
19 #include "llvm/Object/Binary.h"
20 #include "llvm/Object/Error.h"
1821 #include "llvm/Object/SymbolicFile.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/Error.h"
24 #include "llvm/Support/ErrorOr.h"
2125 #include "llvm/Support/FileSystem.h"
2226 #include "llvm/Support/MemoryBuffer.h"
23 #include string>
27 #include assert>
28 #include
29 #include
30 #include
2431
2532 namespace llvm {
33
2634 class ARMAttributeParser;
2735
2836 namespace object {
2937
30 class ObjectFile;
3138 class COFFObjectFile;
3239 class MachOObjectFile;
33 class WasmObjectFile;
34
40 class ObjectFile;
41 class SectionRef;
3542 class SymbolRef;
3643 class symbol_iterator;
37 class SectionRef;
38 typedef content_iterator section_iterator;
44 class WasmObjectFile;
45
46 using section_iterator = content_iterator;
3947
4048 /// This is a value type class that represents a single relocation in the list
4149 /// of relocations in the object file.
4250 class RelocationRef {
4351 DataRefImpl RelocationPimpl;
44 const ObjectFile *OwningObject;
52 const ObjectFile *OwningObject = nullptr;
4553
4654 public:
47 RelocationRef() : OwningObject(nullptr) { }
48
55 RelocationRef() = default;
4956 RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
5057
5158 bool operator==(const RelocationRef &Other) const;
6471 DataRefImpl getRawDataRefImpl() const;
6572 const ObjectFile *getObject() const;
6673 };
67 typedef content_iterator relocation_iterator;
74
75 using relocation_iterator = content_iterator;
6876
6977 /// This is a value type class that represents a single section in the list of
7078 /// sections in the object file.
7179 class SectionRef {
7280 friend class SymbolRef;
81
7382 DataRefImpl SectionPimpl;
74 const ObjectFile *OwningObject;
83 const ObjectFile *OwningObject = nullptr;
7584
7685 public:
77 SectionRef() : OwningObject(nullptr) { }
78
86 SectionRef() = default;
7987 SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
8088
8189 bool operator==(const SectionRef &Other) const;
118126 friend class SectionRef;
119127
120128 public:
121 SymbolRef() : BasicSymbolRef() {}
122
123129 enum Type {
124130 ST_Unknown, // Type not specified
125131 ST_Data,
129135 ST_Other
130136 };
131137
138 SymbolRef() = default;
132139 SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
133140 SymbolRef(const BasicSymbolRef &B) : BasicSymbolRef(B) {
134141 assert(isa(BasicSymbolRef::getObject()));
178185 /// to create.
179186 class ObjectFile : public SymbolicFile {
180187 virtual void anchor();
181 ObjectFile() = delete;
182 ObjectFile(const ObjectFile &other) = delete;
183188
184189 protected:
185190 ObjectFile(unsigned int Type, MemoryBufferRef Source);
197202 // Implementations assume that the DataRefImpl is valid and has not been
198203 // modified externally. It's UB otherwise.
199204 friend class SymbolRef;
205
200206 virtual Expected getSymbolName(DataRefImpl Symb) const = 0;
201207 std::error_code printSymbolName(raw_ostream &OS,
202208 DataRefImpl Symb) const override;
210216
211217 // Same as above for SectionRef.
212218 friend class SectionRef;
219
213220 virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
214221 virtual std::error_code getSectionName(DataRefImpl Sec,
215222 StringRef &Res) const = 0;
241248 uint64_t getSymbolValue(DataRefImpl Symb) const;
242249
243250 public:
251 ObjectFile() = delete;
252 ObjectFile(const ObjectFile &other) = delete;
253
244254 uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
245255 assert(getSymbolFlags(Symb) & SymbolRef::SF_Common);
246256 return getCommonSymbolSizeImpl(Symb);
247257 }
248258
249 typedef iterator_range symbol_iterator_range;
259 using symbol_iterator_range = iterator_range;
250260 symbol_iterator_range symbols() const {
251261 return symbol_iterator_range(symbol_begin(), symbol_end());
252262 }
254264 virtual section_iterator section_begin() const = 0;
255265 virtual section_iterator section_end() const = 0;
256266
257 typedef iterator_range section_iterator_range;
267 using section_iterator_range = iterator_range;
258268 section_iterator_range sections() const {
259269 return section_iterator_range(section_begin(), section_end());
260270 }
296306 return createObjectFile(Object, sys::fs::file_magic::unknown);
297307 }
298308
299
300309 static inline bool classof(const Binary *v) {
301310 return v->isObject();
302311 }
352361 const SymbolicFile *O = BasicSymbolRef::getObject();
353362 return cast(O);
354363 }
355
356364
357365 /// SectionRef
358366 inline SectionRef::SectionRef(DataRefImpl SectionP,
478486 return OwningObject;
479487 }
480488
481
482489 } // end namespace object
490
483491 } // end namespace llvm
484492
485 #endif
493 #endif // LLVM_OBJECT_OBJECTFILE_H
1313 #ifndef LLVM_OBJECT_SYMBOLICFILE_H
1414 #define LLVM_OBJECT_SYMBOLICFILE_H
1515
16 #include "llvm/ADT/iterator_range.h"
17 #include "llvm/ADT/StringRef.h"
1618 #include "llvm/Object/Binary.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/FileSystem.h"
1721 #include "llvm/Support/Format.h"
22 #include "llvm/Support/MemoryBuffer.h"
1823 #include
19 #include <utility>
24 #include <cstdint>
25 #include
26 #include
27 #include
28 #include
2029
2130 namespace llvm {
2231 namespace object {
2837 uint32_t a, b;
2938 } d;
3039 uintptr_t p;
40
3141 DataRefImpl() { std::memset(this, 0, sizeof(DataRefImpl)); }
3242 };
3343
8696 /// symbols in the object file.
8797 class BasicSymbolRef {
8898 DataRefImpl SymbolPimpl;
89 const SymbolicFile *OwningObject;
99 const SymbolicFile *OwningObject = nullptr;
90100
91101 public:
92102 enum Flags : unsigned {
107117 // (IR only)
108118 };
109119
110 BasicSymbolRef() : OwningObject(nullptr) { }
120 BasicSymbolRef() = default;
111121 BasicSymbolRef(DataRefImpl SymbolP, const SymbolicFile *Owner);
112122
113123 bool operator==(const BasicSymbolRef &Other) const;
124134 const SymbolicFile *getObject() const;
125135 };
126136
127 typedef content_iterator basic_symbol_iterator;
137 using basic_symbol_iterator = content_iterator;
128138
129139 class SymbolicFile : public Binary {
130140 public:
141 SymbolicFile(unsigned int Type, MemoryBufferRef Source);
131142 ~SymbolicFile() override;
132 SymbolicFile(unsigned int Type, MemoryBufferRef Source);
133143
134144 // virtual interface.
135145 virtual void moveSymbolNext(DataRefImpl &Symb) const = 0;
144154 virtual basic_symbol_iterator symbol_end() const = 0;
145155
146156 // convenience wrappers.
147 typedef iterator_range basic_symbol_iterator_range;
157 using basic_symbol_iterator_range = iterator_range;
148158 basic_symbol_iterator_range symbols() const {
149159 return basic_symbol_iterator_range(symbol_begin(), symbol_end());
150160 }
198208 return OwningObject;
199209 }
200210
201 }
202 }
203
204 #endif
211 } // end namespace object
212 } // end namespace llvm
213
214 #endif // LLVM_OBJECT_SYMBOLICFILE_H
None //===- Archive.cpp - ar File Format implementation --------------*- C++ -*-===//
0 //===- Archive.cpp - ar File Format implementation ------------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/Twine.h"
1317 #include "llvm/Object/Archive.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/Twine.h"
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Object/Error.h"
20 #include "llvm/Support/Chrono.h"
1621 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/ErrorOr.h"
24 #include "llvm/Support/FileSystem.h"
1725 #include "llvm/Support/MemoryBuffer.h"
1826 #include "llvm/Support/Path.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include
29 #include
30 #include
31 #include
32 #include
33 #include
34 #include
35 #include
1936
2037 using namespace llvm;
2138 using namespace object;
2441 static const char *const Magic = "!\n";
2542 static const char *const ThinMagic = "!\n";
2643
27 void Archive::anchor() { }
44 void Archive::anchor() {}
2845
2946 static Error
3047 malformedError(Twine Msg) {
6077 if (Err) {
6178 std::string Buf;
6279 raw_string_ostream OS(Buf);
63 OS.write_escaped(llvm::StringRef(ArMemHdr->Terminator,
64 sizeof(ArMemHdr->Terminator)));
80 OS.write_escaped(StringRef(ArMemHdr->Terminator,
81 sizeof(ArMemHdr->Terminator)));
6582 OS.flush();
6683 std::string Msg("terminator characters in archive member \"" + Buf +
6784 "\" not the correct \"`\\n\" values for the archive "
96113 EndCond = ' ';
97114 else
98115 EndCond = '/';
99 llvm::StringRef::size_type end =
100 llvm::StringRef(ArMemHdr->Name, sizeof(ArMemHdr->Name)).find(EndCond);
101 if (end == llvm::StringRef::npos)
116 StringRef::size_type end =
117 StringRef(ArMemHdr->Name, sizeof(ArMemHdr->Name)).find(EndCond);
118 if (end == StringRef::npos)
102119 end = sizeof(ArMemHdr->Name);
103120 assert(end <= sizeof(ArMemHdr->Name) && end > 0);
104121 // Don't include the EndCond if there is one.
105 return llvm::StringRef(ArMemHdr->Name, end);
122 return StringRef(ArMemHdr->Name, end);
106123 }
107124
108125 // This gets the name looking up long names. Size is the size of the archive
204221
205222 Expected ArchiveMemberHeader::getSize() const {
206223 uint32_t Ret;
207 if (llvm::StringRef(ArMemHdr->Size,
208 sizeof(ArMemHdr->Size)).rtrim(" ").getAsInteger(10, Ret)) {
224 if (StringRef(ArMemHdr->Size,
225 sizeof(ArMemHdr->Size)).rtrim(" ").getAsInteger(10, Ret)) {
209226 std::string Buf;
210227 raw_string_ostream OS(Buf);
211 OS.write_escaped(llvm::StringRef(ArMemHdr->Size,
212 sizeof(ArMemHdr->Size)).rtrim(" "));
228 OS.write_escaped(StringRef(ArMemHdr->Size,
229 sizeof(ArMemHdr->Size)).rtrim(" "));
213230 OS.flush();
214231 uint64_t Offset = reinterpret_cast(ArMemHdr) -
215232 Parent->getData().data();
226243 sizeof(ArMemHdr->AccessMode)).rtrim(' ').getAsInteger(8, Ret)) {
227244 std::string Buf;
228245 raw_string_ostream OS(Buf);
229 OS.write_escaped(llvm::StringRef(ArMemHdr->AccessMode,
230 sizeof(ArMemHdr->AccessMode)).rtrim(" "));
246 OS.write_escaped(StringRef(ArMemHdr->AccessMode,
247 sizeof(ArMemHdr->AccessMode)).rtrim(" "));
231248 OS.flush();
232249 uint64_t Offset = reinterpret_cast(ArMemHdr) -
233250 Parent->getData().data();
246263 .getAsInteger(10, Seconds)) {
247264 std::string Buf;
248265 raw_string_ostream OS(Buf);
249 OS.write_escaped(llvm::StringRef(ArMemHdr->LastModified,
250 sizeof(ArMemHdr->LastModified)).rtrim(" "));
266 OS.write_escaped(StringRef(ArMemHdr->LastModified,
267 sizeof(ArMemHdr->LastModified)).rtrim(" "));
251268 OS.flush();
252269 uint64_t Offset = reinterpret_cast(ArMemHdr) -
253270 Parent->getData().data();
None //===- Binary.cpp - A generic binary file -----------------------*- C++ -*-===//
0 //===- Binary.cpp - A generic binary file ---------------------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Object/Archive.h"
1315 #include "llvm/Object/Binary.h"
14 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Object/Error.h"
17 #include "llvm/Object/MachOUniversal.h"
18 #include "llvm/Object/ObjectFile.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/ErrorOr.h"
1522 #include "llvm/Support/FileSystem.h"
1623 #include "llvm/Support/MemoryBuffer.h"
17 #include "llvm/Support/Path.h"
18
19 // Include headers for createBinary.
20 #include "llvm/Object/Archive.h"
21 #include "llvm/Object/MachOUniversal.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include
25 #include
26 #include
2327
2428 using namespace llvm;
2529 using namespace object;
2630
27 Binary::~Binary() {}
31 Binary::~Binary() = default;
2832
2933 Binary::Binary(unsigned int Type, MemoryBufferRef Source)
3034 : TypeID(Type), Data(Source) {}
None //===- COFFObjectFile.cpp - COFF object file implementation -----*- C++ -*-===//
0 //===- COFFObjectFile.cpp - COFF object file implementation ---------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Object/COFF.h"
1413 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringSwitch.h"
14 #include "llvm/ADT/StringRef.h"
1615 #include "llvm/ADT/Triple.h"
1716 #include "llvm/ADT/iterator_range.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Object/COFF.h"
19 #include "llvm/Object/Error.h"
20 #include "llvm/Object/ObjectFile.h"
1821 #include "llvm/Support/COFF.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include
22 #include "llvm/Support/Endian.h"
23 #include "llvm/Support/Error.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/MathExtras.h"
26 #include "llvm/Support/MemoryBuffer.h"
27 #include
28 #include
29 #include
30 #include
31 #include
2232 #include
33 #include
34 #include
2335
2436 using namespace llvm;
2537 using namespace object;
115127 const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
116128 const coff_section *Addr = reinterpret_cast(Ref.p);
117129
118 # ifndef NDEBUG
130 #ifndef NDEBUG
119131 // Verify that the section points to a valid entry in the section table.
120132 if (Addr < SectionTable || Addr >= (SectionTable + getNumberOfSections()))
121133 report_fatal_error("Section was outside of section table.");
123135 uintptr_t Offset = uintptr_t(Addr) - uintptr_t(SectionTable);
124136 assert(Offset % sizeof(coff_section) == 0 &&
125137 "Section did not point to the beginning of a section");
126 # endif
138 #endif
127139
128140 return Addr;
129141 }
984996 if (Symbol.getNumberOfAuxSymbols() > 0) {
985997 // AUX data comes immediately after the symbol in COFF
986998 Aux = reinterpret_cast(Symbol.getRawPtr()) + SymbolSize;
987 # ifndef NDEBUG
999 #ifndef NDEBUG
9881000 // Verify that the Aux symbol points to a valid entry in the symbol table.
9891001 uintptr_t Offset = uintptr_t(Aux) - uintptr_t(base());
9901002 if (Offset < getPointerToSymbolTable() ||
9941006
9951007 assert((Offset - getPointerToSymbolTable()) % SymbolSize == 0 &&
9961008 "Aux Symbol data did not point to the beginning of a symbol");
997 # endif
1009 #endif
9981010 }
9991011 return makeArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize);
10001012 }
None //===- ObjectFile.cpp - File format independent object file -----*- C++ -*-===//
0 //===- ObjectFile.cpp - File format independent object file ---------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Object/Binary.h"
15 #include "llvm/Object/COFF.h"
16 #include "llvm/Object/Error.h"
17 #include "llvm/Object/MachO.h"
1318 #include "llvm/Object/ObjectFile.h"
14 #include "llvm/Object/COFF.h"
15 #include "llvm/Object/MachO.h"
1619 #include "llvm/Object/Wasm.h"
20 #include "llvm/Support/Error.h"
1721 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/ErrorOr.h"
1823 #include "llvm/Support/FileSystem.h"
1924 #include "llvm/Support/MemoryBuffer.h"
2025 #include "llvm/Support/raw_ostream.h"
26 #include
27 #include
28 #include
2129 #include
2230
2331 using namespace llvm;
2432 using namespace object;
2533
26 void ObjectFile::anchor() { }
34 void ObjectFile::anchor() {}
2735
2836 ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source)
2937 : SymbolicFile(Type, Source) {}
None //===- SymbolicFile.cpp - Interface that only provides symbols --*- C++ -*-===//
0 //===- SymbolicFile.cpp - Interface that only provides symbols ------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Object/COFF.h"
13 #include "llvm/ADT/StringRef.h"
1414 #include "llvm/Object/COFFImportFile.h"
15 #include "llvm/Object/Error.h"
1516 #include "llvm/Object/IRObjectFile.h"
1617 #include "llvm/Object/ObjectFile.h"
1718 #include "llvm/Object/SymbolicFile.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/Error.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/ErrorOr.h"
23 #include "llvm/Support/FileSystem.h"
1824 #include "llvm/Support/MemoryBuffer.h"
25 #include
26 #include
1927
2028 using namespace llvm;
2129 using namespace object;
2331 SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source)
2432 : Binary(Type, Source) {}
2533
26 SymbolicFile::~SymbolicFile() {}
34 SymbolicFile::~SymbolicFile() = default;
2735
2836 Expected> SymbolicFile::createSymbolicFile(
2937 MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context) {