llvm.org GIT mirror llvm / 4323907
Two small cleanups for ELF's templates. * We only ever specialize these templates with an instantiation of ELFType, so we don't need a template template. * Replace LLVM_ELF_COMMA with just passing the individual parameters to the macro. This requires a second macro for when we only have ELFT, but that is still a small win. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179726 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
2 changed file(s) with 73 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
8080 struct ELFDataTypeTypedefHelper;
8181
8282 /// ELF 32bit types.
83 template class ELFT,
84 endianness TargetEndianness, std::size_t MaxAlign>
85 struct ELFDataTypeTypedefHelper >
83 template>
84 struct ELFDataTypeTypedefHelper >
8685 : ELFDataTypeTypedefHelperCommon {
8786 typedef uint32_t value_type;
8887 typedef support::detail::packed_endian_specific_integral
9493 };
9594
9695 /// ELF 64bit types.
97 template class ELFT,
98 endianness TargetEndianness, std::size_t MaxAlign>
99 struct ELFDataTypeTypedefHelper >
96 template>
97 struct ELFDataTypeTypedefHelper >
10098 : ELFDataTypeTypedefHelperCommon {
10199 typedef uint64_t value_type;
102100 typedef support::detail::packed_endian_specific_integral
108106 };
109107
110108 // I really don't like doing this, but the alternative is copypasta.
111 #define LLVM_ELF_IMPORT_TYPES(ELFT) \
112 typedef typename ELFDataTypeTypedefHelper ::Elf_Addr Elf_Addr; \
113 typedef typename ELFDataTypeTypedefHelper ::Elf_Off Elf_Off; \
114 typedef typename ELFDataTypeTypedefHelper ::Elf_Half Elf_Half; \
115 typedef typename ELFDataTypeTypedefHelper ::Elf_Word Elf_Word; \
116 typedef typename ELFDataTypeTypedefHelper ::Elf_Sword Elf_Sword; \
117 typedef typename ELFDataTypeTypedefHelper ::Elf_Xword Elf_Xword; \
118 typedef typename ELFDataTypeTypedefHelper ::Elf_Sxword Elf_Sxword;
119
120 // This is required to get template types into a macro :(
121 #define LLVM_ELF_COMMA ,
122
123 // Section header.
109 #define LLVM_ELF_IMPORT_TYPES(E, M, W) \
110 typedef typename ELFDataTypeTypedefHelper >::Elf_Addr Elf_Addr; \
111 typedef typename ELFDataTypeTypedefHelper >::Elf_Off Elf_Off; \
112 typedef typename ELFDataTypeTypedefHelper >::Elf_Half Elf_Half; \
113 typedef typename ELFDataTypeTypedefHelper >::Elf_Word Elf_Word; \
114 typedef typename \
115 ELFDataTypeTypedefHelper >::Elf_Sword Elf_Sword; \
116 typedef typename \
117 ELFDataTypeTypedefHelper >::Elf_Xword Elf_Xword; \
118 typedef typename \
119 ELFDataTypeTypedefHelper >::Elf_Sxword Elf_Sxword;
120
121 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
122 LLVM_ELF_IMPORT_TYPES(ELFT::TargetEndianness, ELFT::MaxAlignment, \
123 ELFT::Is64Bits)
124
125 // Section header.
124126 template
125127 struct Elf_Shdr_Base;
126128
127 template class ELFT,
128 endianness TargetEndianness, std::size_t MaxAlign>
129 struct Elf_Shdr_Base > {
130 LLVM_ELF_IMPORT_TYPES(ELFT
131 MaxAlign LLVM_ELF_COMMA false>)
129 template
130 struct Elf_Shdr_Base > {
131 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
132132 Elf_Word sh_name; // Section name (index into string table)
133133 Elf_Word sh_type; // Section type (SHT_*)
134134 Elf_Word sh_flags; // Section flags (SHF_*)
141141 Elf_Word sh_entsize; // Size of records contained within the section
142142 };
143143
144 template class ELFT,
145 endianness TargetEndianness, std::size_t MaxAlign>
146 struct Elf_Shdr_Base > {
147 LLVM_ELF_IMPORT_TYPES(ELFT
148 MaxAlign LLVM_ELF_COMMA true>)
144 template
145 struct Elf_Shdr_Base > {
146 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
149147 Elf_Word sh_name; // Section name (index into string table)
150148 Elf_Word sh_type; // Section type (SHT_*)
151149 Elf_Xword sh_flags; // Section flags (SHF_*)
174172 template
175173 struct Elf_Sym_Base;
176174
177 template class ELFT,
178 endianness TargetEndianness, std::size_t MaxAlign>
179 struct Elf_Sym_Base > {
180 LLVM_ELF_IMPORT_TYPES(ELFT
181 MaxAlign LLVM_ELF_COMMA false>)
175 template
176 struct Elf_Sym_Base > {
177 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
182178 Elf_Word st_name; // Symbol name (index into string table)
183179 Elf_Addr st_value; // Value or address associated with the symbol
184180 Elf_Word st_size; // Size of the symbol
187183 Elf_Half st_shndx; // Which section (header table index) it's defined in
188184 };
189185
190 template class ELFT,
191 endianness TargetEndianness, std::size_t MaxAlign>
192 struct Elf_Sym_Base > {
193 LLVM_ELF_IMPORT_TYPES(ELFT
194 MaxAlign LLVM_ELF_COMMA true>)
186 template
187 struct Elf_Sym_Base > {
188 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
195189 Elf_Word st_name; // Symbol name (index into string table)
196190 unsigned char st_info; // Symbol's type and binding attributes
197191 unsigned char st_other; // Must be zero; reserved
219213 /// (.gnu.version). This structure is identical for ELF32 and ELF64.
220214 template
221215 struct Elf_Versym_Impl {
222 LLVM_ELF_IMPORT_TYPES(ELFT)
216 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
223217 Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
224218 };
225219
230224 /// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
231225 template
232226 struct Elf_Verdef_Impl {
233 LLVM_ELF_IMPORT_TYPES(ELFT)
227 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
234228 typedef Elf_Verdaux_Impl Elf_Verdaux;
235229 Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
236230 Elf_Half vd_flags; // Bitwise flags (VER_DEF_*)
250244 /// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
251245 template
252246 struct Elf_Verdaux_Impl {
253 LLVM_ELF_IMPORT_TYPES(ELFT)
247 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
254248 Elf_Word vda_name; // Version name (offset in string table)
255249 Elf_Word vda_next; // Offset to next Verdaux entry (in bytes)
256250 };
259253 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
260254 template
261255 struct Elf_Verneed_Impl {
262 LLVM_ELF_IMPORT_TYPES(ELFT)
256 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
263257 Elf_Half vn_version; // Version of this structure (e.g. VER_NEED_CURRENT)
264258 Elf_Half vn_cnt; // Number of associated Vernaux entries
265259 Elf_Word vn_file; // Library name (string table offset)
271265 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
272266 template
273267 struct Elf_Vernaux_Impl {
274 LLVM_ELF_IMPORT_TYPES(ELFT)
268 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
275269 Elf_Word vna_hash; // Hash of dependency name
276270 Elf_Half vna_flags; // Bitwise Flags (VER_FLAG_*)
277271 Elf_Half vna_other; // Version index, used in .gnu.version entries
284278 template
285279 struct Elf_Dyn_Base;
286280
287 template class ELFT,
288 endianness TargetEndianness, std::size_t MaxAlign>
289 struct Elf_Dyn_Base > {
290 LLVM_ELF_IMPORT_TYPES(ELFT
291 MaxAlign LLVM_ELF_COMMA false>)
281 template
282 struct Elf_Dyn_Base > {
283 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
292284 Elf_Sword d_tag;
293285 union {
294286 Elf_Word d_val;
296288 } d_un;
297289 };
298290
299 template class ELFT,
300 endianness TargetEndianness, std::size_t MaxAlign>
301 struct Elf_Dyn_Base > {
302 LLVM_ELF_IMPORT_TYPES(ELFT
303 MaxAlign LLVM_ELF_COMMA true>)
291 template
292 struct Elf_Dyn_Base > {
293 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
304294 Elf_Sxword d_tag;
305295 union {
306296 Elf_Xword d_val;
322312 template
323313 struct Elf_Rel_Base;
324314
325 template class ELFT,
326 endianness TargetEndianness, std::size_t MaxAlign>
327 struct Elf_Rel_Base, false> {
328 LLVM_ELF_IMPORT_TYPES(ELFT
329 MaxAlign LLVM_ELF_COMMA false>)
315 template
316 struct Elf_Rel_Base, false> {
317 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
330318 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
331319 Elf_Word r_info; // Symbol table index and type of relocation to apply
332320
339327 }
340328 };
341329
342 template class ELFT,
343 endianness TargetEndianness, std::size_t MaxAlign>
344 struct Elf_Rel_Base, false> {
345 LLVM_ELF_IMPORT_TYPES(ELFT
346 MaxAlign LLVM_ELF_COMMA true>)
330 template
331 struct Elf_Rel_Base, false> {
332 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
347333 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
348334 Elf_Xword r_info; // Symbol table index and type of relocation to apply
349335
364350 }
365351 };
366352
367 template class ELFT,
368 endianness TargetEndianness, std::size_t MaxAlign>
369 struct Elf_Rel_Base, true> {
370 LLVM_ELF_IMPORT_TYPES(ELFT
371 MaxAlign LLVM_ELF_COMMA false>)
353 template
354 struct Elf_Rel_Base, true> {
355 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
372356 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
373357 Elf_Word r_info; // Symbol table index and type of relocation to apply
374358 Elf_Sword r_addend; // Compute value for relocatable field by adding this
382366 }
383367 };
384368
385 template class ELFT,
386 endianness TargetEndianness, std::size_t MaxAlign>
387 struct Elf_Rel_Base, true> {
388 LLVM_ELF_IMPORT_TYPES(ELFT
389 MaxAlign LLVM_ELF_COMMA true>)
369 template
370 struct Elf_Rel_Base, true> {
371 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
390372 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
391373 Elf_Xword r_info; // Symbol table index and type of relocation to apply
392374 Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
410392 template
411393 struct Elf_Rel_Impl;
412394
413 template class ELFT,
414 endianness TargetEndianness, std::size_t MaxAlign, bool isRela>
415 struct Elf_Rel_Impl, isRela>
416 : Elf_Rel_Base, isRela> {
417 LLVM_ELF_IMPORT_TYPES(ELFT
418 MaxAlign LLVM_ELF_COMMA true>)
395 template
396 struct Elf_Rel_Impl, isRela>
397 : Elf_Rel_Base, isRela> {
398 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
419399
420400 // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
421401 // and ELF64_R_INFO macros defined in the ELF specification:
432412 }
433413 };
434414
435 template class ELFT,
436 endianness TargetEndianness, std::size_t MaxAlign, bool isRela>
437 struct Elf_Rel_Impl, isRela>
438 : Elf_Rel_Base, isRela> {
439 LLVM_ELF_IMPORT_TYPES(ELFT
440 MaxAlign LLVM_ELF_COMMA false>)
415 template
416 struct Elf_Rel_Impl, isRela>
417 : Elf_Rel_Base, isRela> {
418 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
441419
442420 // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
443421 // and ELF32_R_INFO macros defined in the ELF specification:
456434
457435 template
458436 struct Elf_Ehdr_Impl {
459 LLVM_ELF_IMPORT_TYPES(ELFT)
437 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
460438 unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
461439 Elf_Half e_type; // Type of file (see ET_*)
462440 Elf_Half e_machine; // Required architecture for this file (see EM_*)
482460 template
483461 struct Elf_Phdr_Impl;
484462
485 template class ELFT,
486 endianness TargetEndianness, std::size_t MaxAlign>
487 struct Elf_Phdr_Impl > {
488 LLVM_ELF_IMPORT_TYPES(ELFT
489 MaxAlign LLVM_ELF_COMMA false>)
463 template
464 struct Elf_Phdr_Impl > {
465 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
490466 Elf_Word p_type; // Type of segment
491467 Elf_Off p_offset; // FileOffset where segment is located, in bytes
492468 Elf_Addr p_vaddr; // Virtual Address of beginning of segment
497473 Elf_Word p_align; // Segment alignment constraint
498474 };
499475
500 template class ELFT,
501 endianness TargetEndianness, std::size_t MaxAlign>
502 struct Elf_Phdr_Impl > {
503 LLVM_ELF_IMPORT_TYPES(ELFT
504 MaxAlign LLVM_ELF_COMMA true>)
476 template
477 struct Elf_Phdr_Impl > {
478 LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
505479 Elf_Word p_type; // Type of segment
506480 Elf_Word p_flags; // Segment flags
507481 Elf_Off p_offset; // FileOffset where segment is located, in bytes
514488
515489 template
516490 class ELFObjectFile : public ObjectFile {
517 LLVM_ELF_IMPORT_TYPES(ELFT)
491 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
518492
519493 public:
520494 /// \brief Iterate over constant sized entities.
4040 template
4141 class DyldELFObject
4242 : public ELFObjectFile {
43 LLVM_ELF_IMPORT_TYPES(ELFT)
43 LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
4444
4545 typedef Elf_Shdr_Impl Elf_Shdr;
4646 typedef Elf_Sym_Impl Elf_Sym;