llvm.org GIT mirror llvm / 2c38a66
[Object] Extract Elf_Ehdr. Patch by Hemant Kulkarni! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163532 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 8 years ago
2 changed file(s) with 26 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
386386 }
387387 };
388388
389 template
390 struct Elf_Ehdr_Impl {
391 LLVM_ELF_IMPORT_TYPES(target_endianness, is64Bits)
392 unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
393 Elf_Half e_type; // Type of file (see ET_*)
394 Elf_Half e_machine; // Required architecture for this file (see EM_*)
395 Elf_Word e_version; // Must be equal to 1
396 Elf_Addr e_entry; // Address to jump to in order to start program
397 Elf_Off e_phoff; // Program header table's file offset, in bytes
398 Elf_Off e_shoff; // Section header table's file offset, in bytes
399 Elf_Word e_flags; // Processor-specific flags
400 Elf_Half e_ehsize; // Size of ELF header, in bytes
401 Elf_Half e_phentsize;// Size of an entry in the program header table
402 Elf_Half e_phnum; // Number of entries in the program header table
403 Elf_Half e_shentsize;// Size of an entry in the section header table
404 Elf_Half e_shnum; // Number of entries in the section header table
405 Elf_Half e_shstrndx; // Section header table index of section name
406 // string table
407 bool checkMagic() const {
408 return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
409 }
410 unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
411 unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
412 };
389413
390414 template
391415 class ELFObjectFile : public ObjectFile {
392416 LLVM_ELF_IMPORT_TYPES(target_endianness, is64Bits)
393417
418 typedef Elf_Ehdr_Impl Elf_Ehdr;
394419 typedef Elf_Shdr_Impl Elf_Shdr;
395420 typedef Elf_Sym_Impl Elf_Sym;
396421 typedef Elf_Dyn_Impl Elf_Dyn;
405430 typedef content_iterator dyn_iterator;
406431
407432 protected:
408 struct Elf_Ehdr {
409 unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
410 Elf_Half e_type; // Type of file (see ET_*)
411 Elf_Half e_machine; // Required architecture for this file (see EM_*)
412 Elf_Word e_version; // Must be equal to 1
413 Elf_Addr e_entry; // Address to jump to in order to start program
414 Elf_Off e_phoff; // Program header table's file offset, in bytes
415 Elf_Off e_shoff; // Section header table's file offset, in bytes
416 Elf_Word e_flags; // Processor-specific flags
417 Elf_Half e_ehsize; // Size of ELF header, in bytes
418 Elf_Half e_phentsize;// Size of an entry in the program header table
419 Elf_Half e_phnum; // Number of entries in the program header table
420 Elf_Half e_shentsize;// Size of an entry in the section header table
421 Elf_Half e_shnum; // Number of entries in the section header table
422 Elf_Half e_shstrndx; // Section header table index of section name
423 // string table
424 bool checkMagic() const {
425 return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
426 }
427 unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
428 unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
429 };
430433 // This flag is used for classof, to distinguish ELFObjectFile from
431434 // its subclass. If more subclasses will be created, this flag will
432435 // have to become an enum.
3535 typedef Elf_Rel_Impl Elf_Rel;
3636 typedef Elf_Rel_Impl Elf_Rela;
3737
38 typedef typename ELFObjectFile::
39 Elf_Ehdr Elf_Ehdr;
38 typedef Elf_Ehdr_Impl Elf_Ehdr;
4039
4140 typedef typename ELFDataTypeTypedefHelper<
4241 target_endianness, is64Bits>::value_type addr_type;