1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // This is the external interface for elfcpp.
8 #include "elfcpp_swap.h"
17 // These types are always the same size.
19 typedef uint16_t Elf_Half;
20 typedef uint32_t Elf_Word;
21 typedef int32_t Elf_Sword;
22 typedef uint64_t Elf_Xword;
23 typedef int64_t Elf_Sxword;
25 // These types vary in size depending on the ELF file class. The
26 // template parameter should be 32 or 64.
34 typedef uint32_t Elf_Addr;
35 typedef uint32_t Elf_Off;
36 typedef uint32_t Elf_WXword;
37 typedef int32_t Elf_Swxword;
43 typedef uint64_t Elf_Addr;
44 typedef uint64_t Elf_Off;
45 typedef uint64_t Elf_WXword;
46 typedef int64_t Elf_Swxword;
49 // Offsets within the Ehdr e_ident field.
51 const int EI_MAG0 = 0;
52 const int EI_MAG1 = 1;
53 const int EI_MAG2 = 2;
54 const int EI_MAG3 = 3;
55 const int EI_CLASS = 4;
56 const int EI_DATA = 5;
57 const int EI_VERSION = 6;
58 const int EI_OSABI = 7;
59 const int EI_ABIVERSION = 8;
61 const int EI_NIDENT = 16;
63 // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
65 const int ELFMAG0 = 0x7f;
66 const int ELFMAG1 = 'E';
67 const int ELFMAG2 = 'L';
68 const int ELFMAG3 = 'F';
70 // The valid values found in Ehdr e_ident[EI_CLASS].
79 // The valid values found in Ehdr e_ident[EI_DATA].
88 // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
96 // The valid values found in Ehdr e_ident[EI_OSABI].
103 // ELFOSABI_LINUX is not listed in the ELF standard.
105 // ELFOSABI_HURD is not listed in the ELF standard.
107 ELFOSABI_SOLARIS = 6,
110 ELFOSABI_FREEBSD = 9,
112 ELFOSABI_MODESTO = 11,
113 ELFOSABI_OPENBSD = 12,
114 ELFOSABI_OPENVMS = 13,
117 // A GNU extension for the ARM.
119 // A GNU extension for the MSP.
120 ELFOSABI_STANDALONE = 255
123 // The valid values found in the Ehdr e_type field.
138 // The valid values found in the Ehdr e_machine field.
148 // 6 used to be EM_486
153 // 11 was the old Sparc V9 ABI.
154 // 12 through 14 are reserved.
157 // Some old PowerPC object files use 17.
164 // 23 through 35 are served.
228 // Some old picoJava object files use 99 (EM_PJ is correct).
241 EM_ALTERA_NIOS2 = 113,
249 // Infineon Technologies 16-bit microcontroller with C166-V2 core.
252 EM_XSTORMY16 = 0xad45,
259 // Old AVR objects used 0x1057 (EM_AVR is correct).
260 // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
261 // Old FR30 objects used 0x3330 (EM_FR30 is correct).
262 // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OPENRISC is correct).
263 // Old D10V objects used 0x7650 (EM_D10V is correct).
264 // Old D30V objects used 0x7676 (EM_D30V is correct).
265 // Old IP2X objects used 0x8217 (EM_IP2K is correct).
266 // Old PowerPC objects used 0x9025 (EM_PPC is correct).
267 // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
268 // Old M32R objects used 0x9041 (EM_M32R is correct).
269 // Old V850 objects used 0x9080 (EM_V850 is correct).
270 // Old S/390 objects used 0xa390 (EM_S390 is correct).
271 // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
272 // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
273 // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
276 // Special section indices.
281 SHN_LORESERVE = 0xff00,
289 SHN_HIRESERVE = 0xffff
292 // The valid values found in the Shdr sh_type field.
310 SHT_PREINIT_ARRAY = 16,
312 SHT_SYMTAB_SHNDX = 18,
313 SHT_LOOS = 0x60000000,
314 SHT_HIOS = 0x6fffffff,
315 SHT_LOPROC = 0x70000000,
316 SHT_HIPROC = 0x7fffffff,
317 SHT_LOUSER = 0x80000000,
318 SHT_HIUSER = 0xffffffff,
319 // The remaining values are not in the standard.
320 // List of prelink dependencies.
321 SHT_GNU_LIBLIST = 0x6ffffff7,
322 // Versions defined by file.
323 SHT_SUNW_verdef = 0x6ffffffd,
324 SHT_GNU_verdef = 0x6ffffffd,
325 // Versions needed by file.
326 SHT_SUNW_verneed = 0x6ffffffe,
327 SHT_GNU_verneed = 0x6ffffffe,
329 SHT_SUNW_versym = 0x6fffffff,
330 SHT_GNU_versym = 0x6fffffff,
333 // The valid bit flags found in the Shdr sh_flags field.
342 SHF_INFO_LINK = 0x40,
343 SHF_LINK_ORDER = 0x80,
344 SHF_OS_NONCONFORMING = 0x100,
347 SHF_MASKOS = 0x0ff00000,
348 SHF_MASKPROC = 0xf0000000
351 // Bit flags which appear in the first 32-bit word of the section data
352 // of a SHT_GROUP section.
357 GRP_MASKOS = 0x0ff00000,
358 GRP_MASKPROC = 0xf0000000
361 // The valid values found in the Phdr p_type field.
373 PT_LOOS = 0x60000000,
374 PT_HIOS = 0x6fffffff,
375 PT_LOPROC = 0x70000000,
376 PT_HIPROC = 0x7fffffff,
377 // The remaining values are not in the standard.
378 // Frame unwind information.
379 PT_GNU_EH_FRAME = 0x6474e550,
380 PT_SUNW_EH_FRAME = 0x6474e550,
382 PT_GNU_STACK = 0x6474e551,
383 // Read only after relocation.
384 PT_GNU_RELRO = 0x6474e552
387 // The valid bit flags found in the Phdr p_flags field.
394 PF_MASKOS = 0x0ff00000,
395 PF_MASKPROC = 0xf0000000
398 // Symbol binding from Sym st_info field.
411 // Symbol types from Sym st_info field.
429 elf_st_bind(unsigned char info)
431 return static_cast<STB>(info >> 4);
435 elf_st_type(unsigned char info)
437 return static_cast<STT>(info & 0xf);
441 elf_st_info(STB bind, STT type)
443 return ((static_cast<unsigned char>(bind) << 4)
444 + (static_cast<unsigned char>(type) & 0xf));
447 // Symbol visibility from Sym st_other field.
458 elf_st_visibility(unsigned char other)
460 return static_cast<STV>(other & 0x3);
464 elf_st_nonvis(unsigned char other)
466 return static_cast<STV>(other >> 2);
470 elf_st_other(STV vis, unsigned char nonvis)
472 return ((nonvis << 2)
473 + (static_cast<unsigned char>(vis) & 3));
476 // Reloc information from Rel/Rela r_info field.
480 elf_r_sym(typename Elf_types<size>::Elf_WXword);
484 elf_r_sym<32>(Elf_Word v)
491 elf_r_sym<64>(Elf_Xword v)
498 elf_r_type(typename Elf_types<size>::Elf_WXword);
502 elf_r_type<32>(Elf_Word v)
509 elf_r_type<64>(Elf_Xword v)
511 return v & 0xffffffff;
515 typename Elf_types<size>::Elf_WXword
516 elf_r_info(unsigned int s, unsigned int t);
520 elf_r_info<32>(unsigned int s, unsigned int t)
522 return (s << 8) + (t & 0xff);
527 elf_r_info<64>(unsigned int s, unsigned int t)
529 return (static_cast<Elf_Xword>(s) << 32) + (t & 0xffffffff);
532 // Dynamic tags found in the PT_DYNAMIC segment.
563 DT_INIT_ARRAYSZ = 27,
564 DT_FINI_ARRAYSZ = 28,
568 DT_PREINIT_ARRAY = 33,
569 DT_PREINIT_ARRAYSZ = 33,
570 DT_LOOS = 0x6000000d,
571 DT_HIOS = 0x6ffff000,
572 DT_LOPROC = 0x70000000,
573 DT_HIPROC = 0x7fffffff,
575 // The remaining values are extensions used by GNU or Solaris.
576 DT_VALRNGLO = 0x6ffffd00,
577 DT_GNU_PRELINKED = 0x6ffffdf5,
578 DT_GNU_CONFLICTSZ = 0x6ffffdf6,
579 DT_GNU_LIBLISTSZ = 0x6ffffdf7,
580 DT_CHECKSUM = 0x6ffffdf8,
581 DT_PLTPADSZ = 0x6ffffdf9,
582 DT_MOVEENT = 0x6ffffdfa,
583 DT_MOVESZ = 0x6ffffdfb,
584 DT_FEATURE = 0x6ffffdfc,
585 DT_POSFLAG_1 = 0x6ffffdfd,
586 DT_SYMINSZ = 0x6ffffdfe,
587 DT_SYMINENT = 0x6ffffdff,
588 DT_VALRNGHI = 0x6ffffdff,
590 DT_ADDRRNGLO = 0x6ffffe00,
591 DT_GNU_HASH = 0x6ffffef5,
592 DT_TLSDESC_PLT = 0x6ffffef6,
593 DT_TLSDESC_GOT = 0x6ffffef7,
594 DT_GNU_CONFLICT = 0x6ffffef8,
595 DT_GNU_LIBLIST = 0x6ffffef9,
596 DT_CONFIG = 0x6ffffefa,
597 DT_DEPAUDIT = 0x6ffffefb,
598 DT_AUDIT = 0x6ffffefc,
599 DT_PLTPAD = 0x6ffffefd,
600 DT_MOVETAB = 0x6ffffefe,
601 DT_SYMINFO = 0x6ffffeff,
602 DT_ADDRRNGHI = 0x6ffffeff,
604 DT_RELACOUNT = 0x6ffffff9,
605 DT_RELCOUNT = 0x6ffffffa,
606 DT_FLAGS_1 = 0x6ffffffb,
607 DT_VERDEF = 0x6ffffffc,
608 DT_VERDEFNUM = 0x6ffffffd,
609 DT_VERNEED = 0x6ffffffe,
610 DT_VERNEEDNUM = 0x6fffffff,
612 DT_VERSYM = 0x6ffffff0,
614 DT_AUXILIARY = 0x7ffffffd,
615 DT_USED = 0x7ffffffe,
616 DT_FILTER = 0x7fffffff
619 // Flags found in the DT_FLAGS dynamic element.
630 // Version numbers which appear in the vd_version field of a Verdef
633 const int VER_DEF_NONE = 0;
634 const int VER_DEF_CURRENT = 1;
636 // Version numbers which appear in the vn_version field of a Verneed
639 const int VER_NEED_NONE = 0;
640 const int VER_NEED_CURRENT = 1;
642 // Bit flags which appear in vd_flags of Verdef and vna_flags of
645 const int VER_FLG_BASE = 0x1;
646 const int VER_FLG_WEAK = 0x2;
648 // Special constants found in the SHT_GNU_versym entries.
650 const int VER_NDX_LOCAL = 0;
651 const int VER_NDX_GLOBAL = 1;
653 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
654 // the symbol is hidden and can only be seen when referenced using an
655 // explicit version number. This is a GNU extension.
657 const int VERSYM_HIDDEN = 0x8000;
659 // This is the mask for the rest of the data in a word read from a
660 // SHT_GNU_versym section.
662 const int VERSYM_VERSION = 0x7fff;
664 } // End namespace elfcpp.
666 // Include internal details after defining the types.
667 #include "elfcpp_internal.h"
672 // The offset of the ELF file header in the ELF file.
674 const int file_header_offset = 0;
676 // ELF structure sizes.
681 // Size of ELF file header.
682 static const int ehdr_size = sizeof(internal::Ehdr_data<size>);
683 // Size of ELF segment header.
684 static const int phdr_size = sizeof(internal::Phdr_data<size>);
685 // Size of ELF section header.
686 static const int shdr_size = sizeof(internal::Shdr_data<size>);
687 // Size of ELF symbol table entry.
688 static const int sym_size = sizeof(internal::Sym_data<size>);
689 // Sizes of ELF reloc entries.
690 static const int rel_size = sizeof(internal::Rel_data<size>);
691 static const int rela_size = sizeof(internal::Rela_data<size>);
692 // Size of ELF dynamic entry.
693 static const int dyn_size = sizeof(internal::Dyn_data<size>);
694 // Size of ELF version structures.
695 static const int verdef_size = sizeof(internal::Verdef_data);
696 static const int verdaux_size = sizeof(internal::Verdaux_data);
697 static const int verneed_size = sizeof(internal::Verneed_data);
698 static const int vernaux_size = sizeof(internal::Vernaux_data);
701 // Accessor class for the ELF file header.
703 template<int size, bool big_endian>
707 Ehdr(const unsigned char* p)
708 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(p))
711 template<typename File>
712 Ehdr(File* file, typename File::Location loc)
713 : p_(reinterpret_cast<const internal::Ehdr_data<size>*>(
714 file->view(loc.file_offset, loc.data_size).data()))
719 { return this->p_->e_ident; }
723 { return Convert<16, big_endian>::convert_host(this->p_->e_type); }
726 get_e_machine() const
727 { return Convert<16, big_endian>::convert_host(this->p_->e_machine); }
730 get_e_version() const
731 { return Convert<32, big_endian>::convert_host(this->p_->e_version); }
733 typename Elf_types<size>::Elf_Addr
735 { return Convert<size, big_endian>::convert_host(this->p_->e_entry); }
737 typename Elf_types<size>::Elf_Off
739 { return Convert<size, big_endian>::convert_host(this->p_->e_phoff); }
741 typename Elf_types<size>::Elf_Off
743 { return Convert<size, big_endian>::convert_host(this->p_->e_shoff); }
747 { return Convert<32, big_endian>::convert_host(this->p_->e_flags); }
751 { return Convert<16, big_endian>::convert_host(this->p_->e_ehsize); }
754 get_e_phentsize() const
755 { return Convert<16, big_endian>::convert_host(this->p_->e_phentsize); }
759 { return Convert<16, big_endian>::convert_host(this->p_->e_phnum); }
762 get_e_shentsize() const
763 { return Convert<16, big_endian>::convert_host(this->p_->e_shentsize); }
767 { return Convert<16, big_endian>::convert_host(this->p_->e_shnum); }
770 get_e_shstrndx() const
771 { return Convert<16, big_endian>::convert_host(this->p_->e_shstrndx); }
774 const internal::Ehdr_data<size>* p_;
777 // Write class for the ELF file header.
779 template<int size, bool big_endian>
783 Ehdr_write(unsigned char* p)
784 : p_(reinterpret_cast<internal::Ehdr_data<size>*>(p))
788 put_e_ident(const unsigned char v[EI_NIDENT]) const
789 { memcpy(this->p_->e_ident, v, EI_NIDENT); }
792 put_e_type(Elf_Half v)
793 { this->p_->e_type = Convert<16, big_endian>::convert_host(v); }
796 put_e_machine(Elf_Half v)
797 { this->p_->e_machine = Convert<16, big_endian>::convert_host(v); }
800 put_e_version(Elf_Word v)
801 { this->p_->e_version = Convert<32, big_endian>::convert_host(v); }
804 put_e_entry(typename Elf_types<size>::Elf_Addr v)
805 { this->p_->e_entry = Convert<size, big_endian>::convert_host(v); }
808 put_e_phoff(typename Elf_types<size>::Elf_Off v)
809 { this->p_->e_phoff = Convert<size, big_endian>::convert_host(v); }
812 put_e_shoff(typename Elf_types<size>::Elf_Off v)
813 { this->p_->e_shoff = Convert<size, big_endian>::convert_host(v); }
816 put_e_flags(Elf_Word v)
817 { this->p_->e_flags = Convert<32, big_endian>::convert_host(v); }
820 put_e_ehsize(Elf_Half v)
821 { this->p_->e_ehsize = Convert<16, big_endian>::convert_host(v); }
824 put_e_phentsize(Elf_Half v)
825 { this->p_->e_phentsize = Convert<16, big_endian>::convert_host(v); }
828 put_e_phnum(Elf_Half v)
829 { this->p_->e_phnum = Convert<16, big_endian>::convert_host(v); }
832 put_e_shentsize(Elf_Half v)
833 { this->p_->e_shentsize = Convert<16, big_endian>::convert_host(v); }
836 put_e_shnum(Elf_Half v)
837 { this->p_->e_shnum = Convert<16, big_endian>::convert_host(v); }
840 put_e_shstrndx(Elf_Half v)
841 { this->p_->e_shstrndx = Convert<16, big_endian>::convert_host(v); }
844 internal::Ehdr_data<size>* p_;
847 // Accessor class for an ELF section header.
849 template<int size, bool big_endian>
853 Shdr(const unsigned char* p)
854 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(p))
857 template<typename File>
858 Shdr(File* file, typename File::Location loc)
859 : p_(reinterpret_cast<const internal::Shdr_data<size>*>(
860 file->view(loc.file_offset, loc.data_size).data()))
865 { return Convert<32, big_endian>::convert_host(this->p_->sh_name); }
869 { return Convert<32, big_endian>::convert_host(this->p_->sh_type); }
871 typename Elf_types<size>::Elf_WXword
873 { return Convert<size, big_endian>::convert_host(this->p_->sh_flags); }
875 typename Elf_types<size>::Elf_Addr
877 { return Convert<size, big_endian>::convert_host(this->p_->sh_addr); }
879 typename Elf_types<size>::Elf_Off
880 get_sh_offset() const
881 { return Convert<size, big_endian>::convert_host(this->p_->sh_offset); }
883 typename Elf_types<size>::Elf_WXword
885 { return Convert<size, big_endian>::convert_host(this->p_->sh_size); }
889 { return Convert<32, big_endian>::convert_host(this->p_->sh_link); }
893 { return Convert<32, big_endian>::convert_host(this->p_->sh_info); }
895 typename Elf_types<size>::Elf_WXword
896 get_sh_addralign() const
898 Convert<size, big_endian>::convert_host(this->p_->sh_addralign); }
900 typename Elf_types<size>::Elf_WXword
901 get_sh_entsize() const
902 { return Convert<size, big_endian>::convert_host(this->p_->sh_entsize); }
905 const internal::Shdr_data<size>* p_;
908 // Write class for an ELF section header.
910 template<int size, bool big_endian>
914 Shdr_write(unsigned char* p)
915 : p_(reinterpret_cast<internal::Shdr_data<size>*>(p))
919 put_sh_name(Elf_Word v)
920 { this->p_->sh_name = Convert<32, big_endian>::convert_host(v); }
923 put_sh_type(Elf_Word v)
924 { this->p_->sh_type = Convert<32, big_endian>::convert_host(v); }
927 put_sh_flags(typename Elf_types<size>::Elf_WXword v)
928 { this->p_->sh_flags = Convert<size, big_endian>::convert_host(v); }
931 put_sh_addr(typename Elf_types<size>::Elf_Addr v)
932 { this->p_->sh_addr = Convert<size, big_endian>::convert_host(v); }
935 put_sh_offset(typename Elf_types<size>::Elf_Off v)
936 { this->p_->sh_offset = Convert<size, big_endian>::convert_host(v); }
939 put_sh_size(typename Elf_types<size>::Elf_WXword v)
940 { this->p_->sh_size = Convert<size, big_endian>::convert_host(v); }
943 put_sh_link(Elf_Word v)
944 { this->p_->sh_link = Convert<32, big_endian>::convert_host(v); }
947 put_sh_info(Elf_Word v)
948 { this->p_->sh_info = Convert<32, big_endian>::convert_host(v); }
951 put_sh_addralign(typename Elf_types<size>::Elf_WXword v)
952 { this->p_->sh_addralign = Convert<size, big_endian>::convert_host(v); }
955 put_sh_entsize(typename Elf_types<size>::Elf_WXword v)
956 { this->p_->sh_entsize = Convert<size, big_endian>::convert_host(v); }
959 internal::Shdr_data<size>* p_;
962 // Accessor class for an ELF segment header.
964 template<int size, bool big_endian>
968 Phdr(const unsigned char* p)
969 : p_(reinterpret_cast<const internal::Phdr_data<size>*>(p))
972 template<typename File>
973 Phdr(File* file, typename File::Location loc)
974 : p_(reinterpret_cast<internal::Phdr_data<size>*>(
975 file->view(loc.file_offset, loc.data_size).data()))
980 { return Convert<32, big_endian>::convert_host(this->p_->p_type); }
982 typename Elf_types<size>::Elf_Off
984 { return Convert<size, big_endian>::convert_host(this->p_->p_offset); }
986 typename Elf_types<size>::Elf_Addr
988 { return Convert<size, big_endian>::convert_host(this->p_->p_vaddr); }
990 typename Elf_types<size>::Elf_Addr
992 { return Convert<size, big_endian>::convert_host(this->p_->p_paddr); }
994 typename Elf_types<size>::Elf_WXword
996 { return Convert<size, big_endian>::convert_host(this->p_->p_filesz); }
998 typename Elf_types<size>::Elf_WXword
1000 { return Convert<size, big_endian>::convert_host(this->p_->p_memsz); }
1004 { return Convert<32, big_endian>::convert_host(this->p_->p_flags); }
1006 typename Elf_types<size>::Elf_WXword
1008 { return Convert<size, big_endian>::convert_host(this->p_->p_align); }
1011 const internal::Phdr_data<size>* p_;
1014 // Write class for an ELF segment header.
1016 template<int size, bool big_endian>
1020 Phdr_write(unsigned char* p)
1021 : p_(reinterpret_cast<internal::Phdr_data<size>*>(p))
1025 put_p_type(Elf_Word v)
1026 { this->p_->p_type = Convert<32, big_endian>::convert_host(v); }
1029 put_p_offset(typename Elf_types<size>::Elf_Off v)
1030 { this->p_->p_offset = Convert<size, big_endian>::convert_host(v); }
1033 put_p_vaddr(typename Elf_types<size>::Elf_Addr v)
1034 { this->p_->p_vaddr = Convert<size, big_endian>::convert_host(v); }
1037 put_p_paddr(typename Elf_types<size>::Elf_Addr v)
1038 { this->p_->p_paddr = Convert<size, big_endian>::convert_host(v); }
1041 put_p_filesz(typename Elf_types<size>::Elf_WXword v)
1042 { this->p_->p_filesz = Convert<size, big_endian>::convert_host(v); }
1045 put_p_memsz(typename Elf_types<size>::Elf_WXword v)
1046 { this->p_->p_memsz = Convert<size, big_endian>::convert_host(v); }
1049 put_p_flags(Elf_Word v)
1050 { this->p_->p_flags = Convert<32, big_endian>::convert_host(v); }
1053 put_p_align(typename Elf_types<size>::Elf_WXword v)
1054 { this->p_->p_align = Convert<size, big_endian>::convert_host(v); }
1057 internal::Phdr_data<size>* p_;
1060 // Accessor class for an ELF symbol table entry.
1062 template<int size, bool big_endian>
1066 Sym(const unsigned char* p)
1067 : p_(reinterpret_cast<const internal::Sym_data<size>*>(p))
1070 template<typename File>
1071 Sym(File* file, typename File::Location loc)
1072 : p_(reinterpret_cast<const internal::Sym_data<size>*>(
1073 file->view(loc.file_offset, loc.data_size).data()))
1078 { return Convert<32, big_endian>::convert_host(this->p_->st_name); }
1080 typename Elf_types<size>::Elf_Addr
1081 get_st_value() const
1082 { return Convert<size, big_endian>::convert_host(this->p_->st_value); }
1084 typename Elf_types<size>::Elf_WXword
1086 { return Convert<size, big_endian>::convert_host(this->p_->st_size); }
1090 { return this->p_->st_info; }
1094 { return elf_st_bind(this->get_st_info()); }
1098 { return elf_st_type(this->get_st_info()); }
1101 get_st_other() const
1102 { return this->p_->st_other; }
1105 get_st_visibility() const
1106 { return elf_st_visibility(this->get_st_other()); }
1109 get_st_nonvis() const
1110 { return elf_st_nonvis(this->get_st_other()); }
1113 get_st_shndx() const
1114 { return Convert<16, big_endian>::convert_host(this->p_->st_shndx); }
1117 const internal::Sym_data<size>* p_;
1120 // Writer class for an ELF symbol table entry.
1122 template<int size, bool big_endian>
1126 Sym_write(unsigned char* p)
1127 : p_(reinterpret_cast<internal::Sym_data<size>*>(p))
1131 put_st_name(Elf_Word v)
1132 { this->p_->st_name = Convert<32, big_endian>::convert_host(v); }
1135 put_st_value(typename Elf_types<size>::Elf_Addr v)
1136 { this->p_->st_value = Convert<size, big_endian>::convert_host(v); }
1139 put_st_size(typename Elf_types<size>::Elf_WXword v)
1140 { this->p_->st_size = Convert<size, big_endian>::convert_host(v); }
1143 put_st_info(unsigned char v)
1144 { this->p_->st_info = v; }
1147 put_st_info(STB bind, STT type)
1148 { this->p_->st_info = elf_st_info(bind, type); }
1151 put_st_other(unsigned char v)
1152 { this->p_->st_other = v; }
1155 put_st_other(STV vis, unsigned char nonvis)
1156 { this->p_->st_other = elf_st_other(vis, nonvis); }
1159 put_st_shndx(Elf_Half v)
1160 { this->p_->st_shndx = Convert<16, big_endian>::convert_host(v); }
1162 Sym<size, big_endian>
1164 { return Sym<size, big_endian>(reinterpret_cast<unsigned char*>(this->p_)); }
1167 internal::Sym_data<size>* p_;
1170 // Accessor classes for an ELF REL relocation entry.
1172 template<int size, bool big_endian>
1176 Rel(const unsigned char* p)
1177 : p_(reinterpret_cast<const internal::Rel_data<size>*>(p))
1180 template<typename File>
1181 Rel(File* file, typename File::Location loc)
1182 : p_(reinterpret_cast<const internal::Rel_data<size>*>(
1183 file->view(loc.file_offset, loc.data_size).data()))
1186 typename Elf_types<size>::Elf_Addr
1187 get_r_offset() const
1188 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1190 typename Elf_types<size>::Elf_WXword
1192 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1195 const internal::Rel_data<size>* p_;
1198 // Writer class for an ELF Rel relocation.
1200 template<int size, bool big_endian>
1204 Rel_write(unsigned char* p)
1205 : p_(reinterpret_cast<internal::Rel_data<size>*>(p))
1209 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1210 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1213 put_r_info(typename Elf_types<size>::Elf_WXword v)
1214 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1217 internal::Rel_data<size>* p_;
1220 // Accessor class for an ELF Rela relocation.
1222 template<int size, bool big_endian>
1226 Rela(const unsigned char* p)
1227 : p_(reinterpret_cast<const internal::Rela_data<size>*>(p))
1230 template<typename File>
1231 Rela(File* file, typename File::Location loc)
1232 : p_(reinterpret_cast<const internal::Rela_data<size>*>(
1233 file->view(loc.file_offset, loc.data_size).data()))
1236 typename Elf_types<size>::Elf_Addr
1237 get_r_offset() const
1238 { return Convert<size, big_endian>::convert_host(this->p_->r_offset); }
1240 typename Elf_types<size>::Elf_WXword
1242 { return Convert<size, big_endian>::convert_host(this->p_->r_info); }
1244 typename Elf_types<size>::Elf_Swxword
1245 get_r_addend() const
1246 { return Convert<size, big_endian>::convert_host(this->p_->r_addend); }
1249 const internal::Rela_data<size>* p_;
1252 // Writer class for an ELF Rela relocation.
1254 template<int size, bool big_endian>
1258 Rela_write(unsigned char* p)
1259 : p_(reinterpret_cast<internal::Rela_data<size>*>(p))
1263 put_r_offset(typename Elf_types<size>::Elf_Addr v)
1264 { this->p_->r_offset = Convert<size, big_endian>::convert_host(v); }
1267 put_r_info(typename Elf_types<size>::Elf_WXword v)
1268 { this->p_->r_info = Convert<size, big_endian>::convert_host(v); }
1271 put_r_addend(typename Elf_types<size>::Elf_Swxword v)
1272 { this->p_->r_addend = Convert<size, big_endian>::convert_host(v); }
1275 internal::Rela_data<size>* p_;
1278 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1279 // PT_DYNAMIC segment.
1281 template<int size, bool big_endian>
1285 Dyn(const unsigned char* p)
1286 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(p))
1289 template<typename File>
1290 Dyn(File* file, typename File::Location loc)
1291 : p_(reinterpret_cast<const internal::Dyn_data<size>*>(
1292 file->view(loc.file_offset, loc.data_size).data()))
1295 typename Elf_types<size>::Elf_Swxword
1297 { return Convert<size, big_endian>::convert_host(this->p_->d_tag); }
1299 typename Elf_types<size>::Elf_WXword
1301 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1303 typename Elf_types<size>::Elf_Addr
1305 { return Convert<size, big_endian>::convert_host(this->p_->d_val); }
1308 const internal::Dyn_data<size>* p_;
1311 // Write class for an entry in the SHT_DYNAMIC section.
1313 template<int size, bool big_endian>
1317 Dyn_write(unsigned char* p)
1318 : p_(reinterpret_cast<internal::Dyn_data<size>*>(p))
1322 put_d_tag(typename Elf_types<size>::Elf_Swxword v)
1323 { this->p_->d_tag = Convert<size, big_endian>::convert_host(v); }
1326 put_d_val(typename Elf_types<size>::Elf_WXword v)
1327 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1330 put_d_ptr(typename Elf_types<size>::Elf_Addr v)
1331 { this->p_->d_val = Convert<size, big_endian>::convert_host(v); }
1334 internal::Dyn_data<size>* p_;
1337 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1339 template<int size, bool big_endian>
1343 Verdef(const unsigned char* p)
1344 : p_(reinterpret_cast<const internal::Verdef_data*>(p))
1347 template<typename File>
1348 Verdef(File* file, typename File::Location loc)
1349 : p_(reinterpret_cast<const internal::Verdef_data*>(
1350 file->view(loc.file_offset, loc.data_size).data()))
1354 get_vd_version() const
1355 { return Convert<16, big_endian>::convert_host(this->p_->vd_version); }
1358 get_vd_flags() const
1359 { return Convert<16, big_endian>::convert_host(this->p_->vd_flags); }
1363 { return Convert<16, big_endian>::convert_host(this->p_->vd_ndx); }
1367 { return Convert<16, big_endian>::convert_host(this->p_->vd_cnt); }
1371 { return Convert<32, big_endian>::convert_host(this->p_->vd_hash); }
1375 { return Convert<32, big_endian>::convert_host(this->p_->vd_aux); }
1379 { return Convert<32, big_endian>::convert_host(this->p_->vd_next); }
1382 const internal::Verdef_data* p_;
1385 template<int size, bool big_endian>
1389 Verdef_write(unsigned char* p)
1390 : p_(reinterpret_cast<internal::Verdef_data*>(p))
1394 set_vd_version(Elf_Half v)
1395 { this->p_->vd_version = Convert<16, big_endian>::convert_host(v); }
1398 set_vd_flags(Elf_Half v)
1399 { this->p_->vd_flags = Convert<16, big_endian>::convert_host(v); }
1402 set_vd_ndx(Elf_Half v)
1403 { this->p_->vd_ndx = Convert<16, big_endian>::convert_host(v); }
1406 set_vd_cnt(Elf_Half v)
1407 { this->p_->vd_cnt = Convert<16, big_endian>::convert_host(v); }
1410 set_vd_hash(Elf_Word v)
1411 { this->p_->vd_hash = Convert<32, big_endian>::convert_host(v); }
1414 set_vd_aux(Elf_Word v)
1415 { this->p_->vd_aux = Convert<32, big_endian>::convert_host(v); }
1418 set_vd_next(Elf_Word v)
1419 { this->p_->vd_next = Convert<32, big_endian>::convert_host(v); }
1422 internal::Verdef_data* p_;
1425 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1428 template<int size, bool big_endian>
1432 Verdaux(const unsigned char* p)
1433 : p_(reinterpret_cast<const internal::Verdaux_data*>(p))
1436 template<typename File>
1437 Verdaux(File* file, typename File::Location loc)
1438 : p_(reinterpret_cast<const internal::Verdaux_data*>(
1439 file->view(loc.file_offset, loc.data_size).data()))
1443 get_vda_name() const
1444 { return Convert<32, big_endian>::convert_host(this->p_->vda_name); }
1447 get_vda_next() const
1448 { return Convert<32, big_endian>::convert_host(this->p_->vda_next); }
1451 const internal::Verdaux_data* p_;
1454 template<int size, bool big_endian>
1458 Verdaux_write(unsigned char* p)
1459 : p_(reinterpret_cast<internal::Verdaux_data*>(p))
1463 set_vda_name(Elf_Word v)
1464 { this->p_->vda_name = Convert<32, big_endian>::convert_host(v); }
1467 set_vda_next(Elf_Word v)
1468 { this->p_->vda_next = Convert<32, big_endian>::convert_host(v); }
1471 internal::Verdaux_data* p_;
1474 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1476 template<int size, bool big_endian>
1480 Verneed(const unsigned char* p)
1481 : p_(reinterpret_cast<const internal::Verneed_data*>(p))
1484 template<typename File>
1485 Verneed(File* file, typename File::Location loc)
1486 : p_(reinterpret_cast<const internal::Verneed_data*>(
1487 file->view(loc.file_offset, loc.data_size).data()))
1491 get_vn_version() const
1492 { return Convert<16, big_endian>::convert_host(this->p_->vn_version); }
1496 { return Convert<16, big_endian>::convert_host(this->p_->vn_cnt); }
1500 { return Convert<32, big_endian>::convert_host(this->p_->vn_file); }
1504 { return Convert<32, big_endian>::convert_host(this->p_->vn_aux); }
1508 { return Convert<32, big_endian>::convert_host(this->p_->vn_next); }
1511 const internal::Verneed_data* p_;
1514 template<int size, bool big_endian>
1518 Verneed_write(unsigned char* p)
1519 : p_(reinterpret_cast<internal::Verneed_data*>(p))
1523 set_vn_version(Elf_Half v)
1524 { this->p_->vn_version = Convert<16, big_endian>::convert_host(v); }
1527 set_vn_cnt(Elf_Half v)
1528 { this->p_->vn_cnt = Convert<16, big_endian>::convert_host(v); }
1531 set_vn_file(Elf_Word v)
1532 { this->p_->vn_file = Convert<32, big_endian>::convert_host(v); }
1535 set_vn_aux(Elf_Word v)
1536 { this->p_->vn_aux = Convert<32, big_endian>::convert_host(v); }
1539 set_vn_next(Elf_Word v)
1540 { this->p_->vn_next = Convert<32, big_endian>::convert_host(v); }
1543 internal::Verneed_data* p_;
1546 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1549 template<int size, bool big_endian>
1553 Vernaux(const unsigned char* p)
1554 : p_(reinterpret_cast<const internal::Vernaux_data*>(p))
1557 template<typename File>
1558 Vernaux(File* file, typename File::Location loc)
1559 : p_(reinterpret_cast<const internal::Vernaux_data*>(
1560 file->view(loc.file_offset, loc.data_size).data()))
1564 get_vna_hash() const
1565 { return Convert<32, big_endian>::convert_host(this->p_->vna_hash); }
1568 get_vna_flags() const
1569 { return Convert<16, big_endian>::convert_host(this->p_->vna_flags); }
1572 get_vna_other() const
1573 { return Convert<16, big_endian>::convert_host(this->p_->vna_other); }
1576 get_vna_name() const
1577 { return Convert<32, big_endian>::convert_host(this->p_->vna_name); }
1580 get_vna_next() const
1581 { return Convert<32, big_endian>::convert_host(this->p_->vna_next); }
1584 const internal::Vernaux_data* p_;
1587 template<int size, bool big_endian>
1591 Vernaux_write(unsigned char* p)
1592 : p_(reinterpret_cast<internal::Vernaux_data*>(p))
1596 set_vna_hash(Elf_Word v)
1597 { this->p_->vna_hash = Convert<32, big_endian>::convert_host(v); }
1600 set_vna_flags(Elf_Half v)
1601 { this->p_->vna_flags = Convert<16, big_endian>::convert_host(v); }
1604 set_vna_other(Elf_Half v)
1605 { this->p_->vna_other = Convert<16, big_endian>::convert_host(v); }
1608 set_vna_name(Elf_Word v)
1609 { this->p_->vna_name = Convert<32, big_endian>::convert_host(v); }
1612 set_vna_next(Elf_Word v)
1613 { this->p_->vna_next = Convert<32, big_endian>::convert_host(v); }
1616 internal::Vernaux_data* p_;
1619 } // End namespace elfcpp.
1621 #endif // !defined(ELFPCP_H)