1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // This is the external interface for elfcpp.
8 #include "elfcpp_config.h"
9 #include "elfcpp_swap.h"
18 // These types are always the same size.
20 typedef uint16_t Elf_Half
;
21 typedef uint32_t Elf_Word
;
22 typedef int32_t Elf_Sword
;
23 typedef uint64_t Elf_Xword
;
24 typedef int64_t Elf_Sxword
;
26 // These types vary in size depending on the ELF file class. The
27 // template parameter should be 32 or 64.
35 typedef uint32_t Elf_Addr
;
36 typedef uint32_t Elf_Off
;
37 typedef uint32_t Elf_WXword
;
38 typedef int32_t Elf_Swxword
;
44 typedef uint64_t Elf_Addr
;
45 typedef uint64_t Elf_Off
;
46 typedef uint64_t Elf_WXword
;
47 typedef int64_t Elf_Swxword
;
50 // Offsets within the Ehdr e_ident field.
52 const int EI_MAG0
= 0;
53 const int EI_MAG1
= 1;
54 const int EI_MAG2
= 2;
55 const int EI_MAG3
= 3;
56 const int EI_CLASS
= 4;
57 const int EI_DATA
= 5;
58 const int EI_VERSION
= 6;
59 const int EI_OSABI
= 7;
60 const int EI_ABIVERSION
= 8;
62 const int EI_NIDENT
= 16;
64 // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
66 const int ELFMAG0
= 0x7f;
67 const int ELFMAG1
= 'E';
68 const int ELFMAG2
= 'L';
69 const int ELFMAG3
= 'F';
71 // The valid values found in Ehdr e_ident[EI_CLASS].
80 // The valid values found in Ehdr e_ident[EI_DATA].
89 // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
97 // The valid values found in Ehdr e_ident[EI_OSABI].
104 // ELFOSABI_LINUX is not listed in the ELF standard.
106 // ELFOSABI_HURD is not listed in the ELF standard.
108 ELFOSABI_SOLARIS
= 6,
111 ELFOSABI_FREEBSD
= 9,
113 ELFOSABI_MODESTO
= 11,
114 ELFOSABI_OPENBSD
= 12,
115 ELFOSABI_OPENVMS
= 13,
118 // A GNU extension for the ARM.
120 // A GNU extension for the MSP.
121 ELFOSABI_STANDALONE
= 255
124 // The valid values found in the Ehdr e_type field.
139 // The valid values found in the Ehdr e_machine field.
149 // 6 used to be EM_486
154 // 11 was the old Sparc V9 ABI.
155 // 12 through 14 are reserved.
158 // Some old PowerPC object files use 17.
165 // 23 through 35 are served.
229 // Some old picoJava object files use 99 (EM_PJ is correct).
242 EM_ALTERA_NIOS2
= 113,
250 // Infineon Technologies 16-bit microcontroller with C166-V2 core.
253 EM_XSTORMY16
= 0xad45,
260 // Old AVR objects used 0x1057 (EM_AVR is correct).
261 // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
262 // Old FR30 objects used 0x3330 (EM_FR30 is correct).
263 // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OPENRISC is correct).
264 // Old D10V objects used 0x7650 (EM_D10V is correct).
265 // Old D30V objects used 0x7676 (EM_D30V is correct).
266 // Old IP2X objects used 0x8217 (EM_IP2K is correct).
267 // Old PowerPC objects used 0x9025 (EM_PPC is correct).
268 // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
269 // Old M32R objects used 0x9041 (EM_M32R is correct).
270 // Old V850 objects used 0x9080 (EM_V850 is correct).
271 // Old S/390 objects used 0xa390 (EM_S390 is correct).
272 // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
273 // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
274 // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
277 // Special section indices.
282 SHN_LORESERVE
= 0xff00,
290 SHN_HIRESERVE
= 0xffff
293 // The valid values found in the Shdr sh_type field.
311 SHT_PREINIT_ARRAY
= 16,
313 SHT_SYMTAB_SHNDX
= 18,
314 SHT_LOOS
= 0x60000000,
315 SHT_HIOS
= 0x6fffffff,
316 SHT_LOPROC
= 0x70000000,
317 SHT_HIPROC
= 0x7fffffff,
318 SHT_LOUSER
= 0x80000000,
319 SHT_HIUSER
= 0xffffffff,
320 // The remaining values are not in the standard.
321 // List of prelink dependencies.
322 SHT_GNU_LIBLIST
= 0x6ffffff7,
323 // Versions defined by file.
324 SHT_SUNW_verdef
= 0x6ffffffd,
325 SHT_GNU_verdef
= 0x6ffffffd,
326 // Versions needed by file.
327 SHT_SUNW_verneed
= 0x6ffffffe,
328 SHT_GNU_verneed
= 0x6ffffffe,
330 SHT_SUNW_versym
= 0x6fffffff,
331 SHT_GNU_versym
= 0x6fffffff,
334 // The valid bit flags found in the Shdr sh_flags field.
343 SHF_INFO_LINK
= 0x40,
344 SHF_LINK_ORDER
= 0x80,
345 SHF_OS_NONCONFORMING
= 0x100,
348 SHF_MASKOS
= 0x0ff00000,
349 SHF_MASKPROC
= 0xf0000000
352 // Bit flags which appear in the first 32-bit word of the section data
353 // of a SHT_GROUP section.
358 GRP_MASKOS
= 0x0ff00000,
359 GRP_MASKPROC
= 0xf0000000
362 // The valid values found in the Phdr p_type field.
374 PT_LOOS
= 0x60000000,
375 PT_HIOS
= 0x6fffffff,
376 PT_LOPROC
= 0x70000000,
377 PT_HIPROC
= 0x7fffffff,
378 // The remaining values are not in the standard.
379 // Frame unwind information.
380 PT_GNU_EH_FRAME
= 0x6474e550,
381 PT_SUNW_EH_FRAME
= 0x6474e550,
383 PT_GNU_STACK
= 0x6474e551,
384 // Read only after relocation.
385 PT_GNU_RELRO
= 0x6474e552
388 // The valid bit flags found in the Phdr p_flags field.
395 PF_MASKOS
= 0x0ff00000,
396 PF_MASKPROC
= 0xf0000000
399 // Symbol binding from Sym st_info field.
412 // Symbol types from Sym st_info field.
430 elf_st_bind(unsigned char info
)
432 return static_cast<STB
>(info
>> 4);
436 elf_st_type(unsigned char info
)
438 return static_cast<STT
>(info
& 0xf);
442 elf_st_info(STB bind
, STT type
)
444 return ((static_cast<unsigned char>(bind
) << 4)
445 + (static_cast<unsigned char>(type
) & 0xf));
448 // Symbol visibility from Sym st_other field.
459 elf_st_visibility(unsigned char other
)
461 return static_cast<STV
>(other
& 0x3);
465 elf_st_nonvis(unsigned char other
)
467 return static_cast<STV
>(other
>> 2);
471 elf_st_other(STV vis
, unsigned char nonvis
)
473 return ((nonvis
<< 2)
474 + (static_cast<unsigned char>(vis
) & 3));
477 // Reloc information from Rel/Rela r_info field.
481 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
485 elf_r_sym
<32>(Elf_Word v
)
492 elf_r_sym
<64>(Elf_Xword v
)
499 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
503 elf_r_type
<32>(Elf_Word v
)
510 elf_r_type
<64>(Elf_Xword v
)
512 return v
& 0xffffffff;
516 typename Elf_types
<size
>::Elf_WXword
517 elf_r_info(unsigned int s
, unsigned int t
);
521 elf_r_info
<32>(unsigned int s
, unsigned int t
)
523 return (s
<< 8) + (t
& 0xff);
528 elf_r_info
<64>(unsigned int s
, unsigned int t
)
530 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
533 // Dynamic tags found in the PT_DYNAMIC segment.
564 DT_INIT_ARRAYSZ
= 27,
565 DT_FINI_ARRAYSZ
= 28,
569 DT_PREINIT_ARRAY
= 33,
570 DT_PREINIT_ARRAYSZ
= 33,
571 DT_LOOS
= 0x6000000d,
572 DT_HIOS
= 0x6ffff000,
573 DT_LOPROC
= 0x70000000,
574 DT_HIPROC
= 0x7fffffff,
576 // The remaining values are extensions used by GNU or Solaris.
577 DT_VALRNGLO
= 0x6ffffd00,
578 DT_GNU_PRELINKED
= 0x6ffffdf5,
579 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
580 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
581 DT_CHECKSUM
= 0x6ffffdf8,
582 DT_PLTPADSZ
= 0x6ffffdf9,
583 DT_MOVEENT
= 0x6ffffdfa,
584 DT_MOVESZ
= 0x6ffffdfb,
585 DT_FEATURE
= 0x6ffffdfc,
586 DT_POSFLAG_1
= 0x6ffffdfd,
587 DT_SYMINSZ
= 0x6ffffdfe,
588 DT_SYMINENT
= 0x6ffffdff,
589 DT_VALRNGHI
= 0x6ffffdff,
591 DT_ADDRRNGLO
= 0x6ffffe00,
592 DT_GNU_HASH
= 0x6ffffef5,
593 DT_TLSDESC_PLT
= 0x6ffffef6,
594 DT_TLSDESC_GOT
= 0x6ffffef7,
595 DT_GNU_CONFLICT
= 0x6ffffef8,
596 DT_GNU_LIBLIST
= 0x6ffffef9,
597 DT_CONFIG
= 0x6ffffefa,
598 DT_DEPAUDIT
= 0x6ffffefb,
599 DT_AUDIT
= 0x6ffffefc,
600 DT_PLTPAD
= 0x6ffffefd,
601 DT_MOVETAB
= 0x6ffffefe,
602 DT_SYMINFO
= 0x6ffffeff,
603 DT_ADDRRNGHI
= 0x6ffffeff,
605 DT_RELACOUNT
= 0x6ffffff9,
606 DT_RELCOUNT
= 0x6ffffffa,
607 DT_FLAGS_1
= 0x6ffffffb,
608 DT_VERDEF
= 0x6ffffffc,
609 DT_VERDEFNUM
= 0x6ffffffd,
610 DT_VERNEED
= 0x6ffffffe,
611 DT_VERNEEDNUM
= 0x6fffffff,
613 DT_VERSYM
= 0x6ffffff0,
615 DT_AUXILIARY
= 0x7ffffffd,
616 DT_USED
= 0x7ffffffe,
617 DT_FILTER
= 0x7fffffff
620 // Flags found in the DT_FLAGS dynamic element.
631 // Version numbers which appear in the vd_version field of a Verdef
634 const int VER_DEF_NONE
= 0;
635 const int VER_DEF_CURRENT
= 1;
637 // Version numbers which appear in the vn_version field of a Verneed
640 const int VER_NEED_NONE
= 0;
641 const int VER_NEED_CURRENT
= 1;
643 // Bit flags which appear in vd_flags of Verdef and vna_flags of
646 const int VER_FLG_BASE
= 0x1;
647 const int VER_FLG_WEAK
= 0x2;
649 // Special constants found in the SHT_GNU_versym entries.
651 const int VER_NDX_LOCAL
= 0;
652 const int VER_NDX_GLOBAL
= 1;
654 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
655 // the symbol is hidden and can only be seen when referenced using an
656 // explicit version number. This is a GNU extension.
658 const int VERSYM_HIDDEN
= 0x8000;
660 // This is the mask for the rest of the data in a word read from a
661 // SHT_GNU_versym section.
663 const int VERSYM_VERSION
= 0x7fff;
665 } // End namespace elfcpp.
667 // Include internal details after defining the types.
668 #include "elfcpp_internal.h"
673 // The offset of the ELF file header in the ELF file.
675 const int file_header_offset
= 0;
677 // ELF structure sizes.
682 // Size of ELF file header.
683 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
684 // Size of ELF segment header.
685 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
686 // Size of ELF section header.
687 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
688 // Size of ELF symbol table entry.
689 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
690 // Sizes of ELF reloc entries.
691 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
692 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
693 // Size of ELF dynamic entry.
694 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
697 // Accessor class for the ELF file header.
699 template<int size
, bool big_endian
>
703 Ehdr(const unsigned char* p
)
704 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
707 template<typename File
>
708 Ehdr(File
* file
, typename
File::Location loc
)
709 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
710 file
->view(loc
.file_offset
, loc
.data_size
).data()))
715 { return this->p_
->e_ident
; }
719 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
722 get_e_machine() const
723 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
726 get_e_version() const
727 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
729 typename Elf_types
<size
>::Elf_Addr
731 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
733 typename Elf_types
<size
>::Elf_Off
735 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
737 typename Elf_types
<size
>::Elf_Off
739 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
743 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
747 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
750 get_e_phentsize() const
751 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
755 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
758 get_e_shentsize() const
759 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
763 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
766 get_e_shstrndx() const
767 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
770 const internal::Ehdr_data
<size
>* p_
;
773 // Write class for the ELF file header.
775 template<int size
, bool big_endian
>
779 Ehdr_write(unsigned char* p
)
780 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
784 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
785 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
788 put_e_type(Elf_Half v
)
789 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
792 put_e_machine(Elf_Half v
)
793 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
796 put_e_version(Elf_Word v
)
797 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
800 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
801 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
804 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
805 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
808 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
809 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
812 put_e_flags(Elf_Word v
)
813 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
816 put_e_ehsize(Elf_Half v
)
817 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
820 put_e_phentsize(Elf_Half v
)
821 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
824 put_e_phnum(Elf_Half v
)
825 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
828 put_e_shentsize(Elf_Half v
)
829 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
832 put_e_shnum(Elf_Half v
)
833 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
836 put_e_shstrndx(Elf_Half v
)
837 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
840 internal::Ehdr_data
<size
>* p_
;
843 // Accessor class for an ELF section header.
845 template<int size
, bool big_endian
>
849 Shdr(const unsigned char* p
)
850 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
853 template<typename File
>
854 Shdr(File
* file
, typename
File::Location loc
)
855 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
856 file
->view(loc
.file_offset
, loc
.data_size
).data()))
861 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
865 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
867 typename Elf_types
<size
>::Elf_WXword
869 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
871 typename Elf_types
<size
>::Elf_Addr
873 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
875 typename Elf_types
<size
>::Elf_Off
876 get_sh_offset() const
877 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
879 typename Elf_types
<size
>::Elf_WXword
881 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
885 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
889 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
891 typename Elf_types
<size
>::Elf_WXword
892 get_sh_addralign() const
894 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
896 typename Elf_types
<size
>::Elf_WXword
897 get_sh_entsize() const
898 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
901 const internal::Shdr_data
<size
>* p_
;
904 // Write class for an ELF section header.
906 template<int size
, bool big_endian
>
910 Shdr_write(unsigned char* p
)
911 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
915 put_sh_name(Elf_Word v
)
916 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
919 put_sh_type(Elf_Word v
)
920 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
923 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
924 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
927 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
928 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
931 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
932 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
935 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
936 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
939 put_sh_link(Elf_Word v
)
940 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
943 put_sh_info(Elf_Word v
)
944 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
947 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
948 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
951 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
952 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
955 internal::Shdr_data
<size
>* p_
;
958 // Accessor class for an ELF segment header.
960 template<int size
, bool big_endian
>
964 Phdr(const unsigned char* p
)
965 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
968 template<typename File
>
969 Phdr(File
* file
, typename
File::Location loc
)
970 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
971 file
->view(loc
.file_offset
, loc
.data_size
).data()))
976 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
978 typename Elf_types
<size
>::Elf_Off
980 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
982 typename Elf_types
<size
>::Elf_Addr
984 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
986 typename Elf_types
<size
>::Elf_Addr
988 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
990 typename Elf_types
<size
>::Elf_WXword
992 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
994 typename Elf_types
<size
>::Elf_WXword
996 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1000 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1002 typename Elf_types
<size
>::Elf_WXword
1004 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1007 const internal::Phdr_data
<size
>* p_
;
1010 // Write class for an ELF segment header.
1012 template<int size
, bool big_endian
>
1016 Phdr_write(unsigned char* p
)
1017 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1021 put_p_type(Elf_Word v
)
1022 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1025 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1026 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1029 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1030 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1033 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1034 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1037 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1038 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1041 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1042 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1045 put_p_flags(Elf_Word v
)
1046 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1049 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1050 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1053 internal::Phdr_data
<size
>* p_
;
1056 // Accessor class for an ELF symbol table entry.
1058 template<int size
, bool big_endian
>
1062 Sym(const unsigned char* p
)
1063 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1066 template<typename File
>
1067 Sym(File
* file
, typename
File::Location loc
)
1068 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1069 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1074 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1076 typename Elf_types
<size
>::Elf_Addr
1077 get_st_value() const
1078 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1080 typename Elf_types
<size
>::Elf_WXword
1082 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1086 { return this->p_
->st_info
; }
1090 { return elf_st_bind(this->get_st_info()); }
1094 { return elf_st_type(this->get_st_info()); }
1097 get_st_other() const
1098 { return this->p_
->st_other
; }
1101 get_st_visibility() const
1102 { return elf_st_visibility(this->get_st_other()); }
1105 get_st_nonvis() const
1106 { return elf_st_nonvis(this->get_st_other()); }
1109 get_st_shndx() const
1110 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1113 const internal::Sym_data
<size
>* p_
;
1116 // Writer class for an ELF symbol table entry.
1118 template<int size
, bool big_endian
>
1122 Sym_write(unsigned char* p
)
1123 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1127 put_st_name(Elf_Word v
)
1128 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1131 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1132 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1135 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1136 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1139 put_st_info(unsigned char v
)
1140 { this->p_
->st_info
= v
; }
1143 put_st_info(STB bind
, STT type
)
1144 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1147 put_st_other(unsigned char v
)
1148 { this->p_
->st_other
= v
; }
1151 put_st_other(STV vis
, unsigned char nonvis
)
1152 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1155 put_st_shndx(Elf_Half v
)
1156 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1158 Sym
<size
, big_endian
>
1160 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1163 internal::Sym_data
<size
>* p_
;
1166 // Accessor classes for an ELF REL relocation entry.
1168 template<int size
, bool big_endian
>
1172 Rel(const unsigned char* p
)
1173 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1176 template<typename File
>
1177 Rel(File
* file
, typename
File::Location loc
)
1178 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1179 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1182 typename Elf_types
<size
>::Elf_Addr
1183 get_r_offset() const
1184 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1186 typename Elf_types
<size
>::Elf_WXword
1188 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1191 const internal::Rel_data
<size
>* p_
;
1194 // Writer class for an ELF Rel relocation.
1196 template<int size
, bool big_endian
>
1200 Rel_write(unsigned char* p
)
1201 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1205 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1206 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1209 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1210 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1213 internal::Rel_data
<size
>* p_
;
1216 // Accessor class for an ELF Rela relocation.
1218 template<int size
, bool big_endian
>
1222 Rela(const unsigned char* p
)
1223 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1226 template<typename File
>
1227 Rela(File
* file
, typename
File::Location loc
)
1228 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1229 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1232 typename Elf_types
<size
>::Elf_Addr
1233 get_r_offset() const
1234 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1236 typename Elf_types
<size
>::Elf_WXword
1238 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1240 typename Elf_types
<size
>::Elf_Swxword
1241 get_r_addend() const
1242 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1245 const internal::Rela_data
<size
>* p_
;
1248 // Writer class for an ELF Rela relocation.
1250 template<int size
, bool big_endian
>
1254 Rela_write(unsigned char* p
)
1255 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1259 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1260 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1263 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1264 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1267 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1268 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1271 internal::Rela_data
<size
>* p_
;
1274 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1275 // PT_DYNAMIC segment.
1277 template<int size
, bool big_endian
>
1281 Dyn(const unsigned char* p
)
1282 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1285 template<typename File
>
1286 Dyn(File
* file
, typename
File::Location loc
)
1287 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1288 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1291 typename Elf_types
<size
>::Elf_Swxword
1293 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1295 typename Elf_types
<size
>::Elf_WXword
1297 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1299 typename Elf_types
<size
>::Elf_Addr
1301 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1304 const internal::Dyn_data
<size
>* p_
;
1307 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1309 template<int size
, bool big_endian
>
1313 Verdef(const unsigned char* p
)
1314 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1317 template<typename File
>
1318 Verdef(File
* file
, typename
File::Location loc
)
1319 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1320 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1324 get_vd_version() const
1325 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1328 get_vd_flags() const
1329 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1333 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1337 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1341 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1345 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1349 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1352 const internal::Verdef_data
* p_
;
1355 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1358 template<int size
, bool big_endian
>
1362 Verdaux(const unsigned char* p
)
1363 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1366 template<typename File
>
1367 Verdaux(File
* file
, typename
File::Location loc
)
1368 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1369 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1373 get_vda_name() const
1374 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1377 get_vda_next() const
1378 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1381 const internal::Verdaux_data
* p_
;
1384 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1386 template<int size
, bool big_endian
>
1390 Verneed(const unsigned char* p
)
1391 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1394 template<typename File
>
1395 Verneed(File
* file
, typename
File::Location loc
)
1396 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1397 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1401 get_vn_version() const
1402 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1406 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1410 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1414 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1418 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1421 const internal::Verneed_data
* p_
;
1424 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1427 template<int size
, bool big_endian
>
1431 Vernaux(const unsigned char* p
)
1432 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1435 template<typename File
>
1436 Vernaux(File
* file
, typename
File::Location loc
)
1437 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1438 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1442 get_vna_hash() const
1443 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1446 get_vna_flags() const
1447 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1450 get_vna_other() const
1451 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1454 get_vna_name() const
1455 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1458 get_vna_next() const
1459 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1462 const internal::Vernaux_data
* p_
;
1466 } // End namespace elfcpp.
1468 #endif // !defined(ELFPCP_H)