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 // Note descriptor type codes for notes in a non-core file with an
704 // An architecture string.
708 // Note descriptor type codes for notes in a non-core file with the
713 // The minimum ABI level. This is used by the dynamic linker to
714 // describe the minimal kernel version on which a shared library may
715 // be used. Th value should be four words. Word 0 is an OS
716 // descriptor (see below). Word 1 is the major version of the ABI.
717 // Word 2 is the minor version. Word 3 is the subminor version.
719 // Hardware capabilities information. Word 0 is the number of
720 // entries. Word 1 is a bitmask of enabled entries. The rest of
721 // the descriptor is a series of entries, where each entry is a
722 // single byte followed by a nul terminated string. The byte gives
723 // the bit number to test if enabled in the bitmask.
725 // The build ID as set by the linker's --build-id option. The
726 // format of the descriptor depends on the build ID style.
728 // The version of gold used to link. Th descriptor is just a
730 NT_GNU_GOLD_VERSION
= 4
733 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
737 ELF_NOTE_OS_LINUX
= 0,
739 ELF_NOTE_OS_SOLARIS2
= 2,
740 ELF_NOTE_OS_FREEBSD
= 3,
741 ELF_NOTE_OS_NETBSD
= 4,
742 ELF_NOTE_OS_SYLLABLE
= 5
745 } // End namespace elfcpp.
747 // Include internal details after defining the types.
748 #include "elfcpp_internal.h"
753 // The offset of the ELF file header in the ELF file.
755 const int file_header_offset
= 0;
757 // ELF structure sizes.
762 // Size of ELF file header.
763 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
764 // Size of ELF segment header.
765 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
766 // Size of ELF section header.
767 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
768 // Size of ELF symbol table entry.
769 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
770 // Sizes of ELF reloc entries.
771 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
772 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
773 // Size of ELF dynamic entry.
774 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
775 // Size of ELF version structures.
776 static const int verdef_size
= sizeof(internal::Verdef_data
);
777 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
778 static const int verneed_size
= sizeof(internal::Verneed_data
);
779 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
782 // Accessor class for the ELF file header.
784 template<int size
, bool big_endian
>
788 Ehdr(const unsigned char* p
)
789 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
792 template<typename File
>
793 Ehdr(File
* file
, typename
File::Location loc
)
794 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
795 file
->view(loc
.file_offset
, loc
.data_size
).data()))
800 { return this->p_
->e_ident
; }
804 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
807 get_e_machine() const
808 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
811 get_e_version() const
812 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
814 typename Elf_types
<size
>::Elf_Addr
816 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
818 typename Elf_types
<size
>::Elf_Off
820 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
822 typename Elf_types
<size
>::Elf_Off
824 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
828 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
832 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
835 get_e_phentsize() const
836 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
840 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
843 get_e_shentsize() const
844 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
848 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
851 get_e_shstrndx() const
852 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
855 const internal::Ehdr_data
<size
>* p_
;
858 // Write class for the ELF file header.
860 template<int size
, bool big_endian
>
864 Ehdr_write(unsigned char* p
)
865 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
869 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
870 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
873 put_e_type(Elf_Half v
)
874 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
877 put_e_machine(Elf_Half v
)
878 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
881 put_e_version(Elf_Word v
)
882 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
885 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
886 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
889 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
890 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
893 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
894 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
897 put_e_flags(Elf_Word v
)
898 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
901 put_e_ehsize(Elf_Half v
)
902 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
905 put_e_phentsize(Elf_Half v
)
906 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
909 put_e_phnum(Elf_Half v
)
910 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
913 put_e_shentsize(Elf_Half v
)
914 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
917 put_e_shnum(Elf_Half v
)
918 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
921 put_e_shstrndx(Elf_Half v
)
922 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
925 internal::Ehdr_data
<size
>* p_
;
928 // Accessor class for an ELF section header.
930 template<int size
, bool big_endian
>
934 Shdr(const unsigned char* p
)
935 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
938 template<typename File
>
939 Shdr(File
* file
, typename
File::Location loc
)
940 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
941 file
->view(loc
.file_offset
, loc
.data_size
).data()))
946 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
950 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
952 typename Elf_types
<size
>::Elf_WXword
954 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
956 typename Elf_types
<size
>::Elf_Addr
958 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
960 typename Elf_types
<size
>::Elf_Off
961 get_sh_offset() const
962 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
964 typename Elf_types
<size
>::Elf_WXword
966 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
970 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
974 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
976 typename Elf_types
<size
>::Elf_WXword
977 get_sh_addralign() const
979 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
981 typename Elf_types
<size
>::Elf_WXword
982 get_sh_entsize() const
983 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
986 const internal::Shdr_data
<size
>* p_
;
989 // Write class for an ELF section header.
991 template<int size
, bool big_endian
>
995 Shdr_write(unsigned char* p
)
996 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
1000 put_sh_name(Elf_Word v
)
1001 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
1004 put_sh_type(Elf_Word v
)
1005 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
1008 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
1009 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
1012 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
1013 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
1016 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
1017 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1020 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
1021 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1024 put_sh_link(Elf_Word v
)
1025 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
1028 put_sh_info(Elf_Word v
)
1029 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
1032 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
1033 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
1036 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
1037 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
1040 internal::Shdr_data
<size
>* p_
;
1043 // Accessor class for an ELF segment header.
1045 template<int size
, bool big_endian
>
1049 Phdr(const unsigned char* p
)
1050 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1053 template<typename File
>
1054 Phdr(File
* file
, typename
File::Location loc
)
1055 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1056 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1061 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1063 typename Elf_types
<size
>::Elf_Off
1064 get_p_offset() const
1065 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1067 typename Elf_types
<size
>::Elf_Addr
1069 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1071 typename Elf_types
<size
>::Elf_Addr
1073 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1075 typename Elf_types
<size
>::Elf_WXword
1076 get_p_filesz() const
1077 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1079 typename Elf_types
<size
>::Elf_WXword
1081 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1085 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1087 typename Elf_types
<size
>::Elf_WXword
1089 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1092 const internal::Phdr_data
<size
>* p_
;
1095 // Write class for an ELF segment header.
1097 template<int size
, bool big_endian
>
1101 Phdr_write(unsigned char* p
)
1102 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1106 put_p_type(Elf_Word v
)
1107 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1110 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1111 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1114 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1115 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1118 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1119 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1122 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1123 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1126 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1127 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1130 put_p_flags(Elf_Word v
)
1131 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1134 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1135 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1138 internal::Phdr_data
<size
>* p_
;
1141 // Accessor class for an ELF symbol table entry.
1143 template<int size
, bool big_endian
>
1147 Sym(const unsigned char* p
)
1148 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1151 template<typename File
>
1152 Sym(File
* file
, typename
File::Location loc
)
1153 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1154 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1159 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1161 typename Elf_types
<size
>::Elf_Addr
1162 get_st_value() const
1163 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1165 typename Elf_types
<size
>::Elf_WXword
1167 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1171 { return this->p_
->st_info
; }
1175 { return elf_st_bind(this->get_st_info()); }
1179 { return elf_st_type(this->get_st_info()); }
1182 get_st_other() const
1183 { return this->p_
->st_other
; }
1186 get_st_visibility() const
1187 { return elf_st_visibility(this->get_st_other()); }
1190 get_st_nonvis() const
1191 { return elf_st_nonvis(this->get_st_other()); }
1194 get_st_shndx() const
1195 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1198 const internal::Sym_data
<size
>* p_
;
1201 // Writer class for an ELF symbol table entry.
1203 template<int size
, bool big_endian
>
1207 Sym_write(unsigned char* p
)
1208 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1212 put_st_name(Elf_Word v
)
1213 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1216 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1217 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1220 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1221 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1224 put_st_info(unsigned char v
)
1225 { this->p_
->st_info
= v
; }
1228 put_st_info(STB bind
, STT type
)
1229 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1232 put_st_other(unsigned char v
)
1233 { this->p_
->st_other
= v
; }
1236 put_st_other(STV vis
, unsigned char nonvis
)
1237 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1240 put_st_shndx(Elf_Half v
)
1241 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1243 Sym
<size
, big_endian
>
1245 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1248 internal::Sym_data
<size
>* p_
;
1251 // Accessor classes for an ELF REL relocation entry.
1253 template<int size
, bool big_endian
>
1257 Rel(const unsigned char* p
)
1258 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1261 template<typename File
>
1262 Rel(File
* file
, typename
File::Location loc
)
1263 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1264 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1267 typename Elf_types
<size
>::Elf_Addr
1268 get_r_offset() const
1269 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1271 typename Elf_types
<size
>::Elf_WXword
1273 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1276 const internal::Rel_data
<size
>* p_
;
1279 // Writer class for an ELF Rel relocation.
1281 template<int size
, bool big_endian
>
1285 Rel_write(unsigned char* p
)
1286 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1290 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1291 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1294 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1295 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1298 internal::Rel_data
<size
>* p_
;
1301 // Accessor class for an ELF Rela relocation.
1303 template<int size
, bool big_endian
>
1307 Rela(const unsigned char* p
)
1308 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1311 template<typename File
>
1312 Rela(File
* file
, typename
File::Location loc
)
1313 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1314 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1317 typename Elf_types
<size
>::Elf_Addr
1318 get_r_offset() const
1319 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1321 typename Elf_types
<size
>::Elf_WXword
1323 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1325 typename Elf_types
<size
>::Elf_Swxword
1326 get_r_addend() const
1327 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1330 const internal::Rela_data
<size
>* p_
;
1333 // Writer class for an ELF Rela relocation.
1335 template<int size
, bool big_endian
>
1339 Rela_write(unsigned char* p
)
1340 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1344 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1345 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1348 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1349 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1352 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1353 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1356 internal::Rela_data
<size
>* p_
;
1359 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1360 // PT_DYNAMIC segment.
1362 template<int size
, bool big_endian
>
1366 Dyn(const unsigned char* p
)
1367 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1370 template<typename File
>
1371 Dyn(File
* file
, typename
File::Location loc
)
1372 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1373 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1376 typename Elf_types
<size
>::Elf_Swxword
1378 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1380 typename Elf_types
<size
>::Elf_WXword
1382 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1384 typename Elf_types
<size
>::Elf_Addr
1386 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1389 const internal::Dyn_data
<size
>* p_
;
1392 // Write class for an entry in the SHT_DYNAMIC section.
1394 template<int size
, bool big_endian
>
1398 Dyn_write(unsigned char* p
)
1399 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1403 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1404 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1407 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1408 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1411 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1412 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1415 internal::Dyn_data
<size
>* p_
;
1418 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1420 template<int size
, bool big_endian
>
1424 Verdef(const unsigned char* p
)
1425 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1428 template<typename File
>
1429 Verdef(File
* file
, typename
File::Location loc
)
1430 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1431 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1435 get_vd_version() const
1436 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1439 get_vd_flags() const
1440 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1444 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1448 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1452 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1456 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1460 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1463 const internal::Verdef_data
* p_
;
1466 template<int size
, bool big_endian
>
1470 Verdef_write(unsigned char* p
)
1471 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
1475 set_vd_version(Elf_Half v
)
1476 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
1479 set_vd_flags(Elf_Half v
)
1480 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1483 set_vd_ndx(Elf_Half v
)
1484 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
1487 set_vd_cnt(Elf_Half v
)
1488 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1491 set_vd_hash(Elf_Word v
)
1492 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1495 set_vd_aux(Elf_Word v
)
1496 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1499 set_vd_next(Elf_Word v
)
1500 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
1503 internal::Verdef_data
* p_
;
1506 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1509 template<int size
, bool big_endian
>
1513 Verdaux(const unsigned char* p
)
1514 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1517 template<typename File
>
1518 Verdaux(File
* file
, typename
File::Location loc
)
1519 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1520 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1524 get_vda_name() const
1525 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1528 get_vda_next() const
1529 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1532 const internal::Verdaux_data
* p_
;
1535 template<int size
, bool big_endian
>
1539 Verdaux_write(unsigned char* p
)
1540 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
1544 set_vda_name(Elf_Word v
)
1545 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
1548 set_vda_next(Elf_Word v
)
1549 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
1552 internal::Verdaux_data
* p_
;
1555 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1557 template<int size
, bool big_endian
>
1561 Verneed(const unsigned char* p
)
1562 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1565 template<typename File
>
1566 Verneed(File
* file
, typename
File::Location loc
)
1567 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1568 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1572 get_vn_version() const
1573 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1577 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1581 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1585 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1589 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1592 const internal::Verneed_data
* p_
;
1595 template<int size
, bool big_endian
>
1599 Verneed_write(unsigned char* p
)
1600 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
1604 set_vn_version(Elf_Half v
)
1605 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
1608 set_vn_cnt(Elf_Half v
)
1609 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1612 set_vn_file(Elf_Word v
)
1613 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
1616 set_vn_aux(Elf_Word v
)
1617 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1620 set_vn_next(Elf_Word v
)
1621 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
1624 internal::Verneed_data
* p_
;
1627 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1630 template<int size
, bool big_endian
>
1634 Vernaux(const unsigned char* p
)
1635 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1638 template<typename File
>
1639 Vernaux(File
* file
, typename
File::Location loc
)
1640 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1641 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1645 get_vna_hash() const
1646 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1649 get_vna_flags() const
1650 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1653 get_vna_other() const
1654 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1657 get_vna_name() const
1658 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1661 get_vna_next() const
1662 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1665 const internal::Vernaux_data
* p_
;
1668 template<int size
, bool big_endian
>
1672 Vernaux_write(unsigned char* p
)
1673 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
1677 set_vna_hash(Elf_Word v
)
1678 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1681 set_vna_flags(Elf_Half v
)
1682 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1685 set_vna_other(Elf_Half v
)
1686 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
1689 set_vna_name(Elf_Word v
)
1690 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
1693 set_vna_next(Elf_Word v
)
1694 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
1697 internal::Vernaux_data
* p_
;
1700 } // End namespace elfcpp.
1702 #endif // !defined(ELFPCP_H)