1 /* ELF support for BFD.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002,
3 2003 Free Software Foundation, Inc.
5 Written by Fred Fish @ Cygnus Support, from information published
6 in "UNIX System V Release 4, Programmers Guide: ANSI C and
7 Programming Support Tools".
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
26 /* This file is part of ELF support for BFD, and contains the portions
27 that describe how ELF is represented internally in the BFD library.
28 I.E. it describes the in-memory representation of ELF. It requires
29 the elf-common.h file which contains the portions that are common to
30 both the internal and external representations. */
33 /* NOTE that these structures are not kept in the same order as they appear
34 in the object file. In some cases they've been reordered for more optimal
35 packing under various circumstances. */
37 #ifndef _ELF_INTERNAL_H
38 #define _ELF_INTERNAL_H
42 #define EI_NIDENT 16 /* Size of e_ident[] */
44 typedef struct elf_internal_ehdr
{
45 unsigned char e_ident
[EI_NIDENT
]; /* ELF "magic number" */
46 bfd_vma e_entry
; /* Entry point virtual address */
47 bfd_size_type e_phoff
; /* Program header table file offset */
48 bfd_size_type e_shoff
; /* Section header table file offset */
49 unsigned long e_version
; /* Identifies object file version */
50 unsigned long e_flags
; /* Processor-specific flags */
51 unsigned short e_type
; /* Identifies object file type */
52 unsigned short e_machine
; /* Specifies required architecture */
53 unsigned int e_ehsize
; /* ELF header size in bytes */
54 unsigned int e_phentsize
; /* Program header table entry size */
55 unsigned int e_phnum
; /* Program header table entry count */
56 unsigned int e_shentsize
; /* Section header table entry size */
57 unsigned int e_shnum
; /* Section header table entry count */
58 unsigned int e_shstrndx
; /* Section header string table index */
63 struct elf_internal_phdr
{
64 unsigned long p_type
; /* Identifies program segment type */
65 unsigned long p_flags
; /* Segment flags */
66 bfd_vma p_offset
; /* Segment file offset */
67 bfd_vma p_vaddr
; /* Segment virtual address */
68 bfd_vma p_paddr
; /* Segment physical address */
69 bfd_vma p_filesz
; /* Segment size in file */
70 bfd_vma p_memsz
; /* Segment size in memory */
71 bfd_vma p_align
; /* Segment alignment, file & memory */
74 typedef struct elf_internal_phdr Elf_Internal_Phdr
;
78 typedef struct elf_internal_shdr
{
79 unsigned int sh_name
; /* Section name, index in string tbl */
80 unsigned int sh_type
; /* Type of section */
81 bfd_vma sh_flags
; /* Miscellaneous section attributes */
82 bfd_vma sh_addr
; /* Section virtual addr at execution */
83 bfd_size_type sh_size
; /* Size of section in bytes */
84 bfd_size_type sh_entsize
; /* Entry size if section holds table */
85 unsigned long sh_link
; /* Index of another section */
86 unsigned long sh_info
; /* Additional section information */
87 file_ptr sh_offset
; /* Section file offset */
88 unsigned int sh_addralign
; /* Section alignment */
90 /* The internal rep also has some cached info associated with it. */
91 asection
* bfd_section
; /* Associated BFD section. */
92 unsigned char *contents
; /* Section contents. */
95 /* Symbol table entry */
97 struct elf_internal_sym
{
98 bfd_vma st_value
; /* Value of the symbol */
99 bfd_vma st_size
; /* Associated symbol size */
100 unsigned long st_name
; /* Symbol name, index in string tbl */
101 unsigned char st_info
; /* Type and binding attributes */
102 unsigned char st_other
; /* Visibilty, and target specific */
103 unsigned int st_shndx
; /* Associated section index */
106 typedef struct elf_internal_sym Elf_Internal_Sym
;
110 typedef struct elf_internal_note
{
111 unsigned long namesz
; /* Size of entry's owner string */
112 unsigned long descsz
; /* Size of the note descriptor */
113 unsigned long type
; /* Interpretation of the descriptor */
114 char * namedata
; /* Start of the name+desc data */
115 char * descdata
; /* Start of the desc data */
116 bfd_vma descpos
; /* File offset of the descdata */
119 /* Relocation Entries */
121 typedef struct elf_internal_rela
{
122 bfd_vma r_offset
; /* Location at which to apply the action */
123 bfd_vma r_info
; /* Index and Type of relocation */
124 bfd_vma r_addend
; /* Constant addend used to compute value */
127 /* dynamic section structure */
129 typedef struct elf_internal_dyn
{
130 /* This needs to support 64-bit values in elf64. */
131 bfd_vma d_tag
; /* entry tag value */
133 /* This needs to support 64-bit values in elf64. */
139 /* This structure appears in a SHT_GNU_verdef section. */
141 typedef struct elf_internal_verdef
{
142 unsigned short vd_version
; /* Version number of structure. */
143 unsigned short vd_flags
; /* Flags (VER_FLG_*). */
144 unsigned short vd_ndx
; /* Version index. */
145 unsigned short vd_cnt
; /* Number of verdaux entries. */
146 unsigned long vd_hash
; /* Hash of name. */
147 unsigned long vd_aux
; /* Offset to verdaux entries. */
148 unsigned long vd_next
; /* Offset to next verdef. */
150 /* These fields are set up when BFD reads in the structure. FIXME:
151 It would be cleaner to store these in a different structure. */
152 bfd
*vd_bfd
; /* BFD. */
153 const char *vd_nodename
; /* Version name. */
154 struct elf_internal_verdef
*vd_nextdef
; /* vd_next as pointer. */
155 struct elf_internal_verdaux
*vd_auxptr
; /* vd_aux as pointer. */
156 unsigned int vd_exp_refno
; /* Used by the linker. */
157 } Elf_Internal_Verdef
;
159 /* This structure appears in a SHT_GNU_verdef section. */
161 typedef struct elf_internal_verdaux
{
162 unsigned long vda_name
; /* String table offset of name. */
163 unsigned long vda_next
; /* Offset to next verdaux. */
165 /* These fields are set up when BFD reads in the structure. FIXME:
166 It would be cleaner to store these in a different structure. */
167 const char *vda_nodename
; /* vda_name as pointer. */
168 struct elf_internal_verdaux
*vda_nextptr
; /* vda_next as pointer. */
169 } Elf_Internal_Verdaux
;
171 /* This structure appears in a SHT_GNU_verneed section. */
173 typedef struct elf_internal_verneed
{
174 unsigned short vn_version
; /* Version number of structure. */
175 unsigned short vn_cnt
; /* Number of vernaux entries. */
176 unsigned long vn_file
; /* String table offset of library name. */
177 unsigned long vn_aux
; /* Offset to vernaux entries. */
178 unsigned long vn_next
; /* Offset to next verneed. */
180 /* These fields are set up when BFD reads in the structure. FIXME:
181 It would be cleaner to store these in a different structure. */
182 bfd
*vn_bfd
; /* BFD. */
183 const char *vn_filename
; /* vn_file as pointer. */
184 struct elf_internal_vernaux
*vn_auxptr
; /* vn_aux as pointer. */
185 struct elf_internal_verneed
*vn_nextref
; /* vn_nextref as pointer. */
186 } Elf_Internal_Verneed
;
188 /* This structure appears in a SHT_GNU_verneed section. */
190 typedef struct elf_internal_vernaux
{
191 unsigned long vna_hash
; /* Hash of dependency name. */
192 unsigned short vna_flags
; /* Flags (VER_FLG_*). */
193 unsigned short vna_other
; /* Unused. */
194 unsigned long vna_name
; /* String table offset to version name. */
195 unsigned long vna_next
; /* Offset to next vernaux. */
197 /* These fields are set up when BFD reads in the structure. FIXME:
198 It would be cleaner to store these in a different structure. */
199 const char *vna_nodename
; /* vna_name as pointer. */
200 struct elf_internal_vernaux
*vna_nextptr
; /* vna_next as pointer. */
201 } Elf_Internal_Vernaux
;
203 /* This structure appears in a SHT_GNU_versym section. This is not a
204 standard ELF structure; ELF just uses Elf32_Half. */
206 typedef struct elf_internal_versym
{
207 unsigned short vs_vers
;
208 } Elf_Internal_Versym
;
210 /* Structure for syminfo section. */
213 unsigned short int si_boundto
;
214 unsigned short int si_flags
;
215 } Elf_Internal_Syminfo
;
217 /* This structure appears on the stack and in NT_AUXV core file notes. */
225 /* This structure is used to describe how sections should be assigned
226 to program segments. */
228 struct elf_segment_map
230 /* Next program segment. */
231 struct elf_segment_map
*next
;
232 /* Program segment type. */
233 unsigned long p_type
;
234 /* Program segment flags. */
235 unsigned long p_flags
;
236 /* Program segment physical address. */
238 /* Whether the p_flags field is valid; if not, the flags are based
239 on the section flags. */
240 unsigned int p_flags_valid
: 1;
241 /* Whether the p_paddr field is valid; if not, the physical address
242 is based on the section lma values. */
243 unsigned int p_paddr_valid
: 1;
244 /* Whether this segment includes the file header. */
245 unsigned int includes_filehdr
: 1;
246 /* Whether this segment includes the program headers. */
247 unsigned int includes_phdrs
: 1;
248 /* Number of sections (may be 0). */
250 /* Sections. Actual number of elements is in count field. */
251 asection
*sections
[1];
254 /* Decide if the given sec_hdr is in the given segment in file. */
255 #define ELF_IS_SECTION_IN_SEGMENT_FILE(sec_hdr, segment) \
256 (sec_hdr->sh_size > 0 \
257 /* PT_TLS segment contains only SHF_TLS sections. */ \
258 && (segment->p_type != PT_TLS \
259 || (sec_hdr->sh_flags & SHF_TLS) != 0) \
260 /* Compare allocated sec_hdrs by VMA, unallocated sec_hdrs \
262 && (sec_hdr->sh_flags & SHF_ALLOC \
263 ? (sec_hdr->sh_addr >= segment->p_vaddr \
264 && sec_hdr->sh_addr + sec_hdr->sh_size \
265 <= segment->p_vaddr + segment->p_memsz) \
266 : ((bfd_vma) sec_hdr->sh_offset >= segment->p_offset \
267 && (sec_hdr->sh_offset + sec_hdr->sh_size \
268 <= segment->p_offset + segment->p_filesz))))
270 /* Decide if the given sec_hdr is in the given segment in memory. */
271 #define ELF_IS_SECTION_IN_SEGMENT_MEMORY(sec_hdr, segment) \
272 (ELF_IS_SECTION_IN_SEGMENT_FILE (sec_hdr, segment) \
273 /* .tbss is special. It doesn't contribute memory space to \
274 normal segments. */ \
275 && (!((sec_hdr->sh_flags & SHF_TLS) != 0 \
276 && sec_hdr->sh_type == SHT_NOBITS) \
277 || segment->p_type == PT_TLS))
279 #endif /* _ELF_INTERNAL_H */