1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010 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 // A special value found in the Ehdr e_phnum field.
309 // Number of program segments stored in sh_info field of first
314 // Special section indices.
319 SHN_LORESERVE
= 0xff00,
327 SHN_HIRESERVE
= 0xffff,
329 // Provide for initial and final section ordering in conjunction
330 // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
334 // x86_64 specific large common symbol.
335 SHN_X86_64_LCOMMON
= 0xff02
338 // The valid values found in the Shdr sh_type field.
356 SHT_PREINIT_ARRAY
= 16,
358 SHT_SYMTAB_SHNDX
= 18,
359 SHT_LOOS
= 0x60000000,
360 SHT_HIOS
= 0x6fffffff,
361 SHT_LOPROC
= 0x70000000,
362 SHT_HIPROC
= 0x7fffffff,
363 SHT_LOUSER
= 0x80000000,
364 SHT_HIUSER
= 0xffffffff,
365 // The remaining values are not in the standard.
366 // Incremental build data.
367 SHT_GNU_INCREMENTAL_INPUTS
= 0x6fff4700,
368 // Object attributes.
369 SHT_GNU_ATTRIBUTES
= 0x6ffffff5,
370 // GNU style dynamic hash table.
371 SHT_GNU_HASH
= 0x6ffffff6,
372 // List of prelink dependencies.
373 SHT_GNU_LIBLIST
= 0x6ffffff7,
374 // Versions defined by file.
375 SHT_SUNW_verdef
= 0x6ffffffd,
376 SHT_GNU_verdef
= 0x6ffffffd,
377 // Versions needed by file.
378 SHT_SUNW_verneed
= 0x6ffffffe,
379 SHT_GNU_verneed
= 0x6ffffffe,
381 SHT_SUNW_versym
= 0x6fffffff,
382 SHT_GNU_versym
= 0x6fffffff,
384 SHT_SPARC_GOTDATA
= 0x70000000,
386 // ARM-specific section types.
387 // Exception Index table.
388 SHT_ARM_EXIDX
= 0x70000001,
389 // BPABI DLL dynamic linking pre-emption map.
390 SHT_ARM_PREEMPTMAP
= 0x70000002,
391 // Object file compatibility attributes.
392 SHT_ARM_ATTRIBUTES
= 0x70000003,
393 // Support for debugging overlaid programs.
394 SHT_ARM_DEBUGOVERLAY
= 0x70000004,
395 SHT_ARM_OVERLAYSECTION
= 0x70000005,
397 // x86_64 unwind information.
398 SHT_X86_64_UNWIND
= 0x70000001,
400 // Link editor is to sort the entries in this section based on the
401 // address specified in the associated symbol table entry.
402 SHT_ORDERED
= 0x7fffffff
405 // The valid bit flags found in the Shdr sh_flags field.
414 SHF_INFO_LINK
= 0x40,
415 SHF_LINK_ORDER
= 0x80,
416 SHF_OS_NONCONFORMING
= 0x100,
419 SHF_MASKOS
= 0x0ff00000,
420 SHF_MASKPROC
= 0xf0000000,
422 // Indicates this section requires ordering in relation to
423 // other sections of the same type. Ordered sections are
424 // combined within the section pointed to by the sh_link entry.
425 // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
426 // sorted section is to precede or follow, respectively, all
427 // other sections in the set being ordered.
428 SHF_ORDERED
= 0x40000000,
429 // This section is excluded from input to the link-edit of an
430 // executable or shared object. This flag is ignored if SHF_ALLOC
431 // is also set, or if relocations exist against the section.
432 SHF_EXCLUDE
= 0x80000000,
434 // x86_64 specific large section.
435 SHF_X86_64_LARGE
= 0x10000000
438 // Bit flags which appear in the first 32-bit word of the section data
439 // of a SHT_GROUP section.
444 GRP_MASKOS
= 0x0ff00000,
445 GRP_MASKPROC
= 0xf0000000
448 // The valid values found in the Phdr p_type field.
460 PT_LOOS
= 0x60000000,
461 PT_HIOS
= 0x6fffffff,
462 PT_LOPROC
= 0x70000000,
463 PT_HIPROC
= 0x7fffffff,
464 // The remaining values are not in the standard.
465 // Frame unwind information.
466 PT_GNU_EH_FRAME
= 0x6474e550,
467 PT_SUNW_EH_FRAME
= 0x6474e550,
469 PT_GNU_STACK
= 0x6474e551,
470 // Read only after relocation.
471 PT_GNU_RELRO
= 0x6474e552,
472 // Platform architecture compatibility information
473 PT_ARM_ARCHEXT
= 0x70000000,
474 // Exception unwind tables
475 PT_ARM_EXIDX
= 0x70000001
478 // The valid bit flags found in the Phdr p_flags field.
485 PF_MASKOS
= 0x0ff00000,
486 PF_MASKPROC
= 0xf0000000
489 // Symbol binding from Sym st_info field.
503 // Symbol types from Sym st_info field.
520 // The section type that must be used for register symbols on
521 // Sparc. These symbols initialize a global register.
522 STT_SPARC_REGISTER
= 13,
524 // ARM: a THUMB function. This is not defined in ARM ELF Specification but
525 // used by the GNU tool-chain.
530 elf_st_bind(unsigned char info
)
532 return static_cast<STB
>(info
>> 4);
536 elf_st_type(unsigned char info
)
538 return static_cast<STT
>(info
& 0xf);
542 elf_st_info(STB bind
, STT type
)
544 return ((static_cast<unsigned char>(bind
) << 4)
545 + (static_cast<unsigned char>(type
) & 0xf));
548 // Symbol visibility from Sym st_other field.
559 elf_st_visibility(unsigned char other
)
561 return static_cast<STV
>(other
& 0x3);
565 elf_st_nonvis(unsigned char other
)
567 return static_cast<STV
>(other
>> 2);
571 elf_st_other(STV vis
, unsigned char nonvis
)
573 return ((nonvis
<< 2)
574 + (static_cast<unsigned char>(vis
) & 3));
577 // Reloc information from Rel/Rela r_info field.
581 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
585 elf_r_sym
<32>(Elf_Word v
)
592 elf_r_sym
<64>(Elf_Xword v
)
599 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
603 elf_r_type
<32>(Elf_Word v
)
610 elf_r_type
<64>(Elf_Xword v
)
612 return v
& 0xffffffff;
616 typename Elf_types
<size
>::Elf_WXword
617 elf_r_info(unsigned int s
, unsigned int t
);
621 elf_r_info
<32>(unsigned int s
, unsigned int t
)
623 return (s
<< 8) + (t
& 0xff);
628 elf_r_info
<64>(unsigned int s
, unsigned int t
)
630 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
633 // Dynamic tags found in the PT_DYNAMIC segment.
664 DT_INIT_ARRAYSZ
= 27,
665 DT_FINI_ARRAYSZ
= 28,
669 // This is used to mark a range of dynamic tags. It is not really
673 DT_PREINIT_ARRAY
= 32,
674 DT_PREINIT_ARRAYSZ
= 33,
675 DT_LOOS
= 0x6000000d,
676 DT_HIOS
= 0x6ffff000,
677 DT_LOPROC
= 0x70000000,
678 DT_HIPROC
= 0x7fffffff,
680 // The remaining values are extensions used by GNU or Solaris.
681 DT_VALRNGLO
= 0x6ffffd00,
682 DT_GNU_PRELINKED
= 0x6ffffdf5,
683 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
684 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
685 DT_CHECKSUM
= 0x6ffffdf8,
686 DT_PLTPADSZ
= 0x6ffffdf9,
687 DT_MOVEENT
= 0x6ffffdfa,
688 DT_MOVESZ
= 0x6ffffdfb,
689 DT_FEATURE
= 0x6ffffdfc,
690 DT_POSFLAG_1
= 0x6ffffdfd,
691 DT_SYMINSZ
= 0x6ffffdfe,
692 DT_SYMINENT
= 0x6ffffdff,
693 DT_VALRNGHI
= 0x6ffffdff,
695 DT_ADDRRNGLO
= 0x6ffffe00,
696 DT_GNU_HASH
= 0x6ffffef5,
697 DT_TLSDESC_PLT
= 0x6ffffef6,
698 DT_TLSDESC_GOT
= 0x6ffffef7,
699 DT_GNU_CONFLICT
= 0x6ffffef8,
700 DT_GNU_LIBLIST
= 0x6ffffef9,
701 DT_CONFIG
= 0x6ffffefa,
702 DT_DEPAUDIT
= 0x6ffffefb,
703 DT_AUDIT
= 0x6ffffefc,
704 DT_PLTPAD
= 0x6ffffefd,
705 DT_MOVETAB
= 0x6ffffefe,
706 DT_SYMINFO
= 0x6ffffeff,
707 DT_ADDRRNGHI
= 0x6ffffeff,
709 DT_RELACOUNT
= 0x6ffffff9,
710 DT_RELCOUNT
= 0x6ffffffa,
711 DT_FLAGS_1
= 0x6ffffffb,
712 DT_VERDEF
= 0x6ffffffc,
713 DT_VERDEFNUM
= 0x6ffffffd,
714 DT_VERNEED
= 0x6ffffffe,
715 DT_VERNEEDNUM
= 0x6fffffff,
717 DT_VERSYM
= 0x6ffffff0,
719 // Specify the value of _GLOBAL_OFFSET_TABLE_.
720 DT_PPC_GOT
= 0x70000000,
722 // Specify the start of the .glink section.
723 DT_PPC64_GLINK
= 0x70000000,
725 // Specify the start and size of the .opd section.
726 DT_PPC64_OPD
= 0x70000001,
727 DT_PPC64_OPDSZ
= 0x70000002,
729 // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
730 // symbol table. One dynamic entry exists for every STT_SPARC_REGISTER
731 // symbol in the symbol table.
732 DT_SPARC_REGISTER
= 0x70000001,
734 DT_AUXILIARY
= 0x7ffffffd,
735 DT_USED
= 0x7ffffffe,
736 DT_FILTER
= 0x7fffffff
739 // Flags found in the DT_FLAGS dynamic element.
750 // Flags found in the DT_FLAGS_1 dynamic element.
758 DF_1_LOADFLTR
= 0x10,
759 DF_1_INITFIRST
= 0x20,
764 DF_1_INTERPOSE
= 0x400,
765 DF_1_NODEFLIB
= 0x800,
766 DF_1_NODUMP
= 0x1000,
767 DF_1_CONLFAT
= 0x2000
770 // Version numbers which appear in the vd_version field of a Verdef
773 const int VER_DEF_NONE
= 0;
774 const int VER_DEF_CURRENT
= 1;
776 // Version numbers which appear in the vn_version field of a Verneed
779 const int VER_NEED_NONE
= 0;
780 const int VER_NEED_CURRENT
= 1;
782 // Bit flags which appear in vd_flags of Verdef and vna_flags of
785 const int VER_FLG_BASE
= 0x1;
786 const int VER_FLG_WEAK
= 0x2;
787 const int VER_FLG_INFO
= 0x4;
789 // Special constants found in the SHT_GNU_versym entries.
791 const int VER_NDX_LOCAL
= 0;
792 const int VER_NDX_GLOBAL
= 1;
794 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
795 // the symbol is hidden and can only be seen when referenced using an
796 // explicit version number. This is a GNU extension.
798 const int VERSYM_HIDDEN
= 0x8000;
800 // This is the mask for the rest of the data in a word read from a
801 // SHT_GNU_versym section.
803 const int VERSYM_VERSION
= 0x7fff;
805 // Note descriptor type codes for notes in a non-core file with an
812 // An architecture string.
816 // Note descriptor type codes for notes in a non-core file with the
821 // The minimum ABI level. This is used by the dynamic linker to
822 // describe the minimal kernel version on which a shared library may
823 // be used. Th value should be four words. Word 0 is an OS
824 // descriptor (see below). Word 1 is the major version of the ABI.
825 // Word 2 is the minor version. Word 3 is the subminor version.
827 // Hardware capabilities information. Word 0 is the number of
828 // entries. Word 1 is a bitmask of enabled entries. The rest of
829 // the descriptor is a series of entries, where each entry is a
830 // single byte followed by a nul terminated string. The byte gives
831 // the bit number to test if enabled in the bitmask.
833 // The build ID as set by the linker's --build-id option. The
834 // format of the descriptor depends on the build ID style.
836 // The version of gold used to link. Th descriptor is just a
838 NT_GNU_GOLD_VERSION
= 4
841 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
845 ELF_NOTE_OS_LINUX
= 0,
847 ELF_NOTE_OS_SOLARIS2
= 2,
848 ELF_NOTE_OS_FREEBSD
= 3,
849 ELF_NOTE_OS_NETBSD
= 4,
850 ELF_NOTE_OS_SYLLABLE
= 5
853 } // End namespace elfcpp.
855 // Include internal details after defining the types.
856 #include "elfcpp_internal.h"
861 // The offset of the ELF file header in the ELF file.
863 const int file_header_offset
= 0;
865 // ELF structure sizes.
870 // Size of ELF file header.
871 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
872 // Size of ELF segment header.
873 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
874 // Size of ELF section header.
875 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
876 // Size of ELF symbol table entry.
877 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
878 // Sizes of ELF reloc entries.
879 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
880 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
881 // Size of ELF dynamic entry.
882 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
883 // Size of ELF version structures.
884 static const int verdef_size
= sizeof(internal::Verdef_data
);
885 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
886 static const int verneed_size
= sizeof(internal::Verneed_data
);
887 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
890 // Accessor class for the ELF file header.
892 template<int size
, bool big_endian
>
896 Ehdr(const unsigned char* p
)
897 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
900 template<typename File
>
901 Ehdr(File
* file
, typename
File::Location loc
)
902 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
903 file
->view(loc
.file_offset
, loc
.data_size
).data()))
908 { return this->p_
->e_ident
; }
912 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
915 get_e_machine() const
916 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
919 get_e_version() const
920 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
922 typename Elf_types
<size
>::Elf_Addr
924 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
926 typename Elf_types
<size
>::Elf_Off
928 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
930 typename Elf_types
<size
>::Elf_Off
932 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
936 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
940 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
943 get_e_phentsize() const
944 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
948 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
951 get_e_shentsize() const
952 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
956 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
959 get_e_shstrndx() const
960 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
963 const internal::Ehdr_data
<size
>* p_
;
966 // Write class for the ELF file header.
968 template<int size
, bool big_endian
>
972 Ehdr_write(unsigned char* p
)
973 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
977 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
978 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
981 put_e_type(Elf_Half v
)
982 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
985 put_e_machine(Elf_Half v
)
986 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
989 put_e_version(Elf_Word v
)
990 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
993 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
994 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
997 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
998 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
1001 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
1002 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
1005 put_e_flags(Elf_Word v
)
1006 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1009 put_e_ehsize(Elf_Half v
)
1010 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
1013 put_e_phentsize(Elf_Half v
)
1014 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
1017 put_e_phnum(Elf_Half v
)
1018 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
1021 put_e_shentsize(Elf_Half v
)
1022 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
1025 put_e_shnum(Elf_Half v
)
1026 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
1029 put_e_shstrndx(Elf_Half v
)
1030 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
1033 internal::Ehdr_data
<size
>* p_
;
1036 // Accessor class for an ELF section header.
1038 template<int size
, bool big_endian
>
1042 Shdr(const unsigned char* p
)
1043 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
1046 template<typename File
>
1047 Shdr(File
* file
, typename
File::Location loc
)
1048 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
1049 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1054 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
1058 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
1060 typename Elf_types
<size
>::Elf_WXword
1061 get_sh_flags() const
1062 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
1064 typename Elf_types
<size
>::Elf_Addr
1066 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
1068 typename Elf_types
<size
>::Elf_Off
1069 get_sh_offset() const
1070 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
1072 typename Elf_types
<size
>::Elf_WXword
1074 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
1078 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
1082 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
1084 typename Elf_types
<size
>::Elf_WXword
1085 get_sh_addralign() const
1087 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
1089 typename Elf_types
<size
>::Elf_WXword
1090 get_sh_entsize() const
1091 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
1094 const internal::Shdr_data
<size
>* p_
;
1097 // Write class for an ELF section header.
1099 template<int size
, bool big_endian
>
1103 Shdr_write(unsigned char* p
)
1104 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
1108 put_sh_name(Elf_Word v
)
1109 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
1112 put_sh_type(Elf_Word v
)
1113 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
1116 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
1117 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
1120 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
1121 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
1124 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
1125 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1128 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
1129 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1132 put_sh_link(Elf_Word v
)
1133 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
1136 put_sh_info(Elf_Word v
)
1137 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
1140 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
1141 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
1144 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
1145 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
1148 internal::Shdr_data
<size
>* p_
;
1151 // Accessor class for an ELF segment header.
1153 template<int size
, bool big_endian
>
1157 Phdr(const unsigned char* p
)
1158 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1161 template<typename File
>
1162 Phdr(File
* file
, typename
File::Location loc
)
1163 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1164 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1169 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1171 typename Elf_types
<size
>::Elf_Off
1172 get_p_offset() const
1173 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1175 typename Elf_types
<size
>::Elf_Addr
1177 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1179 typename Elf_types
<size
>::Elf_Addr
1181 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1183 typename Elf_types
<size
>::Elf_WXword
1184 get_p_filesz() const
1185 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1187 typename Elf_types
<size
>::Elf_WXword
1189 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1193 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1195 typename Elf_types
<size
>::Elf_WXword
1197 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1200 const internal::Phdr_data
<size
>* p_
;
1203 // Write class for an ELF segment header.
1205 template<int size
, bool big_endian
>
1209 Phdr_write(unsigned char* p
)
1210 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1214 put_p_type(Elf_Word v
)
1215 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1218 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1219 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1222 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1223 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1226 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1227 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1230 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1231 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1234 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1235 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1238 put_p_flags(Elf_Word v
)
1239 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1242 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1243 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1246 internal::Phdr_data
<size
>* p_
;
1249 // Accessor class for an ELF symbol table entry.
1251 template<int size
, bool big_endian
>
1255 Sym(const unsigned char* p
)
1256 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1259 template<typename File
>
1260 Sym(File
* file
, typename
File::Location loc
)
1261 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1262 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1267 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1269 typename Elf_types
<size
>::Elf_Addr
1270 get_st_value() const
1271 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1273 typename Elf_types
<size
>::Elf_WXword
1275 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1279 { return this->p_
->st_info
; }
1283 { return elf_st_bind(this->get_st_info()); }
1287 { return elf_st_type(this->get_st_info()); }
1290 get_st_other() const
1291 { return this->p_
->st_other
; }
1294 get_st_visibility() const
1295 { return elf_st_visibility(this->get_st_other()); }
1298 get_st_nonvis() const
1299 { return elf_st_nonvis(this->get_st_other()); }
1302 get_st_shndx() const
1303 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1306 const internal::Sym_data
<size
>* p_
;
1309 // Writer class for an ELF symbol table entry.
1311 template<int size
, bool big_endian
>
1315 Sym_write(unsigned char* p
)
1316 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1320 put_st_name(Elf_Word v
)
1321 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1324 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1325 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1328 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1329 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1332 put_st_info(unsigned char v
)
1333 { this->p_
->st_info
= v
; }
1336 put_st_info(STB bind
, STT type
)
1337 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1340 put_st_other(unsigned char v
)
1341 { this->p_
->st_other
= v
; }
1344 put_st_other(STV vis
, unsigned char nonvis
)
1345 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1348 put_st_shndx(Elf_Half v
)
1349 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1351 Sym
<size
, big_endian
>
1353 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1356 internal::Sym_data
<size
>* p_
;
1359 // Accessor classes for an ELF REL relocation entry.
1361 template<int size
, bool big_endian
>
1365 Rel(const unsigned char* p
)
1366 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1369 template<typename File
>
1370 Rel(File
* file
, typename
File::Location loc
)
1371 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1372 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1375 typename Elf_types
<size
>::Elf_Addr
1376 get_r_offset() const
1377 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1379 typename Elf_types
<size
>::Elf_WXword
1381 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1384 const internal::Rel_data
<size
>* p_
;
1387 // Writer class for an ELF Rel relocation.
1389 template<int size
, bool big_endian
>
1393 Rel_write(unsigned char* p
)
1394 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1398 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1399 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1402 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1403 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1406 internal::Rel_data
<size
>* p_
;
1409 // Accessor class for an ELF Rela relocation.
1411 template<int size
, bool big_endian
>
1415 Rela(const unsigned char* p
)
1416 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1419 template<typename File
>
1420 Rela(File
* file
, typename
File::Location loc
)
1421 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1422 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1425 typename Elf_types
<size
>::Elf_Addr
1426 get_r_offset() const
1427 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1429 typename Elf_types
<size
>::Elf_WXword
1431 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1433 typename Elf_types
<size
>::Elf_Swxword
1434 get_r_addend() const
1435 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1438 const internal::Rela_data
<size
>* p_
;
1441 // Writer class for an ELF Rela relocation.
1443 template<int size
, bool big_endian
>
1447 Rela_write(unsigned char* p
)
1448 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1452 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1453 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1456 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1457 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1460 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1461 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1464 internal::Rela_data
<size
>* p_
;
1467 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1468 // PT_DYNAMIC segment.
1470 template<int size
, bool big_endian
>
1474 Dyn(const unsigned char* p
)
1475 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1478 template<typename File
>
1479 Dyn(File
* file
, typename
File::Location loc
)
1480 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1481 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1484 typename Elf_types
<size
>::Elf_Swxword
1486 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1488 typename Elf_types
<size
>::Elf_WXword
1490 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1492 typename Elf_types
<size
>::Elf_Addr
1494 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1497 const internal::Dyn_data
<size
>* p_
;
1500 // Write class for an entry in the SHT_DYNAMIC section.
1502 template<int size
, bool big_endian
>
1506 Dyn_write(unsigned char* p
)
1507 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1511 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1512 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1515 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1516 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1519 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1520 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1523 internal::Dyn_data
<size
>* p_
;
1526 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1528 template<int size
, bool big_endian
>
1532 Verdef(const unsigned char* p
)
1533 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1536 template<typename File
>
1537 Verdef(File
* file
, typename
File::Location loc
)
1538 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1539 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1543 get_vd_version() const
1544 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1547 get_vd_flags() const
1548 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1552 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
1556 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
1560 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
1564 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
1568 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
1571 const internal::Verdef_data
* p_
;
1574 template<int size
, bool big_endian
>
1578 Verdef_write(unsigned char* p
)
1579 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
1583 set_vd_version(Elf_Half v
)
1584 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
1587 set_vd_flags(Elf_Half v
)
1588 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1591 set_vd_ndx(Elf_Half v
)
1592 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
1595 set_vd_cnt(Elf_Half v
)
1596 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1599 set_vd_hash(Elf_Word v
)
1600 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1603 set_vd_aux(Elf_Word v
)
1604 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1607 set_vd_next(Elf_Word v
)
1608 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
1611 internal::Verdef_data
* p_
;
1614 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
1617 template<int size
, bool big_endian
>
1621 Verdaux(const unsigned char* p
)
1622 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
1625 template<typename File
>
1626 Verdaux(File
* file
, typename
File::Location loc
)
1627 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
1628 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1632 get_vda_name() const
1633 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
1636 get_vda_next() const
1637 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
1640 const internal::Verdaux_data
* p_
;
1643 template<int size
, bool big_endian
>
1647 Verdaux_write(unsigned char* p
)
1648 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
1652 set_vda_name(Elf_Word v
)
1653 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
1656 set_vda_next(Elf_Word v
)
1657 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
1660 internal::Verdaux_data
* p_
;
1663 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
1665 template<int size
, bool big_endian
>
1669 Verneed(const unsigned char* p
)
1670 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
1673 template<typename File
>
1674 Verneed(File
* file
, typename
File::Location loc
)
1675 : p_(reinterpret_cast<const internal::Verneed_data
*>(
1676 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1680 get_vn_version() const
1681 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
1685 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
1689 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
1693 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
1697 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
1700 const internal::Verneed_data
* p_
;
1703 template<int size
, bool big_endian
>
1707 Verneed_write(unsigned char* p
)
1708 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
1712 set_vn_version(Elf_Half v
)
1713 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
1716 set_vn_cnt(Elf_Half v
)
1717 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
1720 set_vn_file(Elf_Word v
)
1721 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
1724 set_vn_aux(Elf_Word v
)
1725 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
1728 set_vn_next(Elf_Word v
)
1729 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
1732 internal::Verneed_data
* p_
;
1735 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
1738 template<int size
, bool big_endian
>
1742 Vernaux(const unsigned char* p
)
1743 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
1746 template<typename File
>
1747 Vernaux(File
* file
, typename
File::Location loc
)
1748 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
1749 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1753 get_vna_hash() const
1754 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
1757 get_vna_flags() const
1758 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
1761 get_vna_other() const
1762 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
1765 get_vna_name() const
1766 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
1769 get_vna_next() const
1770 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
1773 const internal::Vernaux_data
* p_
;
1776 template<int size
, bool big_endian
>
1780 Vernaux_write(unsigned char* p
)
1781 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
1785 set_vna_hash(Elf_Word v
)
1786 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
1789 set_vna_flags(Elf_Half v
)
1790 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
1793 set_vna_other(Elf_Half v
)
1794 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
1797 set_vna_name(Elf_Word v
)
1798 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
1801 set_vna_next(Elf_Word v
)
1802 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
1805 internal::Vernaux_data
* p_
;
1808 } // End namespace elfcpp.
1810 #endif // !defined(ELFPCP_H)