1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 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,
320 // Provide for initial and final section ordering in conjunction
321 // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
326 // The valid values found in the Shdr sh_type field.
344 SHT_PREINIT_ARRAY
= 16,
346 SHT_SYMTAB_SHNDX
= 18,
347 SHT_LOOS
= 0x60000000,
348 SHT_HIOS
= 0x6fffffff,
349 SHT_LOPROC
= 0x70000000,
350 SHT_HIPROC
= 0x7fffffff,
351 SHT_LOUSER
= 0x80000000,
352 SHT_HIUSER
= 0xffffffff,
353 // The remaining values are not in the standard.
354 // Incremental build data.
355 SHT_GNU_INCREMENTAL_INPUTS
= 0x6fff4700,
356 // Object attributes.
357 SHT_GNU_ATTRIBUTES
= 0x6ffffff5,
358 // GNU style dynamic hash table.
359 SHT_GNU_HASH
= 0x6ffffff6,
360 // List of prelink dependencies.
361 SHT_GNU_LIBLIST
= 0x6ffffff7,
362 // Versions defined by file.
363 SHT_SUNW_verdef
= 0x6ffffffd,
364 SHT_GNU_verdef
= 0x6ffffffd,
365 // Versions needed by file.
366 SHT_SUNW_verneed
= 0x6ffffffe,
367 SHT_GNU_verneed
= 0x6ffffffe,
369 SHT_SUNW_versym
= 0x6fffffff,
370 SHT_GNU_versym
= 0x6fffffff,
372 SHT_SPARC_GOTDATA
= 0x70000000,
374 // ARM-specific section types.
375 // Exception Index table.
376 SHT_ARM_EXIDX
= 0x70000001,
377 // BPABI DLL dynamic linking pre-emption map.
378 SHT_ARM_PREEMPTMAP
= 0x70000002,
379 // Object file compatibility attributes.
380 SHT_ARM_ATTRIBUTES
= 0x70000003,
381 // Support for debugging overlaid programs.
382 SHT_ARM_DEBUGOVERLAY
= 0x70000004,
383 SHT_ARM_OVERLAYSECTION
= 0x70000005,
385 // Link editor is to sort the entries in this section based on the
386 // address specified in the associated symbol table entry.
387 SHT_ORDERED
= 0x7fffffff,
390 // The valid bit flags found in the Shdr sh_flags field.
399 SHF_INFO_LINK
= 0x40,
400 SHF_LINK_ORDER
= 0x80,
401 SHF_OS_NONCONFORMING
= 0x100,
404 SHF_MASKOS
= 0x0ff00000,
405 SHF_MASKPROC
= 0xf0000000,
407 // Indicates this section requires ordering in relation to
408 // other sections of the same type. Ordered sections are
409 // combined within the section pointed to by the sh_link entry.
410 // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
411 // sorted section is to precede or follow, respectively, all
412 // other sections in the set being ordered.
413 SHF_ORDERED
= 0x40000000,
414 // This section is excluded from input to the link-edit of an
415 // executable or shared object. This flag is ignored if SHF_ALLOC
416 // is also set, or if relocations exist against the section.
417 SHF_EXCLUDE
= 0x80000000,
420 // Bit flags which appear in the first 32-bit word of the section data
421 // of a SHT_GROUP section.
426 GRP_MASKOS
= 0x0ff00000,
427 GRP_MASKPROC
= 0xf0000000
430 // The valid values found in the Phdr p_type field.
442 PT_LOOS
= 0x60000000,
443 PT_HIOS
= 0x6fffffff,
444 PT_LOPROC
= 0x70000000,
445 PT_HIPROC
= 0x7fffffff,
446 // The remaining values are not in the standard.
447 // Frame unwind information.
448 PT_GNU_EH_FRAME
= 0x6474e550,
449 PT_SUNW_EH_FRAME
= 0x6474e550,
451 PT_GNU_STACK
= 0x6474e551,
452 // Read only after relocation.
453 PT_GNU_RELRO
= 0x6474e552,
454 // Platform architecture compatibility information
455 PT_ARM_ARCHEXT
= 0x70000000,
456 // Exception unwind tables
457 PT_ARM_EXIDX
= 0x70000001
460 // The valid bit flags found in the Phdr p_flags field.
467 PF_MASKOS
= 0x0ff00000,
468 PF_MASKPROC
= 0xf0000000
471 // Symbol binding from Sym st_info field.
484 // Symbol types from Sym st_info field.
501 // The section type that must be used for register symbols on
502 // Sparc. These symbols initialize a global register.
503 STT_SPARC_REGISTER
= 13,
505 // ARM: a THUMB function. This is not defined in ARM ELF Specification but
506 // used by the GNU tool-chain.
511 elf_st_bind(unsigned char info
)
513 return static_cast<STB
>(info
>> 4);
517 elf_st_type(unsigned char info
)
519 return static_cast<STT
>(info
& 0xf);
523 elf_st_info(STB bind
, STT type
)
525 return ((static_cast<unsigned char>(bind
) << 4)
526 + (static_cast<unsigned char>(type
) & 0xf));
529 // Symbol visibility from Sym st_other field.
540 elf_st_visibility(unsigned char other
)
542 return static_cast<STV
>(other
& 0x3);
546 elf_st_nonvis(unsigned char other
)
548 return static_cast<STV
>(other
>> 2);
552 elf_st_other(STV vis
, unsigned char nonvis
)
554 return ((nonvis
<< 2)
555 + (static_cast<unsigned char>(vis
) & 3));
558 // Reloc information from Rel/Rela r_info field.
562 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
566 elf_r_sym
<32>(Elf_Word v
)
573 elf_r_sym
<64>(Elf_Xword v
)
580 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
584 elf_r_type
<32>(Elf_Word v
)
591 elf_r_type
<64>(Elf_Xword v
)
593 return v
& 0xffffffff;
597 typename Elf_types
<size
>::Elf_WXword
598 elf_r_info(unsigned int s
, unsigned int t
);
602 elf_r_info
<32>(unsigned int s
, unsigned int t
)
604 return (s
<< 8) + (t
& 0xff);
609 elf_r_info
<64>(unsigned int s
, unsigned int t
)
611 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
614 // Dynamic tags found in the PT_DYNAMIC segment.
645 DT_INIT_ARRAYSZ
= 27,
646 DT_FINI_ARRAYSZ
= 28,
650 DT_PREINIT_ARRAY
= 33,
651 DT_PREINIT_ARRAYSZ
= 33,
652 DT_LOOS
= 0x6000000d,
653 DT_HIOS
= 0x6ffff000,
654 DT_LOPROC
= 0x70000000,
655 DT_HIPROC
= 0x7fffffff,
657 // The remaining values are extensions used by GNU or Solaris.
658 DT_VALRNGLO
= 0x6ffffd00,
659 DT_GNU_PRELINKED
= 0x6ffffdf5,
660 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
661 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
662 DT_CHECKSUM
= 0x6ffffdf8,
663 DT_PLTPADSZ
= 0x6ffffdf9,
664 DT_MOVEENT
= 0x6ffffdfa,
665 DT_MOVESZ
= 0x6ffffdfb,
666 DT_FEATURE
= 0x6ffffdfc,
667 DT_POSFLAG_1
= 0x6ffffdfd,
668 DT_SYMINSZ
= 0x6ffffdfe,
669 DT_SYMINENT
= 0x6ffffdff,
670 DT_VALRNGHI
= 0x6ffffdff,
672 DT_ADDRRNGLO
= 0x6ffffe00,
673 DT_GNU_HASH
= 0x6ffffef5,
674 DT_TLSDESC_PLT
= 0x6ffffef6,
675 DT_TLSDESC_GOT
= 0x6ffffef7,
676 DT_GNU_CONFLICT
= 0x6ffffef8,
677 DT_GNU_LIBLIST
= 0x6ffffef9,
678 DT_CONFIG
= 0x6ffffefa,
679 DT_DEPAUDIT
= 0x6ffffefb,
680 DT_AUDIT
= 0x6ffffefc,
681 DT_PLTPAD
= 0x6ffffefd,
682 DT_MOVETAB
= 0x6ffffefe,
683 DT_SYMINFO
= 0x6ffffeff,
684 DT_ADDRRNGHI
= 0x6ffffeff,
686 DT_RELACOUNT
= 0x6ffffff9,
687 DT_RELCOUNT
= 0x6ffffffa,
688 DT_FLAGS_1
= 0x6ffffffb,
689 DT_VERDEF
= 0x6ffffffc,
690 DT_VERDEFNUM
= 0x6ffffffd,
691 DT_VERNEED
= 0x6ffffffe,
692 DT_VERNEEDNUM
= 0x6fffffff,
694 DT_VERSYM
= 0x6ffffff0,
696 // Specify the value of _GLOBAL_OFFSET_TABLE_.
697 DT_PPC_GOT
= 0x70000000,
699 // Specify the start of the .glink section.
700 DT_PPC64_GLINK
= 0x70000000,
702 // Specify the start and size of the .opd section.
703 DT_PPC64_OPD
= 0x70000001,
704 DT_PPC64_OPDSZ
= 0x70000002,
706 // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
707 // symbol table. One dynamic entry exists for every STT_SPARC_REGISTER
708 // symbol in the symbol table.
709 DT_SPARC_REGISTER
= 0x70000001,
711 DT_AUXILIARY
= 0x7ffffffd,
712 DT_USED
= 0x7ffffffe,
713 DT_FILTER
= 0x7fffffff
716 // Flags found in the DT_FLAGS dynamic element.
727 // Flags found in the DT_FLAGS_1 dynamic element.
735 DF_1_LOADFLTR
= 0x10,
736 DF_1_INITFIRST
= 0x20,
741 DF_1_INTERPOSE
= 0x400,
742 DF_1_NODEFLIB
= 0x800,
743 DF_1_NODUMP
= 0x1000,
744 DF_1_CONLFAT
= 0x2000,
747 // Version numbers which appear in the vd_version field of a Verdef
750 const int VER_DEF_NONE
= 0;
751 const int VER_DEF_CURRENT
= 1;
753 // Version numbers which appear in the vn_version field of a Verneed
756 const int VER_NEED_NONE
= 0;
757 const int VER_NEED_CURRENT
= 1;
759 // Bit flags which appear in vd_flags of Verdef and vna_flags of
762 const int VER_FLG_BASE
= 0x1;
763 const int VER_FLG_WEAK
= 0x2;
765 // Special constants found in the SHT_GNU_versym entries.
767 const int VER_NDX_LOCAL
= 0;
768 const int VER_NDX_GLOBAL
= 1;
770 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
771 // the symbol is hidden and can only be seen when referenced using an
772 // explicit version number. This is a GNU extension.
774 const int VERSYM_HIDDEN
= 0x8000;
776 // This is the mask for the rest of the data in a word read from a
777 // SHT_GNU_versym section.
779 const int VERSYM_VERSION
= 0x7fff;
781 // Note descriptor type codes for notes in a non-core file with an
788 // An architecture string.
792 // Note descriptor type codes for notes in a non-core file with the
797 // The minimum ABI level. This is used by the dynamic linker to
798 // describe the minimal kernel version on which a shared library may
799 // be used. Th value should be four words. Word 0 is an OS
800 // descriptor (see below). Word 1 is the major version of the ABI.
801 // Word 2 is the minor version. Word 3 is the subminor version.
803 // Hardware capabilities information. Word 0 is the number of
804 // entries. Word 1 is a bitmask of enabled entries. The rest of
805 // the descriptor is a series of entries, where each entry is a
806 // single byte followed by a nul terminated string. The byte gives
807 // the bit number to test if enabled in the bitmask.
809 // The build ID as set by the linker's --build-id option. The
810 // format of the descriptor depends on the build ID style.
812 // The version of gold used to link. Th descriptor is just a
814 NT_GNU_GOLD_VERSION
= 4
817 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
821 ELF_NOTE_OS_LINUX
= 0,
823 ELF_NOTE_OS_SOLARIS2
= 2,
824 ELF_NOTE_OS_FREEBSD
= 3,
825 ELF_NOTE_OS_NETBSD
= 4,
826 ELF_NOTE_OS_SYLLABLE
= 5
829 } // End namespace elfcpp.
831 // Include internal details after defining the types.
832 #include "elfcpp_internal.h"
837 // The offset of the ELF file header in the ELF file.
839 const int file_header_offset
= 0;
841 // ELF structure sizes.
846 // Size of ELF file header.
847 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
848 // Size of ELF segment header.
849 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
850 // Size of ELF section header.
851 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
852 // Size of ELF symbol table entry.
853 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
854 // Sizes of ELF reloc entries.
855 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
856 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
857 // Size of ELF dynamic entry.
858 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
859 // Size of ELF version structures.
860 static const int verdef_size
= sizeof(internal::Verdef_data
);
861 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
862 static const int verneed_size
= sizeof(internal::Verneed_data
);
863 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
866 // Accessor class for the ELF file header.
868 template<int size
, bool big_endian
>
872 Ehdr(const unsigned char* p
)
873 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
876 template<typename File
>
877 Ehdr(File
* file
, typename
File::Location loc
)
878 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
879 file
->view(loc
.file_offset
, loc
.data_size
).data()))
884 { return this->p_
->e_ident
; }
888 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
891 get_e_machine() const
892 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
895 get_e_version() const
896 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
898 typename Elf_types
<size
>::Elf_Addr
900 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
902 typename Elf_types
<size
>::Elf_Off
904 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
906 typename Elf_types
<size
>::Elf_Off
908 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
912 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
916 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
919 get_e_phentsize() const
920 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
924 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
927 get_e_shentsize() const
928 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
932 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
935 get_e_shstrndx() const
936 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
939 const internal::Ehdr_data
<size
>* p_
;
942 // Write class for the ELF file header.
944 template<int size
, bool big_endian
>
948 Ehdr_write(unsigned char* p
)
949 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
953 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
954 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
957 put_e_type(Elf_Half v
)
958 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
961 put_e_machine(Elf_Half v
)
962 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
965 put_e_version(Elf_Word v
)
966 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
969 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
970 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
973 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
974 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
977 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
978 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
981 put_e_flags(Elf_Word v
)
982 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
985 put_e_ehsize(Elf_Half v
)
986 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
989 put_e_phentsize(Elf_Half v
)
990 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
993 put_e_phnum(Elf_Half v
)
994 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
997 put_e_shentsize(Elf_Half v
)
998 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
1001 put_e_shnum(Elf_Half v
)
1002 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
1005 put_e_shstrndx(Elf_Half v
)
1006 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
1009 internal::Ehdr_data
<size
>* p_
;
1012 // Accessor class for an ELF section header.
1014 template<int size
, bool big_endian
>
1018 Shdr(const unsigned char* p
)
1019 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
1022 template<typename File
>
1023 Shdr(File
* file
, typename
File::Location loc
)
1024 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
1025 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1030 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
1034 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
1036 typename Elf_types
<size
>::Elf_WXword
1037 get_sh_flags() const
1038 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
1040 typename Elf_types
<size
>::Elf_Addr
1042 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
1044 typename Elf_types
<size
>::Elf_Off
1045 get_sh_offset() const
1046 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
1048 typename Elf_types
<size
>::Elf_WXword
1050 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
1054 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
1058 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
1060 typename Elf_types
<size
>::Elf_WXword
1061 get_sh_addralign() const
1063 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
1065 typename Elf_types
<size
>::Elf_WXword
1066 get_sh_entsize() const
1067 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
1070 const internal::Shdr_data
<size
>* p_
;
1073 // Write class for an ELF section header.
1075 template<int size
, bool big_endian
>
1079 Shdr_write(unsigned char* p
)
1080 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
1084 put_sh_name(Elf_Word v
)
1085 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
1088 put_sh_type(Elf_Word v
)
1089 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
1092 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
1093 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
1096 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
1097 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
1100 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
1101 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1104 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
1105 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1108 put_sh_link(Elf_Word v
)
1109 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
1112 put_sh_info(Elf_Word v
)
1113 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
1116 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
1117 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
1120 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
1121 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
1124 internal::Shdr_data
<size
>* p_
;
1127 // Accessor class for an ELF segment header.
1129 template<int size
, bool big_endian
>
1133 Phdr(const unsigned char* p
)
1134 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1137 template<typename File
>
1138 Phdr(File
* file
, typename
File::Location loc
)
1139 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1140 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1145 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1147 typename Elf_types
<size
>::Elf_Off
1148 get_p_offset() const
1149 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1151 typename Elf_types
<size
>::Elf_Addr
1153 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1155 typename Elf_types
<size
>::Elf_Addr
1157 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1159 typename Elf_types
<size
>::Elf_WXword
1160 get_p_filesz() const
1161 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1163 typename Elf_types
<size
>::Elf_WXword
1165 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1169 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1171 typename Elf_types
<size
>::Elf_WXword
1173 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1176 const internal::Phdr_data
<size
>* p_
;
1179 // Write class for an ELF segment header.
1181 template<int size
, bool big_endian
>
1185 Phdr_write(unsigned char* p
)
1186 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1190 put_p_type(Elf_Word v
)
1191 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1194 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1195 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1198 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1199 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1202 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1203 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1206 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1207 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1210 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1211 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1214 put_p_flags(Elf_Word v
)
1215 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1218 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1219 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1222 internal::Phdr_data
<size
>* p_
;
1225 // Accessor class for an ELF symbol table entry.
1227 template<int size
, bool big_endian
>
1231 Sym(const unsigned char* p
)
1232 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1235 template<typename File
>
1236 Sym(File
* file
, typename
File::Location loc
)
1237 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1238 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1243 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1245 typename Elf_types
<size
>::Elf_Addr
1246 get_st_value() const
1247 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1249 typename Elf_types
<size
>::Elf_WXword
1251 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1255 { return this->p_
->st_info
; }
1259 { return elf_st_bind(this->get_st_info()); }
1263 { return elf_st_type(this->get_st_info()); }
1266 get_st_other() const
1267 { return this->p_
->st_other
; }
1270 get_st_visibility() const
1271 { return elf_st_visibility(this->get_st_other()); }
1274 get_st_nonvis() const
1275 { return elf_st_nonvis(this->get_st_other()); }
1278 get_st_shndx() const
1279 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1282 const internal::Sym_data
<size
>* p_
;
1285 // Writer class for an ELF symbol table entry.
1287 template<int size
, bool big_endian
>
1291 Sym_write(unsigned char* p
)
1292 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1296 put_st_name(Elf_Word v
)
1297 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1300 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1301 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1304 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1305 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1308 put_st_info(unsigned char v
)
1309 { this->p_
->st_info
= v
; }
1312 put_st_info(STB bind
, STT type
)
1313 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1316 put_st_other(unsigned char v
)
1317 { this->p_
->st_other
= v
; }
1320 put_st_other(STV vis
, unsigned char nonvis
)
1321 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1324 put_st_shndx(Elf_Half v
)
1325 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1327 Sym
<size
, big_endian
>
1329 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1332 internal::Sym_data
<size
>* p_
;
1335 // Accessor classes for an ELF REL relocation entry.
1337 template<int size
, bool big_endian
>
1341 Rel(const unsigned char* p
)
1342 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1345 template<typename File
>
1346 Rel(File
* file
, typename
File::Location loc
)
1347 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1348 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1351 typename Elf_types
<size
>::Elf_Addr
1352 get_r_offset() const
1353 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1355 typename Elf_types
<size
>::Elf_WXword
1357 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1360 const internal::Rel_data
<size
>* p_
;
1363 // Writer class for an ELF Rel relocation.
1365 template<int size
, bool big_endian
>
1369 Rel_write(unsigned char* p
)
1370 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1374 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1375 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1378 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1379 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1382 internal::Rel_data
<size
>* p_
;
1385 // Accessor class for an ELF Rela relocation.
1387 template<int size
, bool big_endian
>
1391 Rela(const unsigned char* p
)
1392 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1395 template<typename File
>
1396 Rela(File
* file
, typename
File::Location loc
)
1397 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1398 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1401 typename Elf_types
<size
>::Elf_Addr
1402 get_r_offset() const
1403 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1405 typename Elf_types
<size
>::Elf_WXword
1407 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1409 typename Elf_types
<size
>::Elf_Swxword
1410 get_r_addend() const
1411 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1414 const internal::Rela_data
<size
>* p_
;
1417 // Writer class for an ELF Rela relocation.
1419 template<int size
, bool big_endian
>
1423 Rela_write(unsigned char* p
)
1424 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1428 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1429 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1432 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1433 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1436 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1437 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1440 internal::Rela_data
<size
>* p_
;
1443 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1444 // PT_DYNAMIC segment.
1446 template<int size
, bool big_endian
>
1450 Dyn(const unsigned char* p
)
1451 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1454 template<typename File
>
1455 Dyn(File
* file
, typename
File::Location loc
)
1456 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1457 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1460 typename Elf_types
<size
>::Elf_Swxword
1462 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1464 typename Elf_types
<size
>::Elf_WXword
1466 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1468 typename Elf_types
<size
>::Elf_Addr
1470 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1473 const internal::Dyn_data
<size
>* p_
;
1476 // Write class for an entry in the SHT_DYNAMIC section.
1478 template<int size
, bool big_endian
>
1482 Dyn_write(unsigned char* p
)
1483 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1487 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1488 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1491 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1492 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1495 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1496 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1499 internal::Dyn_data
<size
>* p_
;
1502 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1504 template<int size
, bool big_endian
>
1508 Verdef(const unsigned char* p
)
1509 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1512 template<typename File
>
1513 Verdef(File
* file
, typename
File::Location loc
)
1514 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1515 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1519 get_vd_version() const
1520 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1523 get_vd_flags() const
1524 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1528 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1532 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1536 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1540 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1544 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1547 const internal::Verdef_data
* p_
;
1550 template<int size
, bool big_endian
>
1554 Verdef_write(unsigned char* p
)
1555 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
1559 set_vd_version(Elf_Half v
)
1560 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
1563 set_vd_flags(Elf_Half v
)
1564 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1567 set_vd_ndx(Elf_Half v
)
1568 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
1571 set_vd_cnt(Elf_Half v
)
1572 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1575 set_vd_hash(Elf_Word v
)
1576 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1579 set_vd_aux(Elf_Word v
)
1580 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1583 set_vd_next(Elf_Word v
)
1584 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
1587 internal::Verdef_data
* p_
;
1590 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1593 template<int size
, bool big_endian
>
1597 Verdaux(const unsigned char* p
)
1598 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1601 template<typename File
>
1602 Verdaux(File
* file
, typename
File::Location loc
)
1603 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1604 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1608 get_vda_name() const
1609 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1612 get_vda_next() const
1613 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1616 const internal::Verdaux_data
* p_
;
1619 template<int size
, bool big_endian
>
1623 Verdaux_write(unsigned char* p
)
1624 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
1628 set_vda_name(Elf_Word v
)
1629 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
1632 set_vda_next(Elf_Word v
)
1633 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
1636 internal::Verdaux_data
* p_
;
1639 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1641 template<int size
, bool big_endian
>
1645 Verneed(const unsigned char* p
)
1646 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1649 template<typename File
>
1650 Verneed(File
* file
, typename
File::Location loc
)
1651 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1652 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1656 get_vn_version() const
1657 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1661 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1665 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1669 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1673 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1676 const internal::Verneed_data
* p_
;
1679 template<int size
, bool big_endian
>
1683 Verneed_write(unsigned char* p
)
1684 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
1688 set_vn_version(Elf_Half v
)
1689 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
1692 set_vn_cnt(Elf_Half v
)
1693 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1696 set_vn_file(Elf_Word v
)
1697 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
1700 set_vn_aux(Elf_Word v
)
1701 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1704 set_vn_next(Elf_Word v
)
1705 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
1708 internal::Verneed_data
* p_
;
1711 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1714 template<int size
, bool big_endian
>
1718 Vernaux(const unsigned char* p
)
1719 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1722 template<typename File
>
1723 Vernaux(File
* file
, typename
File::Location loc
)
1724 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1725 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1729 get_vna_hash() const
1730 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1733 get_vna_flags() const
1734 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1737 get_vna_other() const
1738 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1741 get_vna_name() const
1742 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1745 get_vna_next() const
1746 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1749 const internal::Vernaux_data
* p_
;
1752 template<int size
, bool big_endian
>
1756 Vernaux_write(unsigned char* p
)
1757 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
1761 set_vna_hash(Elf_Word v
)
1762 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1765 set_vna_flags(Elf_Half v
)
1766 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1769 set_vna_other(Elf_Half v
)
1770 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
1773 set_vna_name(Elf_Word v
)
1774 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
1777 set_vna_next(Elf_Word v
)
1778 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
1781 internal::Vernaux_data
* p_
;
1784 } // End namespace elfcpp.
1786 #endif // !defined(ELFPCP_H)