1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 #include "elf/common.h"
28 #include "elf/internal.h"
30 #include "Data_window.h"
35 template <class ITEM
> class Vector
;
36 template <typename Key_t
, typename Value_t
> class Map
;
38 #define GELF_R_SYM(info) ((info)>>32)
39 #define GELF_ST_TYPE(info) ((info) & 0xf)
40 #define GELF_ST_BIND(info) ((info) >> 4)
41 #define GELF_R_TYPE(info) ((((uint64_t)(info))<<56)>>56)
43 #define SHF_SUNW_ABSENT 0x00200000 /* section data not present */
46 #define ANC_SUNW_NULL 0
47 #define ANC_SUNW_CHECKSUM 1 /* elf checksum */
48 #define ANC_SUNW_MEMBER 2 /* name of ancillary group object */
49 #define ANC_SUNW_NUM 3
52 typedef struct S_Elf64_Dyn Elf64_Dyn
;
53 typedef struct S_Elf64_Ancillary Elf64_Ancillary
;
60 uint64_t d_off
; // offset into section
61 uint64_t d_align
; // alignment in section
64 class Elf
: public DbeMessages
, public Data_window
70 ELF_ERR_CANT_OPEN_FILE
,
73 ELF_ERR_BAD_ELF_FORMAT
,
80 static void elf_init ();
81 static unsigned elf_version (unsigned ver
);
82 static Elf
*elf_begin (char *_fname
, Elf_status
*stp
= NULL
);
84 unsigned int elf_get_sec_num (const char *sec_name
);
85 char *get_sec_name (unsigned int sec
);
86 Elf_Internal_Ehdr
*elf_getehdr ();
87 Elf_Internal_Phdr
*get_phdr (unsigned int ndx
);
88 Elf_Internal_Shdr
*get_shdr (unsigned int ndx
);
89 Elf64_Dyn
*elf_getdyn (Elf_Internal_Phdr
*phdr
, unsigned int ndx
, Elf64_Dyn
*pdyn
);
90 Elf_Data
*elf_getdata (unsigned int sec
);
91 int64_t elf_checksum ();
92 uint64_t get_baseAddr();
93 char *elf_strptr (unsigned int sec
, uint64_t off
);
94 Elf_Internal_Sym
*elf_getsym (Elf_Data
*edta
, unsigned int ndx
, Elf_Internal_Sym
*dst
);
95 Elf_Internal_Rela
*elf_getrel (Elf_Data
*edta
, unsigned int ndx
, Elf_Internal_Rela
*dst
);
96 Elf_Internal_Rela
*elf_getrela (Elf_Data
*edta
, unsigned int ndx
, Elf_Internal_Rela
*dst
);
97 Elf64_Ancillary
*elf_getancillary (Elf_Data
*edta
, unsigned int ndx
, Elf64_Ancillary
*dst
);
98 Elf
*find_ancillary_files (char *lo_name
); // read the .gnu_debuglink and .SUNW_ancillary seections
99 const char *get_funcname_in_plt (uint64_t pc
);
100 char *get_location ();
102 void dump_elf_sec ();
104 static inline int64_t
105 normalize_checksum (int64_t chk
)
107 return (chk
== 0xffffffff || chk
== -1) ? 0 : chk
;
113 return elf_datatype
== ELFDATA2LSB
;
129 Vector
<Elf
*> *ancillary_files
;
132 Map
<const char*, Symbol
*> *elfSymbols
;
133 unsigned int gnuLink
, analyzerInfo
, SUNW_ldynsym
, stab
, stabStr
, symtab
, dynsym
;
134 unsigned int stabIndex
, stabIndexStr
, stabExcl
, stabExclStr
, info
, plt
;
138 Elf
*get_related_file (const char *lo_name
, const char *nm
);
139 void get_bfd_symbols();
142 Elf_Internal_Ehdr
*ehdrp
;
145 static int bfd_status
;
150 asymbol
**bfd_dynsym
;
151 asymbol
*bfd_synthsym
;
152 Vector
<asymbol
*> *synthsym
;
166 static ElfReloc
*get_elf_reloc (Elf
*elf
, char *sec_name
, ElfReloc
*rlc
);
167 ElfReloc (Elf
*_elf
);
169 long long get_reloc_addr (long long offset
);
171 void dump_rela_debug_sec (int sec
);
175 Vector
<Sreloc
*> *reloc
;