1 // elfcpp.h -- main header file for elfcpp -*- C++ -*-
3 // Copyright (C) 2006-2023 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].
133 // ELFOSABI_LINUX is an alias for ELFOSABI_GNU.
135 ELFOSABI_SOLARIS
= 6,
138 ELFOSABI_FREEBSD
= 9,
140 ELFOSABI_MODESTO
= 11,
141 ELFOSABI_OPENBSD
= 12,
142 ELFOSABI_OPENVMS
= 13,
145 // A GNU extension for the ARM.
147 // A GNU extension for the MSP.
148 ELFOSABI_STANDALONE
= 255
151 // The valid values found in the Ehdr e_type field.
166 // The valid values found in the Ehdr e_machine field.
181 // 11 was the old Sparc V9 ABI.
182 // 12 through 14 are reserved.
185 // Some old PowerPC object files use 17.
192 // 23 through 35 are served.
256 // Some old picoJava object files use 99 (EM_PJ is correct).
269 EM_ALTERA_NIOS2
= 113,
280 // Infineon Technologies 16-bit microcontroller with C166-V2 core.
283 EM_XSTORMY16
= 0xad45,
290 // Old AVR objects used 0x1057 (EM_AVR is correct).
291 // Old MSP430 objects used 0x1059 (EM_MSP430 is correct).
292 // Old FR30 objects used 0x3330 (EM_FR30 is correct).
293 // Old OpenRISC objects used 0x3426 and 0x8472 (EM_OR1K is correct).
294 // Old D10V objects used 0x7650 (EM_D10V is correct).
295 // Old D30V objects used 0x7676 (EM_D30V is correct).
296 // Old IP2X objects used 0x8217 (EM_IP2K is correct).
297 // Old PowerPC objects used 0x9025 (EM_PPC is correct).
298 // Old Alpha objects used 0x9026 (EM_ALPHA is correct).
299 // Old M32R objects used 0x9041 (EM_M32R is correct).
300 // Old V850 objects used 0x9080 (EM_V850 is correct).
301 // Old S/390 objects used 0xa390 (EM_S390 is correct).
302 // Old Xtensa objects used 0xabc7 (EM_XTENSA is correct).
303 // Old MN10300 objects used 0xbeef (EM_MN10300 is correct).
304 // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
307 // A special value found in the Ehdr e_phnum field.
311 // Number of program segments stored in sh_info field of first
316 // Special section indices.
321 SHN_LORESERVE
= 0xff00,
329 SHN_HIRESERVE
= 0xffff,
331 // Provide for initial and final section ordering in conjunction
332 // with the SHF_LINK_ORDER and SHF_ORDERED section flags.
336 // x86_64 specific large common symbol.
337 SHN_X86_64_LCOMMON
= 0xff02
340 // The valid values found in the Shdr sh_type field.
358 SHT_PREINIT_ARRAY
= 16,
360 SHT_SYMTAB_SHNDX
= 18,
361 SHT_LOOS
= 0x60000000,
362 SHT_HIOS
= 0x6fffffff,
363 SHT_LOPROC
= 0x70000000,
364 SHT_HIPROC
= 0x7fffffff,
365 SHT_LOUSER
= 0x80000000,
366 SHT_HIUSER
= 0xffffffff,
367 // The remaining values are not in the standard.
368 // Incremental build data.
369 SHT_GNU_INCREMENTAL_INPUTS
= 0x6fff4700,
370 SHT_GNU_INCREMENTAL_SYMTAB
= 0x6fff4701,
371 SHT_GNU_INCREMENTAL_RELOCS
= 0x6fff4702,
372 SHT_GNU_INCREMENTAL_GOT_PLT
= 0x6fff4703,
373 // Object attributes.
374 SHT_GNU_ATTRIBUTES
= 0x6ffffff5,
375 // GNU style dynamic hash table.
376 SHT_GNU_HASH
= 0x6ffffff6,
377 // List of prelink dependencies.
378 SHT_GNU_LIBLIST
= 0x6ffffff7,
379 // Versions defined by file.
380 SHT_SUNW_verdef
= 0x6ffffffd,
381 SHT_GNU_verdef
= 0x6ffffffd,
382 // Versions needed by file.
383 SHT_SUNW_verneed
= 0x6ffffffe,
384 SHT_GNU_verneed
= 0x6ffffffe,
386 SHT_SUNW_versym
= 0x6fffffff,
387 SHT_GNU_versym
= 0x6fffffff,
389 SHT_SPARC_GOTDATA
= 0x70000000,
391 // ARM-specific section types.
392 // Exception Index table.
393 SHT_ARM_EXIDX
= 0x70000001,
394 // BPABI DLL dynamic linking pre-emption map.
395 SHT_ARM_PREEMPTMAP
= 0x70000002,
396 // Object file compatibility attributes.
397 SHT_ARM_ATTRIBUTES
= 0x70000003,
398 // Support for debugging overlaid programs.
399 SHT_ARM_DEBUGOVERLAY
= 0x70000004,
400 SHT_ARM_OVERLAYSECTION
= 0x70000005,
402 // x86_64 unwind information.
403 SHT_X86_64_UNWIND
= 0x70000001,
405 // MIPS-specific section types.
406 // Section contains register usage information.
407 SHT_MIPS_REGINFO
= 0x70000006,
408 // Section contains miscellaneous options.
409 SHT_MIPS_OPTIONS
= 0x7000000d,
410 // ABI related flags section.
411 SHT_MIPS_ABIFLAGS
= 0x7000002a,
413 // AARCH64-specific section type.
414 SHT_AARCH64_ATTRIBUTES
= 0x70000003,
416 // CSKY-specific section types.
417 // Object file compatibility attributes.
418 SHT_CSKY_ATTRIBUTES
= 0x70000001,
420 // Link editor is to sort the entries in this section based on the
421 // address specified in the associated symbol table entry.
422 SHT_ORDERED
= 0x7fffffff
425 // The valid bit flags found in the Shdr sh_flags field.
434 SHF_INFO_LINK
= 0x40,
435 SHF_LINK_ORDER
= 0x80,
436 SHF_OS_NONCONFORMING
= 0x100,
439 SHF_COMPRESSED
= 0x800,
440 SHF_MASKOS
= 0x0ff00000,
441 SHF_GNU_RETAIN
= 0x200000,
442 SHF_MASKPROC
= 0xf0000000,
444 // Indicates this section requires ordering in relation to
445 // other sections of the same type. Ordered sections are
446 // combined within the section pointed to by the sh_link entry.
447 // The sh_info values SHN_BEFORE and SHN_AFTER imply that the
448 // sorted section is to precede or follow, respectively, all
449 // other sections in the set being ordered.
450 SHF_ORDERED
= 0x40000000,
451 // This section is excluded from input to the link-edit of an
452 // executable or shared object. This flag is ignored if SHF_ALLOC
453 // is also set, or if relocations exist against the section.
454 SHF_EXCLUDE
= 0x80000000,
456 // Section with data that is GP relative addressable.
457 SHF_MIPS_GPREL
= 0x10000000,
459 // x86_64 specific large section.
460 SHF_X86_64_LARGE
= 0x10000000
463 // Values which appear in the first Elf_WXword of the section data
464 // of a SHF_COMPRESSED section.
467 ELFCOMPRESS_ZLIB
= 1,
468 ELFCOMPRESS_ZSTD
= 2,
469 ELFCOMPRESS_LOOS
= 0x60000000,
470 ELFCOMPRESS_HIOS
= 0x6fffffff,
471 ELFCOMPRESS_LOPROC
= 0x70000000,
472 ELFCOMPRESS_HIPROC
= 0x7fffffff,
475 // Bit flags which appear in the first 32-bit word of the section data
476 // of a SHT_GROUP section.
481 GRP_MASKOS
= 0x0ff00000,
482 GRP_MASKPROC
= 0xf0000000
485 // The valid values found in the Phdr p_type field.
497 PT_LOOS
= 0x60000000,
498 PT_HIOS
= 0x6fffffff,
499 PT_LOPROC
= 0x70000000,
500 PT_HIPROC
= 0x7fffffff,
501 // The remaining values are not in the standard.
502 // Frame unwind information.
503 PT_GNU_EH_FRAME
= 0x6474e550,
504 PT_SUNW_EH_FRAME
= 0x6474e550,
506 PT_GNU_STACK
= 0x6474e551,
507 // Read only after relocation.
508 PT_GNU_RELRO
= 0x6474e552,
509 // Platform architecture compatibility information
510 PT_ARM_ARCHEXT
= 0x70000000,
511 // Exception unwind tables
512 PT_ARM_EXIDX
= 0x70000001,
513 // Register usage information. Identifies one .reginfo section.
514 PT_MIPS_REGINFO
=0x70000000,
515 // Runtime procedure table.
516 PT_MIPS_RTPROC
= 0x70000001,
517 // .MIPS.options section.
518 PT_MIPS_OPTIONS
= 0x70000002,
519 // .MIPS.abiflags section.
520 PT_MIPS_ABIFLAGS
= 0x70000003,
521 // Platform architecture compatibility information
522 PT_AARCH64_ARCHEXT
= 0x70000000,
523 // Exception unwind tables
524 PT_AARCH64_UNWIND
= 0x70000001,
525 // 4k page table size
526 PT_S390_PGSTE
= 0x70000000,
529 // The valid bit flags found in the Phdr p_flags field.
536 PF_MASKOS
= 0x0ff00000,
537 PF_MASKPROC
= 0xf0000000
540 // Symbol binding from Sym st_info field.
554 // Symbol types from Sym st_info field.
566 // GNU extension: symbol value points to a function which is called
567 // at runtime to determine the final value of the symbol.
575 // The section type that must be used for register symbols on
576 // Sparc. These symbols initialize a global register.
577 STT_SPARC_REGISTER
= 13,
579 // ARM: a THUMB function. This is not defined in ARM ELF Specification but
580 // used by the GNU tool-chain.
585 elf_st_bind(unsigned char info
)
587 return static_cast<STB
>(info
>> 4);
591 elf_st_type(unsigned char info
)
593 return static_cast<STT
>(info
& 0xf);
597 elf_st_info(STB bind
, STT type
)
599 return ((static_cast<unsigned char>(bind
) << 4)
600 + (static_cast<unsigned char>(type
) & 0xf));
603 // Symbol visibility from Sym st_other field.
614 elf_st_visibility(unsigned char other
)
616 return static_cast<STV
>(other
& 0x3);
620 elf_st_nonvis(unsigned char other
)
622 return static_cast<STV
>(other
>> 2);
626 elf_st_other(STV vis
, unsigned char nonvis
)
628 return ((nonvis
<< 2)
629 + (static_cast<unsigned char>(vis
) & 3));
632 // Reloc information from Rel/Rela r_info field.
636 elf_r_sym(typename Elf_types
<size
>::Elf_WXword
);
640 elf_r_sym
<32>(Elf_Word v
)
647 elf_r_sym
<64>(Elf_Xword v
)
654 elf_r_type(typename Elf_types
<size
>::Elf_WXword
);
658 elf_r_type
<32>(Elf_Word v
)
665 elf_r_type
<64>(Elf_Xword v
)
667 return v
& 0xffffffff;
671 typename Elf_types
<size
>::Elf_WXword
672 elf_r_info(unsigned int s
, unsigned int t
);
676 elf_r_info
<32>(unsigned int s
, unsigned int t
)
678 return (s
<< 8) + (t
& 0xff);
683 elf_r_info
<64>(unsigned int s
, unsigned int t
)
685 return (static_cast<Elf_Xword
>(s
) << 32) + (t
& 0xffffffff);
688 // Dynamic tags found in the PT_DYNAMIC segment.
719 DT_INIT_ARRAYSZ
= 27,
720 DT_FINI_ARRAYSZ
= 28,
724 // This is used to mark a range of dynamic tags. It is not really
728 DT_PREINIT_ARRAY
= 32,
729 DT_PREINIT_ARRAYSZ
= 33,
730 DT_LOOS
= 0x6000000d,
731 DT_HIOS
= 0x6ffff000,
732 DT_LOPROC
= 0x70000000,
733 DT_HIPROC
= 0x7fffffff,
735 // The remaining values are extensions used by GNU or Solaris.
736 DT_VALRNGLO
= 0x6ffffd00,
737 DT_GNU_FLAGS_1
= 0x6ffffdf4,
738 DT_GNU_PRELINKED
= 0x6ffffdf5,
739 DT_GNU_CONFLICTSZ
= 0x6ffffdf6,
740 DT_GNU_LIBLISTSZ
= 0x6ffffdf7,
741 DT_CHECKSUM
= 0x6ffffdf8,
742 DT_PLTPADSZ
= 0x6ffffdf9,
743 DT_MOVEENT
= 0x6ffffdfa,
744 DT_MOVESZ
= 0x6ffffdfb,
745 DT_FEATURE
= 0x6ffffdfc,
746 DT_POSFLAG_1
= 0x6ffffdfd,
747 DT_SYMINSZ
= 0x6ffffdfe,
748 DT_SYMINENT
= 0x6ffffdff,
749 DT_VALRNGHI
= 0x6ffffdff,
751 DT_ADDRRNGLO
= 0x6ffffe00,
752 DT_GNU_HASH
= 0x6ffffef5,
753 DT_TLSDESC_PLT
= 0x6ffffef6,
754 DT_TLSDESC_GOT
= 0x6ffffef7,
755 DT_GNU_CONFLICT
= 0x6ffffef8,
756 DT_GNU_LIBLIST
= 0x6ffffef9,
757 DT_CONFIG
= 0x6ffffefa,
758 DT_DEPAUDIT
= 0x6ffffefb,
759 DT_AUDIT
= 0x6ffffefc,
760 DT_PLTPAD
= 0x6ffffefd,
761 DT_MOVETAB
= 0x6ffffefe,
762 DT_SYMINFO
= 0x6ffffeff,
763 DT_ADDRRNGHI
= 0x6ffffeff,
765 DT_RELACOUNT
= 0x6ffffff9,
766 DT_RELCOUNT
= 0x6ffffffa,
767 DT_FLAGS_1
= 0x6ffffffb,
768 DT_VERDEF
= 0x6ffffffc,
769 DT_VERDEFNUM
= 0x6ffffffd,
770 DT_VERNEED
= 0x6ffffffe,
771 DT_VERNEEDNUM
= 0x6fffffff,
773 DT_VERSYM
= 0x6ffffff0,
775 // Specify the value of _GLOBAL_OFFSET_TABLE_.
776 DT_PPC_GOT
= 0x70000000,
778 // Specify whether various optimisations are possible.
779 DT_PPC_OPT
= 0x70000001,
781 // Specify the start of the .glink section.
782 DT_PPC64_GLINK
= 0x70000000,
784 // Specify the start and size of the .opd section.
785 DT_PPC64_OPD
= 0x70000001,
786 DT_PPC64_OPDSZ
= 0x70000002,
788 // Specify whether various optimisations are possible.
789 DT_PPC64_OPT
= 0x70000003,
791 // The index of an STT_SPARC_REGISTER symbol within the DT_SYMTAB
792 // symbol table. One dynamic entry exists for every STT_SPARC_REGISTER
793 // symbol in the symbol table.
794 DT_SPARC_REGISTER
= 0x70000001,
796 // MIPS specific dynamic array tags.
797 // 32 bit version number for runtime linker interface.
798 DT_MIPS_RLD_VERSION
= 0x70000001,
800 DT_MIPS_TIME_STAMP
= 0x70000002,
801 // Checksum of external strings and common sizes.
802 DT_MIPS_ICHECKSUM
= 0x70000003,
803 // Index of version string in string table.
804 DT_MIPS_IVERSION
= 0x70000004,
806 DT_MIPS_FLAGS
= 0x70000005,
807 // Base address of the segment.
808 DT_MIPS_BASE_ADDRESS
= 0x70000006,
810 DT_MIPS_MSYM
= 0x70000007,
811 // Address of .conflict section.
812 DT_MIPS_CONFLICT
= 0x70000008,
813 // Address of .liblist section.
814 DT_MIPS_LIBLIST
= 0x70000009,
815 // Number of local global offset table entries.
816 DT_MIPS_LOCAL_GOTNO
= 0x7000000a,
817 // Number of entries in the .conflict section.
818 DT_MIPS_CONFLICTNO
= 0x7000000b,
819 // Number of entries in the .liblist section.
820 DT_MIPS_LIBLISTNO
= 0x70000010,
821 // Number of entries in the .dynsym section.
822 DT_MIPS_SYMTABNO
= 0x70000011,
823 // Index of first external dynamic symbol not referenced locally.
824 DT_MIPS_UNREFEXTNO
= 0x70000012,
825 // Index of first dynamic symbol in global offset table.
826 DT_MIPS_GOTSYM
= 0x70000013,
827 // Number of page table entries in global offset table.
828 DT_MIPS_HIPAGENO
= 0x70000014,
829 // Address of run time loader map, used for debugging.
830 DT_MIPS_RLD_MAP
= 0x70000016,
831 // Delta C++ class definition.
832 DT_MIPS_DELTA_CLASS
= 0x70000017,
833 // Number of entries in DT_MIPS_DELTA_CLASS.
834 DT_MIPS_DELTA_CLASS_NO
= 0x70000018,
835 // Delta C++ class instances.
836 DT_MIPS_DELTA_INSTANCE
= 0x70000019,
837 // Number of entries in DT_MIPS_DELTA_INSTANCE.
838 DT_MIPS_DELTA_INSTANCE_NO
= 0x7000001a,
839 // Delta relocations.
840 DT_MIPS_DELTA_RELOC
= 0x7000001b,
841 // Number of entries in DT_MIPS_DELTA_RELOC.
842 DT_MIPS_DELTA_RELOC_NO
= 0x7000001c,
843 // Delta symbols that Delta relocations refer to.
844 DT_MIPS_DELTA_SYM
= 0x7000001d,
845 // Number of entries in DT_MIPS_DELTA_SYM.
846 DT_MIPS_DELTA_SYM_NO
= 0x7000001e,
847 // Delta symbols that hold class declarations.
848 DT_MIPS_DELTA_CLASSSYM
= 0x70000020,
849 // Number of entries in DT_MIPS_DELTA_CLASSSYM.
850 DT_MIPS_DELTA_CLASSSYM_NO
= 0x70000021,
851 // Flags indicating information about C++ flavor.
852 DT_MIPS_CXX_FLAGS
= 0x70000022,
853 // Pixie information (???).
854 DT_MIPS_PIXIE_INIT
= 0x70000023,
855 // Address of .MIPS.symlib
856 DT_MIPS_SYMBOL_LIB
= 0x70000024,
857 // The GOT index of the first PTE for a segment
858 DT_MIPS_LOCALPAGE_GOTIDX
= 0x70000025,
859 // The GOT index of the first PTE for a local symbol
860 DT_MIPS_LOCAL_GOTIDX
= 0x70000026,
861 // The GOT index of the first PTE for a hidden symbol
862 DT_MIPS_HIDDEN_GOTIDX
= 0x70000027,
863 // The GOT index of the first PTE for a protected symbol
864 DT_MIPS_PROTECTED_GOTIDX
= 0x70000028,
865 // Address of `.MIPS.options'.
866 DT_MIPS_OPTIONS
= 0x70000029,
867 // Address of `.interface'.
868 DT_MIPS_INTERFACE
= 0x7000002a,
870 DT_MIPS_DYNSTR_ALIGN
= 0x7000002b,
871 // Size of the .interface section.
872 DT_MIPS_INTERFACE_SIZE
= 0x7000002c,
873 // Size of rld_text_resolve function stored in the GOT.
874 DT_MIPS_RLD_TEXT_RESOLVE_ADDR
= 0x7000002d,
875 // Default suffix of DSO to be added by rld on dlopen() calls.
876 DT_MIPS_PERF_SUFFIX
= 0x7000002e,
877 // Size of compact relocation section (O32).
878 DT_MIPS_COMPACT_SIZE
= 0x7000002f,
879 // GP value for auxiliary GOTs.
880 DT_MIPS_GP_VALUE
= 0x70000030,
881 // Address of auxiliary .dynamic.
882 DT_MIPS_AUX_DYNAMIC
= 0x70000031,
883 // Address of the base of the PLTGOT.
884 DT_MIPS_PLTGOT
= 0x70000032,
885 // Points to the base of a writable PLT.
886 DT_MIPS_RWPLT
= 0x70000034,
887 // Relative offset of run time loader map, used for debugging.
888 DT_MIPS_RLD_MAP_REL
= 0x70000035,
890 DT_AUXILIARY
= 0x7ffffffd,
891 DT_USED
= 0x7ffffffe,
892 DT_FILTER
= 0x7fffffff
895 // Flags found in the DT_FLAGS dynamic element.
906 // Flags found in the DT_FLAGS_1 dynamic element.
914 DF_1_LOADFLTR
= 0x10,
915 DF_1_INITFIRST
= 0x20,
920 DF_1_INTERPOSE
= 0x400,
921 DF_1_NODEFLIB
= 0x800,
922 DF_1_NODUMP
= 0x1000,
923 DF_1_CONLFAT
= 0x2000,
924 DF_1_PIE
= 0x08000000
927 // Flags found in the DT_GNU_FLAGS_1 dynamic element.
930 DF_GNU_1_UNIQUE
= 0x1,
933 // Version numbers which appear in the vd_version field of a Verdef
936 const int VER_DEF_NONE
= 0;
937 const int VER_DEF_CURRENT
= 1;
939 // Version numbers which appear in the vn_version field of a Verneed
942 const int VER_NEED_NONE
= 0;
943 const int VER_NEED_CURRENT
= 1;
945 // Bit flags which appear in vd_flags of Verdef and vna_flags of
948 const int VER_FLG_BASE
= 0x1;
949 const int VER_FLG_WEAK
= 0x2;
950 const int VER_FLG_INFO
= 0x4;
952 // Special constants found in the SHT_GNU_versym entries.
954 const int VER_NDX_LOCAL
= 0;
955 const int VER_NDX_GLOBAL
= 1;
957 // A SHT_GNU_versym section holds 16-bit words. This bit is set if
958 // the symbol is hidden and can only be seen when referenced using an
959 // explicit version number. This is a GNU extension.
961 const int VERSYM_HIDDEN
= 0x8000;
963 // This is the mask for the rest of the data in a word read from a
964 // SHT_GNU_versym section.
966 const int VERSYM_VERSION
= 0x7fff;
968 // Note descriptor type codes for notes in a non-core file with an
975 // An architecture string.
979 // Note descriptor type codes for notes in a non-core file with the
984 // The minimum ABI level. This is used by the dynamic linker to
985 // describe the minimal kernel version on which a shared library may
986 // be used. Th value should be four words. Word 0 is an OS
987 // descriptor (see below). Word 1 is the major version of the ABI.
988 // Word 2 is the minor version. Word 3 is the subminor version.
990 // Hardware capabilities information. Word 0 is the number of
991 // entries. Word 1 is a bitmask of enabled entries. The rest of
992 // the descriptor is a series of entries, where each entry is a
993 // single byte followed by a nul terminated string. The byte gives
994 // the bit number to test if enabled in the bitmask.
996 // The build ID as set by the linker's --build-id option. The
997 // format of the descriptor depends on the build ID style.
999 // The version of gold used to link. Th descriptor is just a
1001 NT_GNU_GOLD_VERSION
= 4,
1002 // Program property note, as described in "Linux Extensions to the gABI".
1003 NT_GNU_PROPERTY_TYPE_0
= 5,
1004 // FDO .note.package notes as defined on https://systemd.io/ELF_PACKAGE_METADATA/
1005 FDO_PACKAGING_METADATA
= 0xcafe1a7e
1008 // The OS values which may appear in word 0 of a NT_GNU_ABI_TAG note.
1012 ELF_NOTE_OS_LINUX
= 0,
1013 ELF_NOTE_OS_GNU
= 1,
1014 ELF_NOTE_OS_SOLARIS2
= 2,
1015 ELF_NOTE_OS_FREEBSD
= 3,
1016 ELF_NOTE_OS_NETBSD
= 4,
1017 ELF_NOTE_OS_SYLLABLE
= 5
1020 // Program property types for NT_GNU_PROPERTY_TYPE_0.
1024 GNU_PROPERTY_STACK_SIZE
= 1,
1025 GNU_PROPERTY_NO_COPY_ON_PROTECTED
= 2,
1026 GNU_PROPERTY_LOPROC
= 0xc0000000,
1027 GNU_PROPERTY_X86_COMPAT_ISA_1_USED
= 0xc0000000,
1028 GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
= 0xc0000001,
1029 GNU_PROPERTY_X86_UINT32_AND_LO
= 0xc0000002,
1030 GNU_PROPERTY_X86_UINT32_AND_HI
= 0xc0007fff,
1031 GNU_PROPERTY_X86_UINT32_OR_LO
= 0xc0008000,
1032 GNU_PROPERTY_X86_UINT32_OR_HI
= 0xc000ffff,
1033 GNU_PROPERTY_X86_UINT32_OR_AND_LO
= 0xc0010000,
1034 GNU_PROPERTY_X86_UINT32_OR_AND_HI
= 0xc0017fff,
1035 GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
= GNU_PROPERTY_X86_UINT32_OR_LO
+ 0,
1036 GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ 0,
1037 GNU_PROPERTY_X86_FEATURE_1_AND
= GNU_PROPERTY_X86_UINT32_AND_LO
+ 0,
1038 GNU_PROPERTY_X86_ISA_1_NEEDED
= GNU_PROPERTY_X86_UINT32_OR_LO
+ 2,
1039 GNU_PROPERTY_X86_FEATURE_2_NEEDED
= GNU_PROPERTY_X86_UINT32_OR_LO
+ 1,
1040 GNU_PROPERTY_X86_ISA_1_USED
= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ 2,
1041 GNU_PROPERTY_X86_FEATURE_2_USED
= GNU_PROPERTY_X86_UINT32_OR_AND_LO
+ 1,
1042 GNU_PROPERTY_HIPROC
= 0xdfffffff,
1043 GNU_PROPERTY_LOUSER
= 0xe0000000,
1044 GNU_PROPERTY_HIUSER
= 0xffffffff
1047 } // End namespace elfcpp.
1049 // Include internal details after defining the types.
1050 #include "elfcpp_internal.h"
1055 // The offset of the ELF file header in the ELF file.
1057 const int file_header_offset
= 0;
1059 // ELF structure sizes.
1064 // Size of ELF file header.
1065 static const int ehdr_size
= sizeof(internal::Ehdr_data
<size
>);
1066 // Size of ELF segment header.
1067 static const int phdr_size
= sizeof(internal::Phdr_data
<size
>);
1068 // Size of ELF section header.
1069 static const int shdr_size
= sizeof(internal::Shdr_data
<size
>);
1070 // Size of ELF compression header.
1071 static const int chdr_size
= sizeof(internal::Chdr_data
<size
>);
1072 // Size of ELF symbol table entry.
1073 static const int sym_size
= sizeof(internal::Sym_data
<size
>);
1074 // Sizes of ELF reloc entries.
1075 static const int rel_size
= sizeof(internal::Rel_data
<size
>);
1076 static const int rela_size
= sizeof(internal::Rela_data
<size
>);
1077 // Size of ELF dynamic entry.
1078 static const int dyn_size
= sizeof(internal::Dyn_data
<size
>);
1079 // Size of ELF version structures.
1080 static const int verdef_size
= sizeof(internal::Verdef_data
);
1081 static const int verdaux_size
= sizeof(internal::Verdaux_data
);
1082 static const int verneed_size
= sizeof(internal::Verneed_data
);
1083 static const int vernaux_size
= sizeof(internal::Vernaux_data
);
1086 // Accessor class for the ELF file header.
1088 template<int size
, bool big_endian
>
1092 Ehdr(const unsigned char* p
)
1093 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(p
))
1096 template<typename File
>
1097 Ehdr(File
* file
, typename
File::Location loc
)
1098 : p_(reinterpret_cast<const internal::Ehdr_data
<size
>*>(
1099 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1102 const unsigned char*
1104 { return this->p_
->e_ident
; }
1107 get_ei_osabi() const
1108 { return this->p_
->e_ident
[EI_OSABI
]; }
1111 get_ei_abiversion() const
1112 { return this->p_
->e_ident
[EI_ABIVERSION
]; }
1116 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_type
); }
1119 get_e_machine() const
1120 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_machine
); }
1123 get_e_version() const
1124 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_version
); }
1126 typename Elf_types
<size
>::Elf_Addr
1128 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_entry
); }
1130 typename Elf_types
<size
>::Elf_Off
1132 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_phoff
); }
1134 typename Elf_types
<size
>::Elf_Off
1136 { return Convert
<size
, big_endian
>::convert_host(this->p_
->e_shoff
); }
1140 { return Convert
<32, big_endian
>::convert_host(this->p_
->e_flags
); }
1143 get_e_ehsize() const
1144 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_ehsize
); }
1147 get_e_phentsize() const
1148 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phentsize
); }
1152 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_phnum
); }
1155 get_e_shentsize() const
1156 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shentsize
); }
1160 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shnum
); }
1163 get_e_shstrndx() const
1164 { return Convert
<16, big_endian
>::convert_host(this->p_
->e_shstrndx
); }
1167 const internal::Ehdr_data
<size
>* p_
;
1170 // Write class for the ELF file header.
1172 template<int size
, bool big_endian
>
1176 Ehdr_write(unsigned char* p
)
1177 : p_(reinterpret_cast<internal::Ehdr_data
<size
>*>(p
))
1181 put_e_ident(const unsigned char v
[EI_NIDENT
]) const
1182 { memcpy(this->p_
->e_ident
, v
, EI_NIDENT
); }
1185 put_e_type(Elf_Half v
)
1186 { this->p_
->e_type
= Convert
<16, big_endian
>::convert_host(v
); }
1189 put_e_machine(Elf_Half v
)
1190 { this->p_
->e_machine
= Convert
<16, big_endian
>::convert_host(v
); }
1193 put_e_version(Elf_Word v
)
1194 { this->p_
->e_version
= Convert
<32, big_endian
>::convert_host(v
); }
1197 put_e_entry(typename Elf_types
<size
>::Elf_Addr v
)
1198 { this->p_
->e_entry
= Convert
<size
, big_endian
>::convert_host(v
); }
1201 put_e_phoff(typename Elf_types
<size
>::Elf_Off v
)
1202 { this->p_
->e_phoff
= Convert
<size
, big_endian
>::convert_host(v
); }
1205 put_e_shoff(typename Elf_types
<size
>::Elf_Off v
)
1206 { this->p_
->e_shoff
= Convert
<size
, big_endian
>::convert_host(v
); }
1209 put_e_flags(Elf_Word v
)
1210 { this->p_
->e_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1213 put_e_ehsize(Elf_Half v
)
1214 { this->p_
->e_ehsize
= Convert
<16, big_endian
>::convert_host(v
); }
1217 put_e_phentsize(Elf_Half v
)
1218 { this->p_
->e_phentsize
= Convert
<16, big_endian
>::convert_host(v
); }
1221 put_e_phnum(Elf_Half v
)
1222 { this->p_
->e_phnum
= Convert
<16, big_endian
>::convert_host(v
); }
1225 put_e_shentsize(Elf_Half v
)
1226 { this->p_
->e_shentsize
= Convert
<16, big_endian
>::convert_host(v
); }
1229 put_e_shnum(Elf_Half v
)
1230 { this->p_
->e_shnum
= Convert
<16, big_endian
>::convert_host(v
); }
1233 put_e_shstrndx(Elf_Half v
)
1234 { this->p_
->e_shstrndx
= Convert
<16, big_endian
>::convert_host(v
); }
1237 internal::Ehdr_data
<size
>* p_
;
1240 // Accessor class for an ELF section header.
1242 template<int size
, bool big_endian
>
1246 Shdr(const unsigned char* p
)
1247 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(p
))
1250 template<typename File
>
1251 Shdr(File
* file
, typename
File::Location loc
)
1252 : p_(reinterpret_cast<const internal::Shdr_data
<size
>*>(
1253 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1258 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_name
); }
1262 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_type
); }
1264 typename Elf_types
<size
>::Elf_WXword
1265 get_sh_flags() const
1266 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_flags
); }
1268 typename Elf_types
<size
>::Elf_Addr
1270 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addr
); }
1272 typename Elf_types
<size
>::Elf_Off
1273 get_sh_offset() const
1274 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_offset
); }
1276 typename Elf_types
<size
>::Elf_WXword
1278 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_size
); }
1282 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_link
); }
1286 { return Convert
<32, big_endian
>::convert_host(this->p_
->sh_info
); }
1288 typename Elf_types
<size
>::Elf_WXword
1289 get_sh_addralign() const
1291 Convert
<size
, big_endian
>::convert_host(this->p_
->sh_addralign
); }
1293 typename Elf_types
<size
>::Elf_WXword
1294 get_sh_entsize() const
1295 { return Convert
<size
, big_endian
>::convert_host(this->p_
->sh_entsize
); }
1298 const internal::Shdr_data
<size
>* p_
;
1301 // Write class for an ELF section header.
1303 template<int size
, bool big_endian
>
1307 Shdr_write(unsigned char* p
)
1308 : p_(reinterpret_cast<internal::Shdr_data
<size
>*>(p
))
1312 put_sh_name(Elf_Word v
)
1313 { this->p_
->sh_name
= Convert
<32, big_endian
>::convert_host(v
); }
1316 put_sh_type(Elf_Word v
)
1317 { this->p_
->sh_type
= Convert
<32, big_endian
>::convert_host(v
); }
1320 put_sh_flags(typename Elf_types
<size
>::Elf_WXword v
)
1321 { this->p_
->sh_flags
= Convert
<size
, big_endian
>::convert_host(v
); }
1324 put_sh_addr(typename Elf_types
<size
>::Elf_Addr v
)
1325 { this->p_
->sh_addr
= Convert
<size
, big_endian
>::convert_host(v
); }
1328 put_sh_offset(typename Elf_types
<size
>::Elf_Off v
)
1329 { this->p_
->sh_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1332 put_sh_size(typename Elf_types
<size
>::Elf_WXword v
)
1333 { this->p_
->sh_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1336 put_sh_link(Elf_Word v
)
1337 { this->p_
->sh_link
= Convert
<32, big_endian
>::convert_host(v
); }
1340 put_sh_info(Elf_Word v
)
1341 { this->p_
->sh_info
= Convert
<32, big_endian
>::convert_host(v
); }
1344 put_sh_addralign(typename Elf_types
<size
>::Elf_WXword v
)
1345 { this->p_
->sh_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
1348 put_sh_entsize(typename Elf_types
<size
>::Elf_WXword v
)
1349 { this->p_
->sh_entsize
= Convert
<size
, big_endian
>::convert_host(v
); }
1352 internal::Shdr_data
<size
>* p_
;
1355 // Accessor class for an ELF compression header.
1357 template<int size
, bool big_endian
>
1361 Chdr(const unsigned char* p
)
1362 : p_(reinterpret_cast<const internal::Chdr_data
<size
>*>(p
))
1365 template<typename File
>
1366 Chdr(File
* file
, typename
File::Location loc
)
1367 : p_(reinterpret_cast<const internal::Chdr_data
<size
>*>(
1368 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1373 { return Convert
<size
, big_endian
>::convert_host(this->p_
->ch_type
); }
1375 typename Elf_types
<size
>::Elf_WXword
1377 { return Convert
<size
, big_endian
>::convert_host(this->p_
->ch_size
); }
1379 typename Elf_types
<size
>::Elf_WXword
1380 get_ch_addralign() const
1382 Convert
<size
, big_endian
>::convert_host(this->p_
->ch_addralign
); }
1385 const internal::Chdr_data
<size
>* p_
;
1388 // Write class for an ELF compression header.
1390 template<int size
, bool big_endian
>
1394 Chdr_write(unsigned char* p
)
1395 : p_(reinterpret_cast<internal::Chdr_data
<size
>*>(p
))
1399 put_ch_type(typename Elf_types
<size
>::Elf_WXword v
)
1400 { this->p_
->ch_type
= Convert
<size
, big_endian
>::convert_host(v
); }
1403 put_ch_size(typename Elf_types
<size
>::Elf_WXword v
)
1404 { this->p_
->ch_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1407 put_ch_addralign(typename Elf_types
<size
>::Elf_WXword v
)
1408 { this->p_
->ch_addralign
= Convert
<size
, big_endian
>::convert_host(v
); }
1411 put_ch_reserved(Elf_Word
);
1414 internal::Chdr_data
<size
>* p_
;
1419 elfcpp::Chdr_write
<64, true>::put_ch_reserved(Elf_Word v
)
1421 this->p_
->ch_reserved
= v
;
1426 elfcpp::Chdr_write
<64, false>::put_ch_reserved(Elf_Word v
)
1428 this->p_
->ch_reserved
= v
;
1431 // Accessor class for an ELF segment header.
1433 template<int size
, bool big_endian
>
1437 Phdr(const unsigned char* p
)
1438 : p_(reinterpret_cast<const internal::Phdr_data
<size
>*>(p
))
1441 template<typename File
>
1442 Phdr(File
* file
, typename
File::Location loc
)
1443 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(
1444 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1449 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_type
); }
1451 typename Elf_types
<size
>::Elf_Off
1452 get_p_offset() const
1453 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_offset
); }
1455 typename Elf_types
<size
>::Elf_Addr
1457 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_vaddr
); }
1459 typename Elf_types
<size
>::Elf_Addr
1461 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_paddr
); }
1463 typename Elf_types
<size
>::Elf_WXword
1464 get_p_filesz() const
1465 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_filesz
); }
1467 typename Elf_types
<size
>::Elf_WXword
1469 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_memsz
); }
1473 { return Convert
<32, big_endian
>::convert_host(this->p_
->p_flags
); }
1475 typename Elf_types
<size
>::Elf_WXword
1477 { return Convert
<size
, big_endian
>::convert_host(this->p_
->p_align
); }
1480 const internal::Phdr_data
<size
>* p_
;
1483 // Write class for an ELF segment header.
1485 template<int size
, bool big_endian
>
1489 Phdr_write(unsigned char* p
)
1490 : p_(reinterpret_cast<internal::Phdr_data
<size
>*>(p
))
1494 put_p_type(Elf_Word v
)
1495 { this->p_
->p_type
= Convert
<32, big_endian
>::convert_host(v
); }
1498 put_p_offset(typename Elf_types
<size
>::Elf_Off v
)
1499 { this->p_
->p_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1502 put_p_vaddr(typename Elf_types
<size
>::Elf_Addr v
)
1503 { this->p_
->p_vaddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1506 put_p_paddr(typename Elf_types
<size
>::Elf_Addr v
)
1507 { this->p_
->p_paddr
= Convert
<size
, big_endian
>::convert_host(v
); }
1510 put_p_filesz(typename Elf_types
<size
>::Elf_WXword v
)
1511 { this->p_
->p_filesz
= Convert
<size
, big_endian
>::convert_host(v
); }
1514 put_p_memsz(typename Elf_types
<size
>::Elf_WXword v
)
1515 { this->p_
->p_memsz
= Convert
<size
, big_endian
>::convert_host(v
); }
1518 put_p_flags(Elf_Word v
)
1519 { this->p_
->p_flags
= Convert
<32, big_endian
>::convert_host(v
); }
1522 put_p_align(typename Elf_types
<size
>::Elf_WXword v
)
1523 { this->p_
->p_align
= Convert
<size
, big_endian
>::convert_host(v
); }
1526 internal::Phdr_data
<size
>* p_
;
1529 // Accessor class for an ELF symbol table entry.
1531 template<int size
, bool big_endian
>
1535 Sym(const unsigned char* p
)
1536 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(p
))
1539 template<typename File
>
1540 Sym(File
* file
, typename
File::Location loc
)
1541 : p_(reinterpret_cast<const internal::Sym_data
<size
>*>(
1542 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1547 { return Convert
<32, big_endian
>::convert_host(this->p_
->st_name
); }
1549 typename Elf_types
<size
>::Elf_Addr
1550 get_st_value() const
1551 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_value
); }
1553 typename Elf_types
<size
>::Elf_WXword
1555 { return Convert
<size
, big_endian
>::convert_host(this->p_
->st_size
); }
1559 { return this->p_
->st_info
; }
1563 { return elf_st_bind(this->get_st_info()); }
1567 { return elf_st_type(this->get_st_info()); }
1570 get_st_other() const
1571 { return this->p_
->st_other
; }
1574 get_st_visibility() const
1575 { return elf_st_visibility(this->get_st_other()); }
1578 get_st_nonvis() const
1579 { return elf_st_nonvis(this->get_st_other()); }
1582 get_st_shndx() const
1583 { return Convert
<16, big_endian
>::convert_host(this->p_
->st_shndx
); }
1586 const internal::Sym_data
<size
>* p_
;
1589 // Writer class for an ELF symbol table entry.
1591 template<int size
, bool big_endian
>
1595 Sym_write(unsigned char* p
)
1596 : p_(reinterpret_cast<internal::Sym_data
<size
>*>(p
))
1600 put_st_name(Elf_Word v
)
1601 { this->p_
->st_name
= Convert
<32, big_endian
>::convert_host(v
); }
1604 put_st_value(typename Elf_types
<size
>::Elf_Addr v
)
1605 { this->p_
->st_value
= Convert
<size
, big_endian
>::convert_host(v
); }
1608 put_st_size(typename Elf_types
<size
>::Elf_WXword v
)
1609 { this->p_
->st_size
= Convert
<size
, big_endian
>::convert_host(v
); }
1612 put_st_info(unsigned char v
)
1613 { this->p_
->st_info
= v
; }
1616 put_st_info(STB bind
, STT type
)
1617 { this->p_
->st_info
= elf_st_info(bind
, type
); }
1620 put_st_other(unsigned char v
)
1621 { this->p_
->st_other
= v
; }
1624 put_st_other(STV vis
, unsigned char nonvis
)
1625 { this->p_
->st_other
= elf_st_other(vis
, nonvis
); }
1628 put_st_shndx(Elf_Half v
)
1629 { this->p_
->st_shndx
= Convert
<16, big_endian
>::convert_host(v
); }
1631 Sym
<size
, big_endian
>
1633 { return Sym
<size
, big_endian
>(reinterpret_cast<unsigned char*>(this->p_
)); }
1636 internal::Sym_data
<size
>* p_
;
1639 // Accessor classes for an ELF REL relocation entry.
1641 template<int size
, bool big_endian
>
1645 Rel(const unsigned char* p
)
1646 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(p
))
1649 template<typename File
>
1650 Rel(File
* file
, typename
File::Location loc
)
1651 : p_(reinterpret_cast<const internal::Rel_data
<size
>*>(
1652 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1655 typename Elf_types
<size
>::Elf_Addr
1656 get_r_offset() const
1657 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1659 typename Elf_types
<size
>::Elf_WXword
1661 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1664 const internal::Rel_data
<size
>* p_
;
1667 // Writer class for an ELF Rel relocation.
1669 template<int size
, bool big_endian
>
1673 Rel_write(unsigned char* p
)
1674 : p_(reinterpret_cast<internal::Rel_data
<size
>*>(p
))
1678 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1679 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1682 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1683 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1686 internal::Rel_data
<size
>* p_
;
1689 // Accessor class for an ELF Rela relocation.
1691 template<int size
, bool big_endian
>
1695 Rela(const unsigned char* p
)
1696 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(p
))
1699 template<typename File
>
1700 Rela(File
* file
, typename
File::Location loc
)
1701 : p_(reinterpret_cast<const internal::Rela_data
<size
>*>(
1702 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1705 typename Elf_types
<size
>::Elf_Addr
1706 get_r_offset() const
1707 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_offset
); }
1709 typename Elf_types
<size
>::Elf_WXword
1711 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_info
); }
1713 typename Elf_types
<size
>::Elf_Swxword
1714 get_r_addend() const
1715 { return Convert
<size
, big_endian
>::convert_host(this->p_
->r_addend
); }
1718 const internal::Rela_data
<size
>* p_
;
1721 // Writer class for an ELF Rela relocation.
1723 template<int size
, bool big_endian
>
1727 Rela_write(unsigned char* p
)
1728 : p_(reinterpret_cast<internal::Rela_data
<size
>*>(p
))
1732 put_r_offset(typename Elf_types
<size
>::Elf_Addr v
)
1733 { this->p_
->r_offset
= Convert
<size
, big_endian
>::convert_host(v
); }
1736 put_r_info(typename Elf_types
<size
>::Elf_WXword v
)
1737 { this->p_
->r_info
= Convert
<size
, big_endian
>::convert_host(v
); }
1740 put_r_addend(typename Elf_types
<size
>::Elf_Swxword v
)
1741 { this->p_
->r_addend
= Convert
<size
, big_endian
>::convert_host(v
); }
1744 internal::Rela_data
<size
>* p_
;
1747 // MIPS-64 has a non-standard relocation layout.
1749 template<bool big_endian
>
1753 Mips64_rel(const unsigned char* p
)
1754 : p_(reinterpret_cast<const internal::Mips64_rel_data
*>(p
))
1757 template<typename File
>
1758 Mips64_rel(File
* file
, typename
File::Location loc
)
1759 : p_(reinterpret_cast<const internal::Mips64_rel_data
*>(
1760 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1763 typename Elf_types
<64>::Elf_Addr
1764 get_r_offset() const
1765 { return Convert
<64, big_endian
>::convert_host(this->p_
->r_offset
); }
1769 { return Convert
<32, big_endian
>::convert_host(this->p_
->r_sym
); }
1773 { return this->p_
->r_ssym
; }
1777 { return this->p_
->r_type
; }
1781 { return this->p_
->r_type2
; }
1785 { return this->p_
->r_type3
; }
1788 const internal::Mips64_rel_data
* p_
;
1791 template<bool big_endian
>
1792 class Mips64_rel_write
1795 Mips64_rel_write(unsigned char* p
)
1796 : p_(reinterpret_cast<internal::Mips64_rel_data
*>(p
))
1800 put_r_offset(typename Elf_types
<64>::Elf_Addr v
)
1801 { this->p_
->r_offset
= Convert
<64, big_endian
>::convert_host(v
); }
1804 put_r_sym(Elf_Word v
)
1805 { this->p_
->r_sym
= Convert
<32, big_endian
>::convert_host(v
); }
1808 put_r_ssym(unsigned char v
)
1809 { this->p_
->r_ssym
= v
; }
1812 put_r_type(unsigned char v
)
1813 { this->p_
->r_type
= v
; }
1816 put_r_type2(unsigned char v
)
1817 { this->p_
->r_type2
= v
; }
1820 put_r_type3(unsigned char v
)
1821 { this->p_
->r_type3
= v
; }
1824 internal::Mips64_rel_data
* p_
;
1827 template<bool big_endian
>
1831 Mips64_rela(const unsigned char* p
)
1832 : p_(reinterpret_cast<const internal::Mips64_rela_data
*>(p
))
1835 template<typename File
>
1836 Mips64_rela(File
* file
, typename
File::Location loc
)
1837 : p_(reinterpret_cast<const internal::Mips64_rela_data
*>(
1838 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1841 typename Elf_types
<64>::Elf_Addr
1842 get_r_offset() const
1843 { return Convert
<64, big_endian
>::convert_host(this->p_
->r_offset
); }
1847 { return Convert
<32, big_endian
>::convert_host(this->p_
->r_sym
); }
1851 { return this->p_
->r_ssym
; }
1855 { return this->p_
->r_type
; }
1859 { return this->p_
->r_type2
; }
1863 { return this->p_
->r_type3
; }
1865 typename Elf_types
<64>::Elf_Swxword
1866 get_r_addend() const
1867 { return Convert
<64, big_endian
>::convert_host(this->p_
->r_addend
); }
1870 const internal::Mips64_rela_data
* p_
;
1873 template<bool big_endian
>
1874 class Mips64_rela_write
1877 Mips64_rela_write(unsigned char* p
)
1878 : p_(reinterpret_cast<internal::Mips64_rela_data
*>(p
))
1882 put_r_offset(typename Elf_types
<64>::Elf_Addr v
)
1883 { this->p_
->r_offset
= Convert
<64, big_endian
>::convert_host(v
); }
1886 put_r_sym(Elf_Word v
)
1887 { this->p_
->r_sym
= Convert
<32, big_endian
>::convert_host(v
); }
1890 put_r_ssym(unsigned char v
)
1891 { this->p_
->r_ssym
= v
; }
1894 put_r_type(unsigned char v
)
1895 { this->p_
->r_type
= v
; }
1898 put_r_type2(unsigned char v
)
1899 { this->p_
->r_type2
= v
; }
1902 put_r_type3(unsigned char v
)
1903 { this->p_
->r_type3
= v
; }
1906 put_r_addend(typename Elf_types
<64>::Elf_Swxword v
)
1907 { this->p_
->r_addend
= Convert
<64, big_endian
>::convert_host(v
); }
1910 internal::Mips64_rela_data
* p_
;
1913 // Accessor classes for entries in the ELF SHT_DYNAMIC section aka
1914 // PT_DYNAMIC segment.
1916 template<int size
, bool big_endian
>
1920 Dyn(const unsigned char* p
)
1921 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(p
))
1924 template<typename File
>
1925 Dyn(File
* file
, typename
File::Location loc
)
1926 : p_(reinterpret_cast<const internal::Dyn_data
<size
>*>(
1927 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1930 typename Elf_types
<size
>::Elf_Swxword
1932 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_tag
); }
1934 typename Elf_types
<size
>::Elf_WXword
1936 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1938 typename Elf_types
<size
>::Elf_Addr
1940 { return Convert
<size
, big_endian
>::convert_host(this->p_
->d_val
); }
1943 const internal::Dyn_data
<size
>* p_
;
1946 // Write class for an entry in the SHT_DYNAMIC section.
1948 template<int size
, bool big_endian
>
1952 Dyn_write(unsigned char* p
)
1953 : p_(reinterpret_cast<internal::Dyn_data
<size
>*>(p
))
1957 put_d_tag(typename Elf_types
<size
>::Elf_Swxword v
)
1958 { this->p_
->d_tag
= Convert
<size
, big_endian
>::convert_host(v
); }
1961 put_d_val(typename Elf_types
<size
>::Elf_WXword v
)
1962 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1965 put_d_ptr(typename Elf_types
<size
>::Elf_Addr v
)
1966 { this->p_
->d_val
= Convert
<size
, big_endian
>::convert_host(v
); }
1969 internal::Dyn_data
<size
>* p_
;
1972 // Accessor classes for entries in the ELF SHT_GNU_verdef section.
1974 template<int size
, bool big_endian
>
1978 Verdef(const unsigned char* p
)
1979 : p_(reinterpret_cast<const internal::Verdef_data
*>(p
))
1982 template<typename File
>
1983 Verdef(File
* file
, typename
File::Location loc
)
1984 : p_(reinterpret_cast<const internal::Verdef_data
*>(
1985 file
->view(loc
.file_offset
, loc
.data_size
).data()))
1989 get_vd_version() const
1990 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_version
); }
1993 get_vd_flags() const
1994 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_flags
); }
1998 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_ndx
); }
2002 { return Convert
<16, big_endian
>::convert_host(this->p_
->vd_cnt
); }
2006 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_hash
); }
2010 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_aux
); }
2014 { return Convert
<32, big_endian
>::convert_host(this->p_
->vd_next
); }
2017 const internal::Verdef_data
* p_
;
2020 template<int size
, bool big_endian
>
2024 Verdef_write(unsigned char* p
)
2025 : p_(reinterpret_cast<internal::Verdef_data
*>(p
))
2029 set_vd_version(Elf_Half v
)
2030 { this->p_
->vd_version
= Convert
<16, big_endian
>::convert_host(v
); }
2033 set_vd_flags(Elf_Half v
)
2034 { this->p_
->vd_flags
= Convert
<16, big_endian
>::convert_host(v
); }
2037 set_vd_ndx(Elf_Half v
)
2038 { this->p_
->vd_ndx
= Convert
<16, big_endian
>::convert_host(v
); }
2041 set_vd_cnt(Elf_Half v
)
2042 { this->p_
->vd_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
2045 set_vd_hash(Elf_Word v
)
2046 { this->p_
->vd_hash
= Convert
<32, big_endian
>::convert_host(v
); }
2049 set_vd_aux(Elf_Word v
)
2050 { this->p_
->vd_aux
= Convert
<32, big_endian
>::convert_host(v
); }
2053 set_vd_next(Elf_Word v
)
2054 { this->p_
->vd_next
= Convert
<32, big_endian
>::convert_host(v
); }
2057 internal::Verdef_data
* p_
;
2060 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verdef
2063 template<int size
, bool big_endian
>
2067 Verdaux(const unsigned char* p
)
2068 : p_(reinterpret_cast<const internal::Verdaux_data
*>(p
))
2071 template<typename File
>
2072 Verdaux(File
* file
, typename
File::Location loc
)
2073 : p_(reinterpret_cast<const internal::Verdaux_data
*>(
2074 file
->view(loc
.file_offset
, loc
.data_size
).data()))
2078 get_vda_name() const
2079 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_name
); }
2082 get_vda_next() const
2083 { return Convert
<32, big_endian
>::convert_host(this->p_
->vda_next
); }
2086 const internal::Verdaux_data
* p_
;
2089 template<int size
, bool big_endian
>
2093 Verdaux_write(unsigned char* p
)
2094 : p_(reinterpret_cast<internal::Verdaux_data
*>(p
))
2098 set_vda_name(Elf_Word v
)
2099 { this->p_
->vda_name
= Convert
<32, big_endian
>::convert_host(v
); }
2102 set_vda_next(Elf_Word v
)
2103 { this->p_
->vda_next
= Convert
<32, big_endian
>::convert_host(v
); }
2106 internal::Verdaux_data
* p_
;
2109 // Accessor classes for entries in the ELF SHT_GNU_verneed section.
2111 template<int size
, bool big_endian
>
2115 Verneed(const unsigned char* p
)
2116 : p_(reinterpret_cast<const internal::Verneed_data
*>(p
))
2119 template<typename File
>
2120 Verneed(File
* file
, typename
File::Location loc
)
2121 : p_(reinterpret_cast<const internal::Verneed_data
*>(
2122 file
->view(loc
.file_offset
, loc
.data_size
).data()))
2126 get_vn_version() const
2127 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_version
); }
2131 { return Convert
<16, big_endian
>::convert_host(this->p_
->vn_cnt
); }
2135 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_file
); }
2139 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_aux
); }
2143 { return Convert
<32, big_endian
>::convert_host(this->p_
->vn_next
); }
2146 const internal::Verneed_data
* p_
;
2149 template<int size
, bool big_endian
>
2153 Verneed_write(unsigned char* p
)
2154 : p_(reinterpret_cast<internal::Verneed_data
*>(p
))
2158 set_vn_version(Elf_Half v
)
2159 { this->p_
->vn_version
= Convert
<16, big_endian
>::convert_host(v
); }
2162 set_vn_cnt(Elf_Half v
)
2163 { this->p_
->vn_cnt
= Convert
<16, big_endian
>::convert_host(v
); }
2166 set_vn_file(Elf_Word v
)
2167 { this->p_
->vn_file
= Convert
<32, big_endian
>::convert_host(v
); }
2170 set_vn_aux(Elf_Word v
)
2171 { this->p_
->vn_aux
= Convert
<32, big_endian
>::convert_host(v
); }
2174 set_vn_next(Elf_Word v
)
2175 { this->p_
->vn_next
= Convert
<32, big_endian
>::convert_host(v
); }
2178 internal::Verneed_data
* p_
;
2181 // Accessor classes for auxiliary entries in the ELF SHT_GNU_verneed
2184 template<int size
, bool big_endian
>
2188 Vernaux(const unsigned char* p
)
2189 : p_(reinterpret_cast<const internal::Vernaux_data
*>(p
))
2192 template<typename File
>
2193 Vernaux(File
* file
, typename
File::Location loc
)
2194 : p_(reinterpret_cast<const internal::Vernaux_data
*>(
2195 file
->view(loc
.file_offset
, loc
.data_size
).data()))
2199 get_vna_hash() const
2200 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_hash
); }
2203 get_vna_flags() const
2204 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_flags
); }
2207 get_vna_other() const
2208 { return Convert
<16, big_endian
>::convert_host(this->p_
->vna_other
); }
2211 get_vna_name() const
2212 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_name
); }
2215 get_vna_next() const
2216 { return Convert
<32, big_endian
>::convert_host(this->p_
->vna_next
); }
2219 const internal::Vernaux_data
* p_
;
2222 template<int size
, bool big_endian
>
2226 Vernaux_write(unsigned char* p
)
2227 : p_(reinterpret_cast<internal::Vernaux_data
*>(p
))
2231 set_vna_hash(Elf_Word v
)
2232 { this->p_
->vna_hash
= Convert
<32, big_endian
>::convert_host(v
); }
2235 set_vna_flags(Elf_Half v
)
2236 { this->p_
->vna_flags
= Convert
<16, big_endian
>::convert_host(v
); }
2239 set_vna_other(Elf_Half v
)
2240 { this->p_
->vna_other
= Convert
<16, big_endian
>::convert_host(v
); }
2243 set_vna_name(Elf_Word v
)
2244 { this->p_
->vna_name
= Convert
<32, big_endian
>::convert_host(v
); }
2247 set_vna_next(Elf_Word v
)
2248 { this->p_
->vna_next
= Convert
<32, big_endian
>::convert_host(v
); }
2251 internal::Vernaux_data
* p_
;
2254 } // End namespace elfcpp.
2256 #endif // !defined(ELFPCP_H)