dae043469992351b1b4599e00ed166b51b61c617
1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // Copyright 2006, 2007, Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of elfcpp.
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public License
10 // as published by the Free Software Foundation; either version 2, or
11 // (at your option) any later version.
13 // In addition to the permissions in the GNU Library General Public
14 // License, the Free Software Foundation gives you unlimited
15 // permission to link the compiled version of this file into
16 // combinations with other programs, and to distribute those
17 // combinations without any restriction coming from the use of this
18 // file. (The Library Public License restrictions do apply in other
19 // respects; for example, they cover modification of the file, and
20 /// distribution when not linked into a combined executable.)
22 // This program is distributed in the hope that it will be useful, but
23 // WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 // Library General Public License for more details.
27 // You should have received a copy of the GNU Library General Public
28 // License along with this program; if not, write to the Free Software
29 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
32 // This is the external interface for elfcpp.
37 #include "elfcpp_swap.h"
46 // These types are always the same size.
48 typedef uint16_t Elf_Half
;
49 typedef uint32_t Elf_Word
;
50 typedef int32_t Elf_Sword
;
51 typedef uint64_t Elf_Xword
;
52 typedef int64_t Elf_Sxword
;
54 // These types vary in size depending on the ELF file class. The
55 // template parameter should be 32 or 64.
63 typedef uint32_t Elf_Addr
;
64 typedef uint32_t Elf_Off
;
65 typedef uint32_t Elf_WXword
;
66 typedef int32_t Elf_Swxword
;
72 typedef uint64_t Elf_Addr
;
73 typedef uint64_t Elf_Off
;
74 typedef uint64_t Elf_WXword
;
75 typedef int64_t Elf_Swxword
;
78 // Offsets within the Ehdr e_ident field.
80 const int EI_MAG0
= 0;
81 const int EI_MAG1
= 1;
82 const int EI_MAG2
= 2;
83 const int EI_MAG3
= 3;
84 const int EI_CLASS
= 4;
85 const int EI_DATA
= 5;
86 const int EI_VERSION
= 6;
87 const int EI_OSABI
= 7;
88 const int EI_ABIVERSION
= 8;
90 const int EI_NIDENT
= 16;
92 // The valid values found in Ehdr e_ident[EI_MAG0 through EI_MAG3].
94 const int ELFMAG0
= 0x7f;
95 const int ELFMAG1
= 'E';
96 const int ELFMAG2
= 'L';
97 const int ELFMAG3
= 'F';
99 // The valid values found in Ehdr e_ident[EI_CLASS].
108 // The valid values found in Ehdr e_ident[EI_DATA].
117 // The valid values found in Ehdr e_ident[EI_VERSION] and e_version.
125 // The valid values found in Ehdr e_ident[EI_OSABI].
132 // ELFOSABI_LINUX is not listed in the ELF standard.
134 // ELFOSABI_HURD is not listed in the ELF standard.
136 ELFOSABI_SOLARIS
= 6,
139 ELFOSABI_FREEBSD
= 9,
141 ELFOSABI_MODESTO
= 11,
142 ELFOSABI_OPENBSD
= 12,
143 ELFOSABI_OPENVMS
= 13,
146 // A GNU extension for the ARM.
148 // A GNU extension for the MSP.
149 ELFOSABI_STANDALONE
= 255
152 // The valid values found in the Ehdr e_type field.
167 // The valid values found in the Ehdr e_machine field.
177 // 6 used to be EM_486
182 // 11 was the old Sparc V9 ABI.
183 // 12 through 14 are reserved.
186 // Some old PowerPC object files use 17.
193 // 23 through 35 are served.
257 // Some old picoJava object files use 99 (EM_PJ is correct).
270 EM_ALTERA_NIOS2
= 113,
278 // Infineon Technologies 16-bit microcontroller with C166-V2 core.
281 EM_XSTORMY16
= 0xad45,
288 // Old AVR objects used 0x1057 (EM_AVR is correct).
289 // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
290 // Old FR30 objects used 0x3330 (EM_FR30 is correct).
291 // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OPENRISC is correct).
292 // Old D10V objects used 0x7650 (EM_D10V is correct).
293 // Old D30V objects used 0x7676 (EM_D30V is correct).
294 // Old IP2X objects used 0x8217 (EM_IP2K is correct).
295 // Old PowerPC objects used 0x9025 (EM_PPC is correct).
296 // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
297 // Old M32R objects used 0x9041 (EM_M32R is correct).
298 // Old V850 objects used 0x9080 (EM_V850 is correct).
299 // Old S/390 objects used 0xa390 (EM_S390 is correct).
300 // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
301 // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
302 // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
305 // Special section indices.
310 SHN_LORESERVE
= 0xff00,
318 SHN_HIRESERVE
= 0xffff
321 // The valid values found in the Shdr sh_type field.
339 SHT_PREINIT_ARRAY
= 16,
341 SHT_SYMTAB_SHNDX
= 18,
342 SHT_LOOS
= 0x60000000,
343 SHT_HIOS
= 0x6fffffff,
344 SHT_LOPROC
= 0x70000000,
345 SHT_HIPROC
= 0x7fffffff,
346 SHT_LOUSER
= 0x80000000,
347 SHT_HIUSER
= 0xffffffff,
348 // The remaining values are not in the standard.
349 // Object attributes.
350 SHT_GNU_ATTRIBUTES
= 0x6ffffff5,
351 // GNU style dynamic hash table.
352 SHT_GNU_HASH
= 0x6ffffff6,
353 // List of prelink dependencies.
354 SHT_GNU_LIBLIST
= 0x6ffffff7,
355 // Versions defined by file.
356 SHT_SUNW_verdef
= 0x6ffffffd,
357 SHT_GNU_verdef
= 0x6ffffffd,
358 // Versions needed by file.
359 SHT_SUNW_verneed
= 0x6ffffffe,
360 SHT_GNU_verneed
= 0x6ffffffe,
362 SHT_SUNW_versym
= 0x6fffffff,
363 SHT_GNU_versym
= 0x6fffffff,
366 // The valid bit flags found in the Shdr sh_flags field.
375 SHF_INFO_LINK
= 0x40,
376 SHF_LINK_ORDER
= 0x80,
377 SHF_OS_NONCONFORMING
= 0x100,
380 SHF_MASKOS
= 0x0ff00000,
381 SHF_MASKPROC
= 0xf0000000
384 // Bit flags which appear in the first 32-bit word of the section data
385 // of a SHT_GROUP section.
390 GRP_MASKOS
= 0x0ff00000,
391 GRP_MASKPROC
= 0xf0000000
394 // The valid values found in the Phdr p_type field.
406 PT_LOOS
= 0x60000000,
407 PT_HIOS
= 0x6fffffff,
408 PT_LOPROC
= 0x70000000,
409 PT_HIPROC
= 0x7fffffff,
410 // The remaining values are not in the standard.
411 // Frame unwind information.
412 PT_GNU_EH_FRAME
= 0x6474e550,
413 PT_SUNW_EH_FRAME
= 0x6474e550,
415 PT_GNU_STACK
= 0x6474e551,
416 // Read only after relocation.
417 PT_GNU_RELRO
= 0x6474e552
420 // The valid bit flags found in the Phdr p_flags field.
427 PF_MASKOS
= 0x0ff00000,
428 PF_MASKPROC
= 0xf0000000
431 // Symbol binding from Sym st_info field.
444 // Symbol types from Sym st_info field.
462 elf_st_bind(unsigned char info
)
464 return static_cast<STB
>(info
>> 4);
468 elf_st_type(unsigned char info
)
470 return static_cast<STT
>(info
& 0xf);
474 elf_st_info(STB bind
, STT type
)
476 return ((static_cast<unsigned char>(bind
) << 4)
477 + (static_cast<unsigned char>(type
) & 0xf));
480 // Symbol visibility from Sym st_other field.
491 elf_st_visibility(unsigned char other
)
493 return static_cast<STV
>(other
& 0x3);
497 elf_st_nonvis(unsigned char other
)
499 return static_cast<STV
>(other
>> 2);
503 elf_st_other(STV vis
, unsigned char nonvis
)
505 return ((nonvis
<< 2)
506 + (static_cast<unsigned char>(vis
) & 3));
509 // Reloc information from Rel/Rela r_info field.
513 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
517 elf_r_sym
<32>(Elf_Word v
)
524 elf_r_sym
<64>(Elf_Xword v
)
531 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
535 elf_r_type
<32>(Elf_Word v
)
542 elf_r_type
<64>(Elf_Xword v
)
544 return v
& 0xffffffff;
548 typename Elf_types
<size
>::Elf_WXword
549 elf_r_info(unsigned int s
, unsigned int t
);
553 elf_r_info
<32>(unsigned int s
, unsigned int t
)
555 return (s
<< 8) + (t
& 0xff);
560 elf_r_info
<64>(unsigned int s
, unsigned int t
)
562 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
565 // Dynamic tags found in the PT_DYNAMIC segment.
596 DT_INIT_ARRAYSZ
= 27,
597 DT_FINI_ARRAYSZ
= 28,
601 DT_PREINIT_ARRAY
= 33,
602 DT_PREINIT_ARRAYSZ
= 33,
603 DT_LOOS
= 0x6000000d,
604 DT_HIOS
= 0x6ffff000,
605 DT_LOPROC
= 0x70000000,
606 DT_HIPROC
= 0x7fffffff,
608 // The remaining values are extensions used by GNU or Solaris.
609 DT_VALRNGLO
= 0x6ffffd00,
610 DT_GNU_PRELINKED
= 0x6ffffdf5,
611 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
612 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
613 DT_CHECKSUM
= 0x6ffffdf8,
614 DT_PLTPADSZ
= 0x6ffffdf9,
615 DT_MOVEENT
= 0x6ffffdfa,
616 DT_MOVESZ
= 0x6ffffdfb,
617 DT_FEATURE
= 0x6ffffdfc,
618 DT_POSFLAG_1
= 0x6ffffdfd,
619 DT_SYMINSZ
= 0x6ffffdfe,
620 DT_SYMINENT
= 0x6ffffdff,
621 DT_VALRNGHI
= 0x6ffffdff,
623 DT_ADDRRNGLO
= 0x6ffffe00,
624 DT_GNU_HASH
= 0x6ffffef5,
625 DT_TLSDESC_PLT
= 0x6ffffef6,
626 DT_TLSDESC_GOT
= 0x6ffffef7,
627 DT_GNU_CONFLICT
= 0x6ffffef8,
628 DT_GNU_LIBLIST
= 0x6ffffef9,
629 DT_CONFIG
= 0x6ffffefa,
630 DT_DEPAUDIT
= 0x6ffffefb,
631 DT_AUDIT
= 0x6ffffefc,
632 DT_PLTPAD
= 0x6ffffefd,
633 DT_MOVETAB
= 0x6ffffefe,
634 DT_SYMINFO
= 0x6ffffeff,
635 DT_ADDRRNGHI
= 0x6ffffeff,
637 DT_RELACOUNT
= 0x6ffffff9,
638 DT_RELCOUNT
= 0x6ffffffa,
639 DT_FLAGS_1
= 0x6ffffffb,
640 DT_VERDEF
= 0x6ffffffc,
641 DT_VERDEFNUM
= 0x6ffffffd,
642 DT_VERNEED
= 0x6ffffffe,
643 DT_VERNEEDNUM
= 0x6fffffff,
645 DT_VERSYM
= 0x6ffffff0,
647 DT_AUXILIARY
= 0x7ffffffd,
648 DT_USED
= 0x7ffffffe,
649 DT_FILTER
= 0x7fffffff
652 // Flags found in the DT_FLAGS dynamic element.
663 // Version numbers which appear in the vd_version field of a Verdef
666 const int VER_DEF_NONE
= 0;
667 const int VER_DEF_CURRENT
= 1;
669 // Version numbers which appear in the vn_version field of a Verneed
672 const int VER_NEED_NONE
= 0;
673 const int VER_NEED_CURRENT
= 1;
675 // Bit flags which appear in vd_flags of Verdef and vna_flags of
678 const int VER_FLG_BASE
= 0x1;
679 const int VER_FLG_WEAK
= 0x2;
681 // Special constants found in the SHT_GNU_versym entries.
683 const int VER_NDX_LOCAL
= 0;
684 const int VER_NDX_GLOBAL
= 1;
686 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
687 // the symbol is hidden and can only be seen when referenced using an
688 // explicit version number. This is a GNU extension.
690 const int VERSYM_HIDDEN
= 0x8000;
692 // This is the mask for the rest of the data in a word read from a
693 // SHT_GNU_versym section.
695 const int VERSYM_VERSION
= 0x7fff;
697 } // End namespace elfcpp.
699 // Include internal details after defining the types.
700 #include "elfcpp_internal.h"
705 // The offset of the ELF file header in the ELF file.
707 const int file_header_offset
= 0;
709 // ELF structure sizes.
714 // Size of ELF file header.
715 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
716 // Size of ELF segment header.
717 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
718 // Size of ELF section header.
719 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
720 // Size of ELF symbol table entry.
721 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
722 // Sizes of ELF reloc entries.
723 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
724 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
725 // Size of ELF dynamic entry.
726 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
727 // Size of ELF version structures.
728 static const int verdef_size
= sizeof(internal::Verdef_data
);
729 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
730 static const int verneed_size
= sizeof(internal::Verneed_data
);
731 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
734 // Accessor class for the ELF file header.
736 template<int size
, bool big_endian
>
740 Ehdr(const unsigned char* p
)
741 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
744 template<typename File
>
745 Ehdr(File
* file
, typename
File::Location loc
)
746 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
747 file
->view(loc
.file_offset
, loc
.data_size
).data()))
752 { return this->p_
->e_ident
; }
756 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
759 get_e_machine() const
760 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
763 get_e_version() const
764 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
766 typename Elf_types
<size
>::Elf_Addr
768 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
770 typename Elf_types
<size
>::Elf_Off
772 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
774 typename Elf_types
<size
>::Elf_Off
776 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
780 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
784 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
787 get_e_phentsize() const
788 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
792 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
795 get_e_shentsize() const
796 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
800 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
803 get_e_shstrndx() const
804 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
807 const internal::Ehdr_data
<size
>* p_
;
810 // Write class for the ELF file header.
812 template<int size
, bool big_endian
>
816 Ehdr_write(unsigned char* p
)
817 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
821 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
822 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
825 put_e_type(Elf_Half v
)
826 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
829 put_e_machine(Elf_Half v
)
830 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
833 put_e_version(Elf_Word v
)
834 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
837 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
838 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
841 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
842 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
845 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
846 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
849 put_e_flags(Elf_Word v
)
850 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
853 put_e_ehsize(Elf_Half v
)
854 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
857 put_e_phentsize(Elf_Half v
)
858 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
861 put_e_phnum(Elf_Half v
)
862 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
865 put_e_shentsize(Elf_Half v
)
866 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
869 put_e_shnum(Elf_Half v
)
870 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
873 put_e_shstrndx(Elf_Half v
)
874 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
877 internal::Ehdr_data
<size
>* p_
;
880 // Accessor class for an ELF section header.
882 template<int size
, bool big_endian
>
886 Shdr(const unsigned char* p
)
887 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
890 template<typename File
>
891 Shdr(File
* file
, typename
File::Location loc
)
892 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
893 file
->view(loc
.file_offset
, loc
.data_size
).data()))
898 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
902 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
904 typename Elf_types
<size
>::Elf_WXword
906 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
908 typename Elf_types
<size
>::Elf_Addr
910 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
912 typename Elf_types
<size
>::Elf_Off
913 get_sh_offset() const
914 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
916 typename Elf_types
<size
>::Elf_WXword
918 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
922 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
926 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
928 typename Elf_types
<size
>::Elf_WXword
929 get_sh_addralign() const
931 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
933 typename Elf_types
<size
>::Elf_WXword
934 get_sh_entsize() const
935 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
938 const internal::Shdr_data
<size
>* p_
;
941 // Write class for an ELF section header.
943 template<int size
, bool big_endian
>
947 Shdr_write(unsigned char* p
)
948 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
952 put_sh_name(Elf_Word v
)
953 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
956 put_sh_type(Elf_Word v
)
957 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
960 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
961 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
964 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
965 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
968 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
969 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
972 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
973 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
976 put_sh_link(Elf_Word v
)
977 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
980 put_sh_info(Elf_Word v
)
981 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
984 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
985 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
988 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
989 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
992 internal::Shdr_data
<size
>* p_
;
995 // Accessor class for an ELF segment header.
997 template<int size
, bool big_endian
>
1001 Phdr(const unsigned char* p
)
1002 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1005 template<typename File
>
1006 Phdr(File
* file
, typename
File::Location loc
)
1007 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1008 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1013 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1015 typename Elf_types
<size
>::Elf_Off
1016 get_p_offset() const
1017 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1019 typename Elf_types
<size
>::Elf_Addr
1021 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1023 typename Elf_types
<size
>::Elf_Addr
1025 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1027 typename Elf_types
<size
>::Elf_WXword
1028 get_p_filesz() const
1029 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1031 typename Elf_types
<size
>::Elf_WXword
1033 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1037 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1039 typename Elf_types
<size
>::Elf_WXword
1041 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1044 const internal::Phdr_data
<size
>* p_
;
1047 // Write class for an ELF segment header.
1049 template<int size
, bool big_endian
>
1053 Phdr_write(unsigned char* p
)
1054 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1058 put_p_type(Elf_Word v
)
1059 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1062 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1063 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1066 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1067 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1070 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1071 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1074 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1075 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1078 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1079 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1082 put_p_flags(Elf_Word v
)
1083 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1086 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1087 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1090 internal::Phdr_data
<size
>* p_
;
1093 // Accessor class for an ELF symbol table entry.
1095 template<int size
, bool big_endian
>
1099 Sym(const unsigned char* p
)
1100 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1103 template<typename File
>
1104 Sym(File
* file
, typename
File::Location loc
)
1105 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1106 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1111 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1113 typename Elf_types
<size
>::Elf_Addr
1114 get_st_value() const
1115 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1117 typename Elf_types
<size
>::Elf_WXword
1119 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1123 { return this->p_
->st_info
; }
1127 { return elf_st_bind(this->get_st_info()); }
1131 { return elf_st_type(this->get_st_info()); }
1134 get_st_other() const
1135 { return this->p_
->st_other
; }
1138 get_st_visibility() const
1139 { return elf_st_visibility(this->get_st_other()); }
1142 get_st_nonvis() const
1143 { return elf_st_nonvis(this->get_st_other()); }
1146 get_st_shndx() const
1147 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1150 const internal::Sym_data
<size
>* p_
;
1153 // Writer class for an ELF symbol table entry.
1155 template<int size
, bool big_endian
>
1159 Sym_write(unsigned char* p
)
1160 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1164 put_st_name(Elf_Word v
)
1165 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1168 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1169 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1172 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1173 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1176 put_st_info(unsigned char v
)
1177 { this->p_
->st_info
= v
; }
1180 put_st_info(STB bind
, STT type
)
1181 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1184 put_st_other(unsigned char v
)
1185 { this->p_
->st_other
= v
; }
1188 put_st_other(STV vis
, unsigned char nonvis
)
1189 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1192 put_st_shndx(Elf_Half v
)
1193 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1195 Sym
<size
, big_endian
>
1197 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1200 internal::Sym_data
<size
>* p_
;
1203 // Accessor classes for an ELF REL relocation entry.
1205 template<int size
, bool big_endian
>
1209 Rel(const unsigned char* p
)
1210 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1213 template<typename File
>
1214 Rel(File
* file
, typename
File::Location loc
)
1215 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1216 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1219 typename Elf_types
<size
>::Elf_Addr
1220 get_r_offset() const
1221 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1223 typename Elf_types
<size
>::Elf_WXword
1225 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1228 const internal::Rel_data
<size
>* p_
;
1231 // Writer class for an ELF Rel relocation.
1233 template<int size
, bool big_endian
>
1237 Rel_write(unsigned char* p
)
1238 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1242 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1243 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1246 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1247 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1250 internal::Rel_data
<size
>* p_
;
1253 // Accessor class for an ELF Rela relocation.
1255 template<int size
, bool big_endian
>
1259 Rela(const unsigned char* p
)
1260 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1263 template<typename File
>
1264 Rela(File
* file
, typename
File::Location loc
)
1265 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1266 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1269 typename Elf_types
<size
>::Elf_Addr
1270 get_r_offset() const
1271 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1273 typename Elf_types
<size
>::Elf_WXword
1275 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1277 typename Elf_types
<size
>::Elf_Swxword
1278 get_r_addend() const
1279 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1282 const internal::Rela_data
<size
>* p_
;
1285 // Writer class for an ELF Rela relocation.
1287 template<int size
, bool big_endian
>
1291 Rela_write(unsigned char* p
)
1292 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1296 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1297 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1300 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1301 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1304 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1305 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1308 internal::Rela_data
<size
>* p_
;
1311 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1312 // PT_DYNAMIC segment.
1314 template<int size
, bool big_endian
>
1318 Dyn(const unsigned char* p
)
1319 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1322 template<typename File
>
1323 Dyn(File
* file
, typename
File::Location loc
)
1324 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1325 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1328 typename Elf_types
<size
>::Elf_Swxword
1330 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1332 typename Elf_types
<size
>::Elf_WXword
1334 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1336 typename Elf_types
<size
>::Elf_Addr
1338 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1341 const internal::Dyn_data
<size
>* p_
;
1344 // Write class for an entry in the SHT_DYNAMIC section.
1346 template<int size
, bool big_endian
>
1350 Dyn_write(unsigned char* p
)
1351 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1355 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1356 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1359 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1360 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1363 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1364 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1367 internal::Dyn_data
<size
>* p_
;
1370 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1372 template<int size
, bool big_endian
>
1376 Verdef(const unsigned char* p
)
1377 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1380 template<typename File
>
1381 Verdef(File
* file
, typename
File::Location loc
)
1382 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1383 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1387 get_vd_version() const
1388 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1391 get_vd_flags() const
1392 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1396 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1400 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1404 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1408 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1412 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1415 const internal::Verdef_data
* p_
;
1418 template<int size
, bool big_endian
>
1422 Verdef_write(unsigned char* p
)
1423 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
1427 set_vd_version(Elf_Half v
)
1428 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
1431 set_vd_flags(Elf_Half v
)
1432 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1435 set_vd_ndx(Elf_Half v
)
1436 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
1439 set_vd_cnt(Elf_Half v
)
1440 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1443 set_vd_hash(Elf_Word v
)
1444 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1447 set_vd_aux(Elf_Word v
)
1448 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1451 set_vd_next(Elf_Word v
)
1452 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
1455 internal::Verdef_data
* p_
;
1458 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1461 template<int size
, bool big_endian
>
1465 Verdaux(const unsigned char* p
)
1466 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1469 template<typename File
>
1470 Verdaux(File
* file
, typename
File::Location loc
)
1471 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1472 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1476 get_vda_name() const
1477 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1480 get_vda_next() const
1481 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1484 const internal::Verdaux_data
* p_
;
1487 template<int size
, bool big_endian
>
1491 Verdaux_write(unsigned char* p
)
1492 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
1496 set_vda_name(Elf_Word v
)
1497 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
1500 set_vda_next(Elf_Word v
)
1501 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
1504 internal::Verdaux_data
* p_
;
1507 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1509 template<int size
, bool big_endian
>
1513 Verneed(const unsigned char* p
)
1514 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1517 template<typename File
>
1518 Verneed(File
* file
, typename
File::Location loc
)
1519 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1520 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1524 get_vn_version() const
1525 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1529 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1533 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1537 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1541 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1544 const internal::Verneed_data
* p_
;
1547 template<int size
, bool big_endian
>
1551 Verneed_write(unsigned char* p
)
1552 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
1556 set_vn_version(Elf_Half v
)
1557 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
1560 set_vn_cnt(Elf_Half v
)
1561 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1564 set_vn_file(Elf_Word v
)
1565 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
1568 set_vn_aux(Elf_Word v
)
1569 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1572 set_vn_next(Elf_Word v
)
1573 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
1576 internal::Verneed_data
* p_
;
1579 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1582 template<int size
, bool big_endian
>
1586 Vernaux(const unsigned char* p
)
1587 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1590 template<typename File
>
1591 Vernaux(File
* file
, typename
File::Location loc
)
1592 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1593 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1597 get_vna_hash() const
1598 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1601 get_vna_flags() const
1602 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1605 get_vna_other() const
1606 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1609 get_vna_name() const
1610 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1613 get_vna_next() const
1614 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1617 const internal::Vernaux_data
* p_
;
1620 template<int size
, bool big_endian
>
1624 Vernaux_write(unsigned char* p
)
1625 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
1629 set_vna_hash(Elf_Word v
)
1630 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1633 set_vna_flags(Elf_Half v
)
1634 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1637 set_vna_other(Elf_Half v
)
1638 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
1641 set_vna_name(Elf_Word v
)
1642 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
1645 set_vna_next(Elf_Word v
)
1646 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
1649 internal::Vernaux_data
* p_
;
1652 } // End namespace elfcpp.
1654 #endif // !defined(ELFPCP_H)
This page took 0.08017 seconds and 4 git commands to generate.