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 // List of prelink dependencies.
350 SHT_GNU_LIBLIST
= 0x6ffffff7,
351 // Versions defined by file.
352 SHT_SUNW_verdef
= 0x6ffffffd,
353 SHT_GNU_verdef
= 0x6ffffffd,
354 // Versions needed by file.
355 SHT_SUNW_verneed
= 0x6ffffffe,
356 SHT_GNU_verneed
= 0x6ffffffe,
358 SHT_SUNW_versym
= 0x6fffffff,
359 SHT_GNU_versym
= 0x6fffffff,
362 // The valid bit flags found in the Shdr sh_flags field.
371 SHF_INFO_LINK
= 0x40,
372 SHF_LINK_ORDER
= 0x80,
373 SHF_OS_NONCONFORMING
= 0x100,
376 SHF_MASKOS
= 0x0ff00000,
377 SHF_MASKPROC
= 0xf0000000
380 // Bit flags which appear in the first 32-bit word of the section data
381 // of a SHT_GROUP section.
386 GRP_MASKOS
= 0x0ff00000,
387 GRP_MASKPROC
= 0xf0000000
390 // The valid values found in the Phdr p_type field.
402 PT_LOOS
= 0x60000000,
403 PT_HIOS
= 0x6fffffff,
404 PT_LOPROC
= 0x70000000,
405 PT_HIPROC
= 0x7fffffff,
406 // The remaining values are not in the standard.
407 // Frame unwind information.
408 PT_GNU_EH_FRAME
= 0x6474e550,
409 PT_SUNW_EH_FRAME
= 0x6474e550,
411 PT_GNU_STACK
= 0x6474e551,
412 // Read only after relocation.
413 PT_GNU_RELRO
= 0x6474e552
416 // The valid bit flags found in the Phdr p_flags field.
423 PF_MASKOS
= 0x0ff00000,
424 PF_MASKPROC
= 0xf0000000
427 // Symbol binding from Sym st_info field.
440 // Symbol types from Sym st_info field.
458 elf_st_bind(unsigned char info
)
460 return static_cast<STB
>(info
>> 4);
464 elf_st_type(unsigned char info
)
466 return static_cast<STT
>(info
& 0xf);
470 elf_st_info(STB bind
, STT type
)
472 return ((static_cast<unsigned char>(bind
) << 4)
473 + (static_cast<unsigned char>(type
) & 0xf));
476 // Symbol visibility from Sym st_other field.
487 elf_st_visibility(unsigned char other
)
489 return static_cast<STV
>(other
& 0x3);
493 elf_st_nonvis(unsigned char other
)
495 return static_cast<STV
>(other
>> 2);
499 elf_st_other(STV vis
, unsigned char nonvis
)
501 return ((nonvis
<< 2)
502 + (static_cast<unsigned char>(vis
) & 3));
505 // Reloc information from Rel/Rela r_info field.
509 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
513 elf_r_sym
<32>(Elf_Word v
)
520 elf_r_sym
<64>(Elf_Xword v
)
527 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
531 elf_r_type
<32>(Elf_Word v
)
538 elf_r_type
<64>(Elf_Xword v
)
540 return v
& 0xffffffff;
544 typename Elf_types
<size
>::Elf_WXword
545 elf_r_info(unsigned int s
, unsigned int t
);
549 elf_r_info
<32>(unsigned int s
, unsigned int t
)
551 return (s
<< 8) + (t
& 0xff);
556 elf_r_info
<64>(unsigned int s
, unsigned int t
)
558 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
561 // Dynamic tags found in the PT_DYNAMIC segment.
592 DT_INIT_ARRAYSZ
= 27,
593 DT_FINI_ARRAYSZ
= 28,
597 DT_PREINIT_ARRAY
= 33,
598 DT_PREINIT_ARRAYSZ
= 33,
599 DT_LOOS
= 0x6000000d,
600 DT_HIOS
= 0x6ffff000,
601 DT_LOPROC
= 0x70000000,
602 DT_HIPROC
= 0x7fffffff,
604 // The remaining values are extensions used by GNU or Solaris.
605 DT_VALRNGLO
= 0x6ffffd00,
606 DT_GNU_PRELINKED
= 0x6ffffdf5,
607 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
608 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
609 DT_CHECKSUM
= 0x6ffffdf8,
610 DT_PLTPADSZ
= 0x6ffffdf9,
611 DT_MOVEENT
= 0x6ffffdfa,
612 DT_MOVESZ
= 0x6ffffdfb,
613 DT_FEATURE
= 0x6ffffdfc,
614 DT_POSFLAG_1
= 0x6ffffdfd,
615 DT_SYMINSZ
= 0x6ffffdfe,
616 DT_SYMINENT
= 0x6ffffdff,
617 DT_VALRNGHI
= 0x6ffffdff,
619 DT_ADDRRNGLO
= 0x6ffffe00,
620 DT_GNU_HASH
= 0x6ffffef5,
621 DT_TLSDESC_PLT
= 0x6ffffef6,
622 DT_TLSDESC_GOT
= 0x6ffffef7,
623 DT_GNU_CONFLICT
= 0x6ffffef8,
624 DT_GNU_LIBLIST
= 0x6ffffef9,
625 DT_CONFIG
= 0x6ffffefa,
626 DT_DEPAUDIT
= 0x6ffffefb,
627 DT_AUDIT
= 0x6ffffefc,
628 DT_PLTPAD
= 0x6ffffefd,
629 DT_MOVETAB
= 0x6ffffefe,
630 DT_SYMINFO
= 0x6ffffeff,
631 DT_ADDRRNGHI
= 0x6ffffeff,
633 DT_RELACOUNT
= 0x6ffffff9,
634 DT_RELCOUNT
= 0x6ffffffa,
635 DT_FLAGS_1
= 0x6ffffffb,
636 DT_VERDEF
= 0x6ffffffc,
637 DT_VERDEFNUM
= 0x6ffffffd,
638 DT_VERNEED
= 0x6ffffffe,
639 DT_VERNEEDNUM
= 0x6fffffff,
641 DT_VERSYM
= 0x6ffffff0,
643 DT_AUXILIARY
= 0x7ffffffd,
644 DT_USED
= 0x7ffffffe,
645 DT_FILTER
= 0x7fffffff
648 // Flags found in the DT_FLAGS dynamic element.
659 // Version numbers which appear in the vd_version field of a Verdef
662 const int VER_DEF_NONE
= 0;
663 const int VER_DEF_CURRENT
= 1;
665 // Version numbers which appear in the vn_version field of a Verneed
668 const int VER_NEED_NONE
= 0;
669 const int VER_NEED_CURRENT
= 1;
671 // Bit flags which appear in vd_flags of Verdef and vna_flags of
674 const int VER_FLG_BASE
= 0x1;
675 const int VER_FLG_WEAK
= 0x2;
677 // Special constants found in the SHT_GNU_versym entries.
679 const int VER_NDX_LOCAL
= 0;
680 const int VER_NDX_GLOBAL
= 1;
682 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
683 // the symbol is hidden and can only be seen when referenced using an
684 // explicit version number. This is a GNU extension.
686 const int VERSYM_HIDDEN
= 0x8000;
688 // This is the mask for the rest of the data in a word read from a
689 // SHT_GNU_versym section.
691 const int VERSYM_VERSION
= 0x7fff;
693 } // End namespace elfcpp.
695 // Include internal details after defining the types.
696 #include "elfcpp_internal.h"
701 // The offset of the ELF file header in the ELF file.
703 const int file_header_offset
= 0;
705 // ELF structure sizes.
710 // Size of ELF file header.
711 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
712 // Size of ELF segment header.
713 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
714 // Size of ELF section header.
715 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
716 // Size of ELF symbol table entry.
717 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
718 // Sizes of ELF reloc entries.
719 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
720 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
721 // Size of ELF dynamic entry.
722 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
723 // Size of ELF version structures.
724 static const int verdef_size
= sizeof(internal::Verdef_data
);
725 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
726 static const int verneed_size
= sizeof(internal::Verneed_data
);
727 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
730 // Accessor class for the ELF file header.
732 template<int size
, bool big_endian
>
736 Ehdr(const unsigned char* p
)
737 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
740 template<typename File
>
741 Ehdr(File
* file
, typename
File::Location loc
)
742 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
743 file
->view(loc
.file_offset
, loc
.data_size
).data()))
748 { return this->p_
->e_ident
; }
752 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
755 get_e_machine() const
756 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
759 get_e_version() const
760 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
762 typename Elf_types
<size
>::Elf_Addr
764 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
766 typename Elf_types
<size
>::Elf_Off
768 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
770 typename Elf_types
<size
>::Elf_Off
772 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
776 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
780 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
783 get_e_phentsize() const
784 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
788 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
791 get_e_shentsize() const
792 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
796 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
799 get_e_shstrndx() const
800 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
803 const internal::Ehdr_data
<size
>* p_
;
806 // Write class for the ELF file header.
808 template<int size
, bool big_endian
>
812 Ehdr_write(unsigned char* p
)
813 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
817 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
818 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
821 put_e_type(Elf_Half v
)
822 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
825 put_e_machine(Elf_Half v
)
826 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
829 put_e_version(Elf_Word v
)
830 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
833 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
834 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
837 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
838 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
841 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
842 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
845 put_e_flags(Elf_Word v
)
846 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
849 put_e_ehsize(Elf_Half v
)
850 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
853 put_e_phentsize(Elf_Half v
)
854 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
857 put_e_phnum(Elf_Half v
)
858 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
861 put_e_shentsize(Elf_Half v
)
862 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
865 put_e_shnum(Elf_Half v
)
866 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
869 put_e_shstrndx(Elf_Half v
)
870 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
873 internal::Ehdr_data
<size
>* p_
;
876 // Accessor class for an ELF section header.
878 template<int size
, bool big_endian
>
882 Shdr(const unsigned char* p
)
883 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
886 template<typename File
>
887 Shdr(File
* file
, typename
File::Location loc
)
888 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
889 file
->view(loc
.file_offset
, loc
.data_size
).data()))
894 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
898 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
900 typename Elf_types
<size
>::Elf_WXword
902 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
904 typename Elf_types
<size
>::Elf_Addr
906 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
908 typename Elf_types
<size
>::Elf_Off
909 get_sh_offset() const
910 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
912 typename Elf_types
<size
>::Elf_WXword
914 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
918 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
922 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
924 typename Elf_types
<size
>::Elf_WXword
925 get_sh_addralign() const
927 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
929 typename Elf_types
<size
>::Elf_WXword
930 get_sh_entsize() const
931 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
934 const internal::Shdr_data
<size
>* p_
;
937 // Write class for an ELF section header.
939 template<int size
, bool big_endian
>
943 Shdr_write(unsigned char* p
)
944 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
948 put_sh_name(Elf_Word v
)
949 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
952 put_sh_type(Elf_Word v
)
953 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
956 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
957 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
960 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
961 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
964 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
965 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
968 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
969 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
972 put_sh_link(Elf_Word v
)
973 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
976 put_sh_info(Elf_Word v
)
977 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
980 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
981 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
984 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
985 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
988 internal::Shdr_data
<size
>* p_
;
991 // Accessor class for an ELF segment header.
993 template<int size
, bool big_endian
>
997 Phdr(const unsigned char* p
)
998 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1001 template<typename File
>
1002 Phdr(File
* file
, typename
File::Location loc
)
1003 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1004 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1009 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1011 typename Elf_types
<size
>::Elf_Off
1012 get_p_offset() const
1013 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1015 typename Elf_types
<size
>::Elf_Addr
1017 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1019 typename Elf_types
<size
>::Elf_Addr
1021 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1023 typename Elf_types
<size
>::Elf_WXword
1024 get_p_filesz() const
1025 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1027 typename Elf_types
<size
>::Elf_WXword
1029 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1033 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1035 typename Elf_types
<size
>::Elf_WXword
1037 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1040 const internal::Phdr_data
<size
>* p_
;
1043 // Write class for an ELF segment header.
1045 template<int size
, bool big_endian
>
1049 Phdr_write(unsigned char* p
)
1050 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1054 put_p_type(Elf_Word v
)
1055 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1058 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1059 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1062 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1063 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1066 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1067 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1070 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1071 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1074 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1075 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1078 put_p_flags(Elf_Word v
)
1079 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1082 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1083 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1086 internal::Phdr_data
<size
>* p_
;
1089 // Accessor class for an ELF symbol table entry.
1091 template<int size
, bool big_endian
>
1095 Sym(const unsigned char* p
)
1096 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1099 template<typename File
>
1100 Sym(File
* file
, typename
File::Location loc
)
1101 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1102 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1107 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1109 typename Elf_types
<size
>::Elf_Addr
1110 get_st_value() const
1111 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1113 typename Elf_types
<size
>::Elf_WXword
1115 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1119 { return this->p_
->st_info
; }
1123 { return elf_st_bind(this->get_st_info()); }
1127 { return elf_st_type(this->get_st_info()); }
1130 get_st_other() const
1131 { return this->p_
->st_other
; }
1134 get_st_visibility() const
1135 { return elf_st_visibility(this->get_st_other()); }
1138 get_st_nonvis() const
1139 { return elf_st_nonvis(this->get_st_other()); }
1142 get_st_shndx() const
1143 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1146 const internal::Sym_data
<size
>* p_
;
1149 // Writer class for an ELF symbol table entry.
1151 template<int size
, bool big_endian
>
1155 Sym_write(unsigned char* p
)
1156 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1160 put_st_name(Elf_Word v
)
1161 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1164 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1165 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1168 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1169 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1172 put_st_info(unsigned char v
)
1173 { this->p_
->st_info
= v
; }
1176 put_st_info(STB bind
, STT type
)
1177 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1180 put_st_other(unsigned char v
)
1181 { this->p_
->st_other
= v
; }
1184 put_st_other(STV vis
, unsigned char nonvis
)
1185 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1188 put_st_shndx(Elf_Half v
)
1189 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1191 Sym
<size
, big_endian
>
1193 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1196 internal::Sym_data
<size
>* p_
;
1199 // Accessor classes for an ELF REL relocation entry.
1201 template<int size
, bool big_endian
>
1205 Rel(const unsigned char* p
)
1206 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1209 template<typename File
>
1210 Rel(File
* file
, typename
File::Location loc
)
1211 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1212 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1215 typename Elf_types
<size
>::Elf_Addr
1216 get_r_offset() const
1217 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1219 typename Elf_types
<size
>::Elf_WXword
1221 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1224 const internal::Rel_data
<size
>* p_
;
1227 // Writer class for an ELF Rel relocation.
1229 template<int size
, bool big_endian
>
1233 Rel_write(unsigned char* p
)
1234 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1238 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1239 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1242 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1243 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1246 internal::Rel_data
<size
>* p_
;
1249 // Accessor class for an ELF Rela relocation.
1251 template<int size
, bool big_endian
>
1255 Rela(const unsigned char* p
)
1256 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1259 template<typename File
>
1260 Rela(File
* file
, typename
File::Location loc
)
1261 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1262 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1265 typename Elf_types
<size
>::Elf_Addr
1266 get_r_offset() const
1267 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1269 typename Elf_types
<size
>::Elf_WXword
1271 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1273 typename Elf_types
<size
>::Elf_Swxword
1274 get_r_addend() const
1275 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1278 const internal::Rela_data
<size
>* p_
;
1281 // Writer class for an ELF Rela relocation.
1283 template<int size
, bool big_endian
>
1287 Rela_write(unsigned char* p
)
1288 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1292 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1293 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1296 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1297 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1300 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1301 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1304 internal::Rela_data
<size
>* p_
;
1307 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1308 // PT_DYNAMIC segment.
1310 template<int size
, bool big_endian
>
1314 Dyn(const unsigned char* p
)
1315 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1318 template<typename File
>
1319 Dyn(File
* file
, typename
File::Location loc
)
1320 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1321 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1324 typename Elf_types
<size
>::Elf_Swxword
1326 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1328 typename Elf_types
<size
>::Elf_WXword
1330 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1332 typename Elf_types
<size
>::Elf_Addr
1334 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1337 const internal::Dyn_data
<size
>* p_
;
1340 // Write class for an entry in the SHT_DYNAMIC section.
1342 template<int size
, bool big_endian
>
1346 Dyn_write(unsigned char* p
)
1347 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1351 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1352 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1355 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1356 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1359 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1360 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1363 internal::Dyn_data
<size
>* p_
;
1366 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1368 template<int size
, bool big_endian
>
1372 Verdef(const unsigned char* p
)
1373 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1376 template<typename File
>
1377 Verdef(File
* file
, typename
File::Location loc
)
1378 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1379 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1383 get_vd_version() const
1384 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1387 get_vd_flags() const
1388 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1392 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1396 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1400 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1404 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1408 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1411 const internal::Verdef_data
* p_
;
1414 template<int size
, bool big_endian
>
1418 Verdef_write(unsigned char* p
)
1419 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
1423 set_vd_version(Elf_Half v
)
1424 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
1427 set_vd_flags(Elf_Half v
)
1428 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1431 set_vd_ndx(Elf_Half v
)
1432 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
1435 set_vd_cnt(Elf_Half v
)
1436 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1439 set_vd_hash(Elf_Word v
)
1440 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1443 set_vd_aux(Elf_Word v
)
1444 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1447 set_vd_next(Elf_Word v
)
1448 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
1451 internal::Verdef_data
* p_
;
1454 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1457 template<int size
, bool big_endian
>
1461 Verdaux(const unsigned char* p
)
1462 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1465 template<typename File
>
1466 Verdaux(File
* file
, typename
File::Location loc
)
1467 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1468 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1472 get_vda_name() const
1473 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1476 get_vda_next() const
1477 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1480 const internal::Verdaux_data
* p_
;
1483 template<int size
, bool big_endian
>
1487 Verdaux_write(unsigned char* p
)
1488 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
1492 set_vda_name(Elf_Word v
)
1493 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
1496 set_vda_next(Elf_Word v
)
1497 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
1500 internal::Verdaux_data
* p_
;
1503 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1505 template<int size
, bool big_endian
>
1509 Verneed(const unsigned char* p
)
1510 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1513 template<typename File
>
1514 Verneed(File
* file
, typename
File::Location loc
)
1515 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1516 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1520 get_vn_version() const
1521 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1525 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1529 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1533 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1537 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1540 const internal::Verneed_data
* p_
;
1543 template<int size
, bool big_endian
>
1547 Verneed_write(unsigned char* p
)
1548 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
1552 set_vn_version(Elf_Half v
)
1553 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
1556 set_vn_cnt(Elf_Half v
)
1557 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1560 set_vn_file(Elf_Word v
)
1561 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
1564 set_vn_aux(Elf_Word v
)
1565 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1568 set_vn_next(Elf_Word v
)
1569 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
1572 internal::Verneed_data
* p_
;
1575 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1578 template<int size
, bool big_endian
>
1582 Vernaux(const unsigned char* p
)
1583 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1586 template<typename File
>
1587 Vernaux(File
* file
, typename
File::Location loc
)
1588 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1589 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1593 get_vna_hash() const
1594 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1597 get_vna_flags() const
1598 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1601 get_vna_other() const
1602 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1605 get_vna_name() const
1606 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1609 get_vna_next() const
1610 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1613 const internal::Vernaux_data
* p_
;
1616 template<int size
, bool big_endian
>
1620 Vernaux_write(unsigned char* p
)
1621 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
1625 set_vna_hash(Elf_Word v
)
1626 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1629 set_vna_flags(Elf_Half v
)
1630 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1633 set_vna_other(Elf_Half v
)
1634 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
1637 set_vna_name(Elf_Word v
)
1638 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
1641 set_vna_next(Elf_Word v
)
1642 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
1645 internal::Vernaux_data
* p_
;
1648 } // End namespace elfcpp.
1650 #endif // !defined(ELFPCP_H)