llvm.org GIT mirror llvm / c581c4f
[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@301275 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 3 years ago
12 changed file(s) with 296 addition(s) and 198 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_OBJECT_ELF_H
1414 #define LLVM_OBJECT_ELF_H
1515
16 #include "llvm/ADT/ArrayRef.h"
1617 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
1719 #include "llvm/Object/ELFTypes.h"
18 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Object/Error.h"
21 #include "llvm/Support/ELF.h"
22 #include "llvm/Support/Endian.h"
23 #include "llvm/Support/Error.h"
24 #include
25 #include
26 #include
27 #include
28 #include
1929
2030 namespace llvm {
2131 namespace object {
4050 class ELFFile {
4151 public:
4252 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
43 typedef typename ELFT::uint uintX_t;
44 typedef typename ELFT::Ehdr Elf_Ehdr;
45 typedef typename ELFT::Shdr Elf_Shdr;
46 typedef typename ELFT::Sym Elf_Sym;
47 typedef typename ELFT::Dyn Elf_Dyn;
48 typedef typename ELFT::Phdr Elf_Phdr;
49 typedef typename ELFT::Rel Elf_Rel;
50 typedef typename ELFT::Rela Elf_Rela;
51 typedef typename ELFT::Verdef Elf_Verdef;
52 typedef typename ELFT::Verdaux Elf_Verdaux;
53 typedef typename ELFT::Verneed Elf_Verneed;
54 typedef typename ELFT::Vernaux Elf_Vernaux;
55 typedef typename ELFT::Versym Elf_Versym;
56 typedef typename ELFT::Hash Elf_Hash;
57 typedef typename ELFT::GnuHash Elf_GnuHash;
58 typedef typename ELFT::DynRange Elf_Dyn_Range;
59 typedef typename ELFT::ShdrRange Elf_Shdr_Range;
60 typedef typename ELFT::SymRange Elf_Sym_Range;
61 typedef typename ELFT::RelRange Elf_Rel_Range;
62 typedef typename ELFT::RelaRange Elf_Rela_Range;
63 typedef typename ELFT::PhdrRange Elf_Phdr_Range;
53 using uintX_t = typename ELFT::uint;
54 using Elf_Ehdr = typename ELFT::Ehdr;
55 using Elf_Shdr = typename ELFT::Shdr;
56 using Elf_Sym = typename ELFT::Sym;
57 using Elf_Dyn = typename ELFT::Dyn;
58 using Elf_Phdr = typename ELFT::Phdr;
59 using Elf_Rel = typename ELFT::Rel;
60 using Elf_Rela = typename ELFT::Rela;
61 using Elf_Verdef = typename ELFT::Verdef;
62 using Elf_Verdaux = typename ELFT::Verdaux;
63 using Elf_Verneed = typename ELFT::Verneed;
64 using Elf_Vernaux = typename ELFT::Vernaux;
65 using Elf_Versym = typename ELFT::Versym;
66 using Elf_Hash = typename ELFT::Hash;
67 using Elf_GnuHash = typename ELFT::GnuHash;
68 using Elf_Dyn_Range = typename ELFT::DynRange;
69 using Elf_Shdr_Range = typename ELFT::ShdrRange;
70 using Elf_Sym_Range = typename ELFT::SymRange;
71 using Elf_Rel_Range = typename ELFT::RelRange;
72 using Elf_Rela_Range = typename ELFT::RelaRange;
73 using Elf_Phdr_Range = typename ELFT::PhdrRange;
6474
6575 const uint8_t *base() const {
6676 return reinterpret_cast(Buf.data());
6979 size_t getBufSize() const { return Buf.size(); }
7080
7181 private:
72
7382 StringRef Buf;
7483
7584 public:
160169 Expected> getSectionContents(const Elf_Shdr *Sec) const;
161170 };
162171
163 typedef ELFFile> ELF32LEFile;
164 typedef ELFFile> ELF64LEFile;
165 typedef ELFFile> ELF32BEFile;
166 typedef ELFFile> ELF64BEFile;
172 using ELF32LEFile = ELFFile>;
173 using ELF64LEFile = ELFFile>;
174 using ELF32BEFile = ELFFile>;
175 using ELF64BEFile = ELFFile>;
167176
168177 template
169178 inline Expected
193202 ArrayRef ShndxTable) const {
194203 uint32_t Index = Sym->st_shndx;
195204 if (Index == ELF::SHN_XINDEX) {
196 auto ErrorOrIndex = object::getExtendedSymbolTableIndex(
205 auto ErrorOrIndex = getExtendedSymbolTableIndex(
197206 Sym, Syms.begin(), ShndxTable);
198207 if (!ErrorOrIndex)
199208 return ErrorOrIndex.takeError();
518527 }
519528 return h;
520529 }
530
521531 } // end namespace object
522532 } // end namespace llvm
523533
524 #endif
534 #endif // LLVM_OBJECT_ELF_H
2626 #include "llvm/Object/ObjectFile.h"
2727 #include "llvm/Object/SymbolicFile.h"
2828 #include "llvm/Support/ARMAttributeParser.h"
29 #include "llvm/Support/ARMBuildAttributes.h"
2930 #include "llvm/Support/Casting.h"
3031 #include "llvm/Support/ELF.h"
3132 #include "llvm/Support/Endian.h"
4142 namespace object {
4243
4344 class elf_symbol_iterator;
44 class ELFSymbolRef;
45 class ELFRelocationRef;
4645
4746 class ELFObjectFileBase : public ObjectFile {
47 friend class ELFRelocationRef;
48 friend class ELFSectionRef;
4849 friend class ELFSymbolRef;
49 friend class ELFSectionRef;
50 friend class ELFRelocationRef;
5150
5251 protected:
5352 ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source);
6463 virtual ErrorOr getRelocationAddend(DataRefImpl Rel) const = 0;
6564
6665 public:
67 typedef iterator_range elf_symbol_iterator_range;
66 using elf_symbol_iterator_range = iterator_range;
67
6868 virtual elf_symbol_iterator_range getDynamicSymbolIterators() const = 0;
6969
7070 elf_symbol_iterator_range symbols() const;
200200 public:
201201 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
202202
203 typedef typename ELFFile::uintX_t uintX_t;
204
205 typedef typename ELFFile::Elf_Sym Elf_Sym;
206 typedef typename ELFFile::Elf_Shdr Elf_Shdr;
207 typedef typename ELFFile::Elf_Ehdr Elf_Ehdr;
208 typedef typename ELFFile::Elf_Rel Elf_Rel;
209 typedef typename ELFFile::Elf_Rela Elf_Rela;
210 typedef typename ELFFile::Elf_Dyn Elf_Dyn;
203 using uintX_t = typename ELFFile::uintX_t;
204
205 using Elf_Sym = typename ELFFile::Elf_Sym;
206 using Elf_Shdr = typename ELFFile::Elf_Shdr;
207 using Elf_Ehdr = typename ELFFile::Elf_Ehdr;
208 using Elf_Rel = typename ELFFile::Elf_Rel;
209 using Elf_Rela = typename ELFFile::Elf_Rela;
210 using Elf_Dyn = typename ELFFile::Elf_Dyn;
211211
212212 protected:
213213 ELFFile EF;
397397 bool isRelocatableObject() const override;
398398 };
399399
400 typedef ELFObjectFile> ELF32LEObjectFile;
401 typedef ELFObjectFile> ELF64LEObjectFile;
402 typedef ELFObjectFile> ELF32BEObjectFile;
403 typedef ELFObjectFile> ELF64BEObjectFile;
400 using ELF32LEObjectFile = ELFObjectFile>;
401 using ELF64LEObjectFile = ELFObjectFile>;
402 using ELF32BEObjectFile = ELFObjectFile>;
403 using ELF64BEObjectFile = ELFObjectFile>;
404404
405405 template
406406 void ELFObjectFile::moveSymbolNext(DataRefImpl &Sym) const {
1010 #define LLVM_OBJECT_ELFTYPES_H
1111
1212 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
1314 #include "llvm/Object/Error.h"
1415 #include "llvm/Support/ELF.h"
1516 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/ErrorOr.h"
17 #include "llvm/Support/Error.h"
18 #include
19 #include
20 #include
21 #include
1722
1823 namespace llvm {
1924 namespace object {
4449 static const endianness TargetEndianness = E;
4550 static const bool Is64Bits = Is64;
4651
47 typedef typename std::conditional::type uint;
48 typedef Elf_Ehdr_Impl> Ehdr;
49 typedef Elf_Shdr_Impl> Shdr;
50 typedef Elf_Sym_Impl> Sym;
51 typedef Elf_Dyn_Impl> Dyn;
52 typedef Elf_Phdr_Impl> Phdr;
53 typedef Elf_Rel_Impl, false> Rel;
54 typedef Elf_Rel_Impl, true> Rela;
55 typedef Elf_Verdef_Impl> Verdef;
56 typedef Elf_Verdaux_Impl> Verdaux;
57 typedef Elf_Verneed_Impl> Verneed;
58 typedef Elf_Vernaux_Impl> Vernaux;
59 typedef Elf_Versym_Impl> Versym;
60 typedef Elf_Hash_Impl> Hash;
61 typedef Elf_GnuHash_Impl> GnuHash;
62 typedef Elf_Chdr_Impl> Chdr;
63 typedef ArrayRef DynRange;
64 typedef ArrayRef ShdrRange;
65 typedef ArrayRef SymRange;
66 typedef ArrayRef RelRange;
67 typedef ArrayRef RelaRange;
68 typedef ArrayRef PhdrRange;
69
70 typedef packed Half;
71 typedef packed Word;
72 typedef packed Sword;
73 typedef packed Xword;
74 typedef packed Sxword;
75 typedef packed Addr;
76 typedef packed Off;
77 };
78
79 typedef ELFType ELF32LE;
80 typedef ELFType ELF32BE;
81 typedef ELFType ELF64LE;
82 typedef ELFType ELF64BE;
52 using uint = typename std::conditional::type;
53 using Ehdr = Elf_Ehdr_Impl>;
54 using Shdr = Elf_Shdr_Impl>;
55 using Sym = Elf_Sym_Impl>;
56 using Dyn = Elf_Dyn_Impl>;
57 using Phdr = Elf_Phdr_Impl>;
58 using Rel = Elf_Rel_Impl, false>;
59 using Rela = Elf_Rel_Impl, true>;
60 using Verdef = Elf_Verdef_Impl>;
61 using Verdaux = Elf_Verdaux_Impl>;
62 using Verneed = Elf_Verneed_Impl>;
63 using Vernaux = Elf_Vernaux_Impl>;
64 using Versym = Elf_Versym_Impl>;
65 using Hash = Elf_Hash_Impl>;
66 using GnuHash = Elf_GnuHash_Impl>;
67 using Chdr = Elf_Chdr_Impl>;
68 using DynRange = ArrayRef;
69 using ShdrRange = ArrayRef;
70 using SymRange = ArrayRef;
71 using RelRange = ArrayRef;
72 using RelaRange = ArrayRef;
73 using PhdrRange = ArrayRef;
74
75 using Half = packed;
76 using Word = packed;
77 using Sword = packed;
78 using Xword = packed;
79 using Sxword = packed;
80 using Addr = packed;
81 using Off = packed;
82 };
83
84 using ELF32LE = ELFType;
85 using ELF32BE = ELFType;
86 using ELF64LE = ELFType;
87 using ELF64BE = ELFType;
8388
8489 // Use an alignment of 2 for the typedefs since that is the worst case for
8590 // ELF files in archives.
8691
8792 // Templates to choose Elf_Addr and Elf_Off depending on is64Bits.
8893 template struct ELFDataTypeTypedefHelperCommon {
89 typedef support::detail::packed_endian_specific_integral<
90 uint16_t, target_endianness, 2> Elf_Half;
91 typedef support::detail::packed_endian_specific_integral<
92 uint32_t, target_endianness, 2> Elf_Word;
93 typedef support::detail::packed_endian_specific_integral<
94 int32_t, target_endianness, 2> Elf_Sword;
95 typedef support::detail::packed_endian_specific_integral<
96 uint64_t, target_endianness, 2> Elf_Xword;
97 typedef support::detail::packed_endian_specific_integral<
98 int64_t, target_endianness, 2> Elf_Sxword;
94 using Elf_Half = support::detail::packed_endian_specific_integral<
95 uint16_t, target_endianness, 2>;
96 using Elf_Word = support::detail::packed_endian_specific_integral<
97 uint32_t, target_endianness, 2>;
98 using Elf_Sword = support::detail::packed_endian_specific_integral<
99 int32_t, target_endianness, 2>;
100 using Elf_Xword = support::detail::packed_endian_specific_integral<
101 uint64_t, target_endianness, 2>;
102 using Elf_Sxword = support::detail::packed_endian_specific_integral<
103 int64_t, target_endianness, 2>;
99104 };
100105
101106 template struct ELFDataTypeTypedefHelper;
104109 template
105110 struct ELFDataTypeTypedefHelper>
106111 : ELFDataTypeTypedefHelperCommon {
107 typedef uint32_t value_type;
108 typedef support::detail::packed_endian_specific_integral<
109 value_type, TargetEndianness, 2> Elf_Addr;
110 typedef support::detail::packed_endian_specific_integral<
111 value_type, TargetEndianness, 2> Elf_Off;
112 using value_type = uint32_t;
113 using Elf_Addr = support::detail::packed_endian_specific_integral<
114 value_type, TargetEndianness, 2>;
115 using Elf_Off = support::detail::packed_endian_specific_integral<
116 value_type, TargetEndianness, 2>;
112117 };
113118
114119 /// ELF 64bit types.
115120 template
116121 struct ELFDataTypeTypedefHelper>
117122 : ELFDataTypeTypedefHelperCommon {
118 typedef uint64_t value_type;
119 typedef support::detail::packed_endian_specific_integral<
120 value_type, TargetEndianness, 2> Elf_Addr;
121 typedef support::detail::packed_endian_specific_integral<
122 value_type, TargetEndianness, 2> Elf_Off;
123 using value_type = uint64_t;
124 using Elf_Addr = support::detail::packed_endian_specific_integral<
125 value_type, TargetEndianness, 2>;
126 using Elf_Off = support::detail::packed_endian_specific_integral<
127 value_type, TargetEndianness, 2>;
123128 };
124129
125130 // I really don't like doing this, but the alternative is copypasta.
126131
127132 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
128 typedef typename ELFT::Addr Elf_Addr; \
129 typedef typename ELFT::Off Elf_Off; \
130 typedef typename ELFT::Half Elf_Half; \
131 typedef typename ELFT::Word Elf_Word; \
132 typedef typename ELFT::Sword Elf_Sword; \
133 typedef typename ELFT::Xword Elf_Xword; \
134 typedef typename ELFT::Sxword Elf_Sxword;
133 using Elf_Addr = typename ELFT::Addr; \
134 using Elf_Off = typename ELFT::Off; \
135 using Elf_Half = typename ELFT::Half; \
136 using Elf_Word = typename ELFT::Word; \
137 using Elf_Sword = typename ELFT::Sword; \
138 using Elf_Xword = typename ELFT::Xword; \
139 using Elf_Sxword = typename ELFT::Sxword;
135140
136141 #define LLD_ELF_COMMA ,
137142 #define LLVM_ELF_IMPORT_TYPES(E, W) \
221226 uint64_t getValue() const { return st_value; }
222227 void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
223228 void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
229
224230 void setBindingAndType(unsigned char b, unsigned char t) {
225231 st_info = (b << 4) + (t & 0x0f);
226232 }
237243 }
238244
239245 bool isAbsolute() const { return st_shndx == ELF::SHN_ABS; }
246
240247 bool isCommon() const {
241248 return getType() == ELF::STT_COMMON || st_shndx == ELF::SHN_COMMON;
242249 }
250
243251 bool isDefined() const { return !isUndefined(); }
252
244253 bool isProcessorSpecific() const {
245254 return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC;
246255 }
256
247257 bool isOSSpecific() const {
248258 return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS;
249259 }
260
250261 bool isReserved() const {
251262 // ELF::SHN_HIRESERVE is 0xffff so st_shndx <= ELF::SHN_HIRESERVE is always
252263 // true and some compilers warn about it.
253264 return st_shndx >= ELF::SHN_LORESERVE;
254265 }
266
255267 bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; }
268
256269 bool isExternal() const {
257270 return getBinding() != ELF::STB_LOCAL;
258271 }
276289 Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
277290 };
278291
279 template struct Elf_Verdaux_Impl;
280
281292 /// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
282293 /// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
283294 template
284295 struct Elf_Verdef_Impl {
285296 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
286 typedef Elf_Verdaux_Impl Elf_Verdaux;
297 using Elf_Verdaux = Elf_Verdaux_Impl;
287298 Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
288299 Elf_Half vd_flags; // Bitwise flags (VER_DEF_*)
289300 Elf_Half vd_ndx; // Version index, used in .gnu.version entries
360371 struct Elf_Dyn_Impl : Elf_Dyn_Base {
361372 using Elf_Dyn_Base::d_tag;
362373 using Elf_Dyn_Base::d_un;
363 typedef typename std::conditional
364 int64_t, int32_t>::type intX_t;
365 typedef typename std::conditional
366 uint64_t, uint32_t>::type uintX_t;
374 using intX_t = typename std::conditional
375 int64_t, int32_t>::type;
376 using uintX_t = typename std::conditional
377 uint64_t, uint32_t>::type;
367378 intX_t getTag() const { return d_tag; }
368379 uintX_t getVal() const { return d_un.d_val; }
369380 uintX_t getPtr() const { return d_un.d_ptr; }
429440 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
430441 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
431442 }
443
432444 void setRInfo(uint64_t R, bool IsMips64EL) {
433445 if (IsMips64EL)
434446 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
482494 Elf_Half e_shnum; // Number of entries in the section header table
483495 Elf_Half e_shstrndx; // Section header table index of section name
484496 // string table
497
485498 bool checkMagic() const {
486499 return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
487500 }
501
488502 unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
489503 unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
490504 };
491
492 template struct Elf_Phdr_Impl;
493505
494506 template
495507 struct Elf_Phdr_Impl> {
581593 template
582594 struct Elf_Mips_RegInfo;
583595
584 template <llvm::support::endianness TargetEndianness>
596 template <support::endianness TargetEndianness>
585597 struct Elf_Mips_RegInfo> {
586598 LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
587599 Elf_Word ri_gprmask; // bit-mask of used general registers
589601 Elf_Addr ri_gp_value; // gp register value
590602 };
591603
592 template <llvm::support::endianness TargetEndianness>
604 template <support::endianness TargetEndianness>
593605 struct Elf_Mips_RegInfo> {
594606 LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
595607 Elf_Word ri_gprmask; // bit-mask of used general registers
608620 Elf_Word info; // Kind-specific information
609621
610622 Elf_Mips_RegInfo &getRegInfo() {
611 assert(kind == llvm::ELF::ODK_REGINFO);
623 assert(kind == ELF::ODK_REGINFO);
612624 return *reinterpret_cast *>(
613625 (uint8_t *)this + sizeof(Elf_Mips_Options));
614626 }
636648 } // end namespace object.
637649 } // end namespace llvm.
638650
639 #endif
651 #endif // LLVM_OBJECT_ELFTYPES_H
2424 #define LLVM_OBJECT_IRSYMTAB_H
2525
2626 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/ADT/iterator_range.h"
28 #include "llvm/ADT/StringRef.h"
2729 #include "llvm/IR/GlobalValue.h"
2830 #include "llvm/Object/SymbolicFile.h"
2931 #include "llvm/Support/Endian.h"
32 #include "llvm/Support/Error.h"
33 #include
34 #include
35 #include
3036
3137 namespace llvm {
3238 namespace irsymtab {
39
3340 namespace storage {
3441
3542 // The data structures in this namespace define the low-level serialization
3643 // format. Clients that just want to read a symbol table should use the
3744 // irsymtab::Reader class.
3845
39 typedef support::ulittle32_t Word;
46 using Word = support::ulittle32_t;
4047
4148 /// A reference to a string in the string table.
4249 struct Str {
4350 Word Offset, Size;
51
4452 StringRef get(StringRef Strtab) const {
4553 return {Strtab.data() + Offset, Size};
4654 }
4957 /// A reference to a range of objects in the symbol table.
5058 template struct Range {
5159 Word Offset, Size;
60
5261 ArrayRef get(StringRef Symtab) const {
5362 return {reinterpret_cast(Symtab.data() + Offset), Size};
5463 }
121130 Str COFFLinkerOpts;
122131 };
123132
124 }
133 } // end namespace storage
125134
126135 /// Fills in Symtab and Strtab with a valid symbol and string table for Mods.
127136 Error build(ArrayRef Mods, SmallVector &Symtab,
151160 int getComdatIndex() const { return ComdatIndex; }
152161
153162 using S = storage::Symbol;
163
154164 GlobalValue::VisibilityTypes getVisibility() const {
155165 return GlobalValue::VisibilityTypes((Flags >> S::FB_visibility) & 3);
156166 }
167
157168 bool isUndefined() const { return (Flags >> S::FB_undefined) & 1; }
158169 bool isWeak() const { return (Flags >> S::FB_weak) & 1; }
159170 bool isCommon() const { return (Flags >> S::FB_common) & 1; }
160171 bool isIndirect() const { return (Flags >> S::FB_indirect) & 1; }
161172 bool isUsed() const { return (Flags >> S::FB_used) & 1; }
162173 bool isTLS() const { return (Flags >> S::FB_tls) & 1; }
174
163175 bool canBeOmittedFromSymbolTable() const {
164176 return (Flags >> S::FB_may_omit) & 1;
165177 }
178
166179 bool isGlobal() const { return (Flags >> S::FB_global) & 1; }
167180 bool isFormatSpecific() const { return (Flags >> S::FB_format_specific) & 1; }
168181 bool isUnnamedAddr() const { return (Flags >> S::FB_unnamed_addr) & 1; }
172185 assert(isCommon());
173186 return CommonSize;
174187 }
188
175189 uint32_t getCommonAlignment() const {
176190 assert(isCommon());
177191 return CommonAlign;
196210 ArrayRef Uncommons;
197211
198212 StringRef str(storage::Str S) const { return S.get(Strtab); }
213
199214 template ArrayRef range(storage::Range R) const {
200215 return R.get(Symtab);
201216 }
217
202218 const storage::Header &header() const {
203219 return *reinterpret_cast(Symtab.data());
204220 }
214230 Uncommons = range(header().Uncommons);
215231 }
216232
217 typedef iterator_range> symbol_range;
233 using symbol_range = iterator_range>;
218234
219235 /// Returns the symbol table for the entire bitcode file.
220236 /// The symbols enumerated by this method are ephemeral, but they can be
297313 SymbolRef(MEnd, MEnd, nullptr, this)};
298314 }
299315
300 }
301
302 }
303
304 #endif
316 } // end namespace irsymtab
317 } // end namespace llvm
318
319 #endif // LLVM_OBJECT_IRSYMTAB_H
None //===- ModuleSymbolTable.h - symbol table for in-memory IR ----------------===//
0 //===- ModuleSymbolTable.h - symbol table for in-memory IR ------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1515 #ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H
1616 #define LLVM_OBJECT_MODULESYMBOLTABLE_H
1717
18 #include "llvm/ADT/ArrayRef.h"
1819 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/ADT/Triple.h"
2020 #include "llvm/IR/Mangler.h"
2121 #include "llvm/Object/SymbolicFile.h"
22 #include "llvm/Support/Allocator.h"
23 #include
2224 #include
2325 #include
26 #include
2427
2528 namespace llvm {
2629
2730 class GlobalValue;
28 class RecordStreamer;
2931
3032 class ModuleSymbolTable {
3133 public:
32 typedef std::pair AsmSymbol;
33 typedef PointerUnion Symbol;
34 using AsmSymbol = std::pair;
35 using Symbol = PointerUnion;
3436
3537 private:
3638 Module *FirstMod = nullptr;
5658 function_ref AsmSymbol);
5759 };
5860
59 }
61 } // end namespace llvm
6062
61 #endif
63 #endif // LLVM_OBJECT_MODULESYMBOLTABLE_H
None //===-------- StackMapParser.h - StackMap Parsing Support -------*- C++ -*-===//
0 //===- StackMapParser.h - StackMap Parsing Support --------------*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 #define LLVM_CODEGEN_STACKMAPPARSER_H
1111
1212 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/iterator_range.h"
1314 #include "llvm/Support/Endian.h"
15 #include
16 #include
17 #include
1418 #include
1519
1620 namespace llvm {
1822 template
1923 class StackMapV2Parser {
2024 public:
21
2225 template
2326 class AccessorIterator {
2427 public:
25
2628 AccessorIterator(AccessorT A) : A(A) {}
29
2730 AccessorIterator& operator++() { A = A.next(); return *this; }
2831 AccessorIterator operator++(int) {
2932 auto tmp = *this;
4750 /// Accessor for function records.
4851 class FunctionAccessor {
4952 friend class StackMapV2Parser;
50 public:
51
53
54 public:
5255 /// Get the function address.
5356 uint64_t getFunctionAddress() const {
5457 return read(P);
7982 /// Accessor for constants.
8083 class ConstantAccessor {
8184 friend class StackMapV2Parser;
82 public:
83
85
86 public:
8487 /// Return the value of this constant.
8588 uint64_t getValue() const { return read(P); }
8689
8790 private:
88
8991 ConstantAccessor(const uint8_t *P) : P(P) {}
9092
9193 const static int ConstantAccessorSize = sizeof(uint64_t);
9799 const uint8_t *P;
98100 };
99101
100 // Forward-declare RecordAccessor so we can friend it below.
101 class RecordAccessor;
102
103102 enum class LocationKind : uint8_t {
104103 Register = 1, Direct = 2, Indirect = 3, Constant = 4, ConstantIndex = 5
105104 };
106
107105
108106 /// Accessor for location records.
109107 class LocationAccessor {
110108 friend class StackMapV2Parser;
111109 friend class RecordAccessor;
112 public:
113
110
111 public:
114112 /// Get the Kind for this location.
115113 LocationKind getKind() const {
116114 return LocationKind(P[KindOffset]);
143141 }
144142
145143 private:
146
147144 LocationAccessor(const uint8_t *P) : P(P) {}
148145
149146 LocationAccessor next() const {
162159 class LiveOutAccessor {
163160 friend class StackMapV2Parser;
164161 friend class RecordAccessor;
165 public:
166
162
163 public:
167164 /// Get the Dwarf register number for this live-out.
168165 uint16_t getDwarfRegNum() const {
169166 return read(P + DwarfRegNumOffset);
175172 }
176173
177174 private:
178
179175 LiveOutAccessor(const uint8_t *P) : P(P) {}
180176
181177 LiveOutAccessor next() const {
193189 /// Accessor for stackmap records.
194190 class RecordAccessor {
195191 friend class StackMapV2Parser;
196 public:
197
198 typedef AccessorIterator location_iterator;
199 typedef AccessorIterator liveout_iterator;
192
193 public:
194 using location_iterator = AccessorIterator;
195 using liveout_iterator = AccessorIterator;
200196
201197 /// Get the patchpoint/stackmap ID for this record.
202198 uint64_t getID() const {
253249 return liveout_iterator(getLiveOut(0));
254250 }
255251
256
257252 /// End iterator for live-outs.
258253 liveout_iterator liveouts_end() const {
259254 return liveout_iterator(getLiveOut(getNumLiveOuts()));
265260 }
266261
267262 private:
268
269263 RecordAccessor(const uint8_t *P) : P(P) {}
270264
271265 unsigned getNumLiveOutsOffset() const {
315309 }
316310 }
317311
318 typedef AccessorIterator function_iterator;
319 typedef AccessorIterator constant_iterator;
320 typedef AccessorIterator record_iterator;
312 using function_iterator = AccessorIterator;
313 using constant_iterator = AccessorIterator;
314 using record_iterator = AccessorIterator;
321315
322316 /// Get the version number of this stackmap. (Always returns 2).
323317 unsigned getVersion() const { return 2; }
412406 }
413407
414408 private:
415
416409 template
417410 static T read(const uint8_t *P) {
418411 return support::endian::read(P);
440433 std::vector StackMapRecordOffsets;
441434 };
442435
443 }
444
445 #endif
436 } // end namespace llvm
437
438 #endif // LLVM_CODEGEN_STACKMAPPARSER_H
None //===- ELF.cpp - ELF object file implementation -----------------*- C++ -*-===//
0 //===- ELF.cpp - ELF object file implementation ---------------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Object/ELF.h"
10 #include "llvm/Support/ELF.h"
1011
11 namespace llvm {
12 namespace object {
12 using namespace llvm;
13 using namespace object;
1314
1415 #define ELF_RELOC(name, value) \
1516 case ELF::name: \
1617 return #name; \
1718
18 StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
19 StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
20 uint32_t Type) {
1921 switch (Machine) {
2022 case ELF::EM_X86_64:
2123 switch (Type) {
138140 }
139141
140142 #undef ELF_RELOC
141
142 } // end namespace object
143 } // end namespace llvm
None //===- ELFObjectFile.cpp - ELF object file implementation -------*- C++ -*-===//
0 //===- ELFObjectFile.cpp - ELF object file implementation -----------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/ADT/Triple.h"
14 #include "llvm/MC/SubtargetFeature.h"
15 #include "llvm/Object/ELF.h"
1316 #include "llvm/Object/ELFObjectFile.h"
17 #include "llvm/Object/ELFTypes.h"
18 #include "llvm/Object/Error.h"
1419 #include "llvm/Support/ARMBuildAttributes.h"
1520 #include "llvm/Support/ARMAttributeParser.h"
21 #include "llvm/Support/ELF.h"
22 #include "llvm/Support/Endian.h"
23 #include "llvm/Support/ErrorHandling.h"
1624 #include "llvm/Support/MathExtras.h"
17
18 namespace llvm {
25 #include
26 #include
27 #include
28 #include
29 #include
30 #include
31 #include
32
33 using namespace llvm;
1934 using namespace object;
2035
2136 ELFObjectFileBase::ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
298313
299314 TheTriple.setArchName(Triple);
300315 }
301
302 } // end namespace llvm
None //===- IRSymtab.cpp - implementation of IR symbol tables --------*- C++ -*-===//
0 //===- IRSymtab.cpp - implementation of IR symbol tables ------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "llvm/Object/IRSymtab.h"
9 #include "llvm/ADT/ArrayRef.h"
10 #include "llvm/ADT/DenseMap.h"
11 #include "llvm/ADT/SmallPtrSet.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Triple.h"
1016 #include "llvm/Analysis/ObjectUtils.h"
17 #include "llvm/IR/Comdat.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/GlobalAlias.h"
20 #include "llvm/IR/GlobalObject.h"
1121 #include "llvm/IR/Mangler.h"
22 #include "llvm/IR/Metadata.h"
1223 #include "llvm/IR/Module.h"
1324 #include "llvm/MC/StringTableBuilder.h"
25 #include "llvm/Object/IRSymtab.h"
1426 #include "llvm/Object/ModuleSymbolTable.h"
27 #include "llvm/Object/SymbolicFile.h"
1528 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Error.h"
31 #include "llvm/Support/raw_ostream.h"
1632 #include "llvm/Support/StringSaver.h"
33 #include
34 #include
35 #include
36 #include
1737
1838 using namespace llvm;
1939 using namespace irsymtab;
2444 struct Builder {
2545 SmallVector &Symtab;
2646 SmallVector &Strtab;
47
2748 Builder(SmallVector &Symtab, SmallVector &Strtab)
2849 : Symtab(Symtab), Strtab(Strtab) {}
2950
4869 S.Offset = StrtabBuilder.add(Value);
4970 S.Size = Value.size();
5071 }
72
5173 template
5274 void writeRange(storage::Range &R, const std::vector &Objs) {
5375 R.Offset = Symtab.size();
227249 return Error::success();
228250 }
229251
230 } // anonymous namespace
252 } // end anonymous namespace
231253
232254 Error irsymtab::build(ArrayRef Mods, SmallVector &Symtab,
233255 SmallVector &Strtab) {
None //===- ModuleSymbolTable.cpp - symbol table for in-memory IR ----*- C++ -*-===//
0 //===- ModuleSymbolTable.cpp - symbol table for in-memory IR --------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1212 //
1313 //===----------------------------------------------------------------------===//
1414
15 #include "llvm/Object/IRObjectFile.h"
1615 #include "RecordStreamer.h"
16 #include "llvm/ADT/SmallString.h"
1717 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Bitcode/BitcodeReader.h"
19 #include "llvm/IR/GVMaterializer.h"
20 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/GlobalAlias.h"
23 #include "llvm/IR/GlobalValue.h"
24 #include "llvm/IR/GlobalVariable.h"
2125 #include "llvm/IR/Mangler.h"
2226 #include "llvm/IR/Module.h"
2327 #include "llvm/MC/MCAsmInfo.h"
2428 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCDirectives.h"
2530 #include "llvm/MC/MCInstrInfo.h"
2631 #include "llvm/MC/MCObjectFileInfo.h"
2732 #include "llvm/MC/MCParser/MCAsmParser.h"
2833 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
2934 #include "llvm/MC/MCRegisterInfo.h"
3035 #include "llvm/MC/MCSubtargetInfo.h"
31 #include "llvm/Object/ObjectFile.h"
36 #include "llvm/MC/MCSymbol.h"
37 #include "llvm/MC/MCTargetOptions.h"
38 #include "llvm/Object/ModuleSymbolTable.h"
39 #include "llvm/Object/SymbolicFile.h"
40 #include "llvm/Support/Casting.h"
41 #include "llvm/Support/CodeGen.h"
42 #include "llvm/Support/ErrorHandling.h"
3243 #include "llvm/Support/MemoryBuffer.h"
44 #include "llvm/Support/raw_ostream.h"
45 #include "llvm/Support/SMLoc.h"
3346 #include "llvm/Support/SourceMgr.h"
3447 #include "llvm/Support/TargetRegistry.h"
35 #include "llvm/Support/raw_ostream.h"
48 #include
49 #include
50 #include
51 #include
52 #include
53
3654 using namespace llvm;
3755 using namespace object;
3856
88
99 #include "RecordStreamer.h"
1010 #include "llvm/MC/MCSymbol.h"
11
1112 using namespace llvm;
1213
1314 void RecordStreamer::markDefined(const MCSymbol &Symbol) {
6869
6970 void RecordStreamer::visitUsedSymbol(const MCSymbol &Sym) { markUsed(Sym); }
7071
72 RecordStreamer::RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
73
7174 RecordStreamer::const_iterator RecordStreamer::begin() {
7275 return Symbols.begin();
7376 }
7477
7578 RecordStreamer::const_iterator RecordStreamer::end() { return Symbols.end(); }
76
77 RecordStreamer::RecordStreamer(MCContext &Context) : MCStreamer(Context) {}
7879
7980 void RecordStreamer::EmitInstruction(const MCInst &Inst,
8081 const MCSubtargetInfo &STI, bool) {
None //===-- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*===//
0 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
99 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
1010 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
1111
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/MC/MCDirectives.h"
1215 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSymbol.h"
17 #include "llvm/Support/SMLoc.h"
18 #include
1319
1420 namespace llvm {
21
1522 class RecordStreamer : public MCStreamer {
1623 public:
1724 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
2330 // their symbol binding after parsing complete. This maps from each
2431 // aliasee to its list of aliases.
2532 DenseMap> SymverAliasMap;
33
2634 void markDefined(const MCSymbol &Symbol);
2735 void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
2836 void markUsed(const MCSymbol &Symbol);
2937 void visitUsedSymbol(const MCSymbol &Sym) override;
3038
3139 public:
32 typedef StringMap::const_iterator const_iterator;
40 RecordStreamer(MCContext &Context);
41
42 using const_iterator = StringMap::const_iterator;
43
3344 const_iterator begin();
3445 const_iterator end();
35 RecordStreamer(MCContext &Context);
3646 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
3747 bool) override;
3848 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
4959 DenseMap> &symverAliases() {
5060 return SymverAliasMap;
5161 }
62
5263 /// Get the state recorded for the given symbol.
5364 State getSymbolState(const MCSymbol *Sym) {
5465 auto SI = Symbols.find(Sym->getName());
5768 return SI->second;
5869 }
5970 };
60 }
61 #endif
71
72 } // end namespace llvm
73
74 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H