xref: /dflybsd-src/contrib/binutils-2.27/include/elf/internal.h (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj /* ELF support for BFD.
2*a9fa9459Szrj    Copyright (C) 1991-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj 
4*a9fa9459Szrj    Written by Fred Fish @ Cygnus Support, from information published
5*a9fa9459Szrj    in "UNIX System V Release 4, Programmers Guide: ANSI C and
6*a9fa9459Szrj    Programming Support Tools".
7*a9fa9459Szrj 
8*a9fa9459Szrj    This file is part of BFD, the Binary File Descriptor library.
9*a9fa9459Szrj 
10*a9fa9459Szrj    This program is free software; you can redistribute it and/or modify
11*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
12*a9fa9459Szrj    the Free Software Foundation; either version 3 of the License, or
13*a9fa9459Szrj    (at your option) any later version.
14*a9fa9459Szrj 
15*a9fa9459Szrj    This program is distributed in the hope that it will be useful,
16*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
17*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*a9fa9459Szrj    GNU General Public License for more details.
19*a9fa9459Szrj 
20*a9fa9459Szrj    You should have received a copy of the GNU General Public License
21*a9fa9459Szrj    along with this program; if not, write to the Free Software
22*a9fa9459Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23*a9fa9459Szrj    MA 02110-1301, USA.  */
24*a9fa9459Szrj 
25*a9fa9459Szrj /* This file is part of ELF support for BFD, and contains the portions
26*a9fa9459Szrj    that describe how ELF is represented internally in the BFD library.
27*a9fa9459Szrj    I.E. it describes the in-memory representation of ELF.  It requires
28*a9fa9459Szrj    the elf-common.h file which contains the portions that are common to
29*a9fa9459Szrj    both the internal and external representations.  */
30*a9fa9459Szrj 
31*a9fa9459Szrj /* NOTE that these structures are not kept in the same order as they appear
32*a9fa9459Szrj    in the object file.  In some cases they've been reordered for more optimal
33*a9fa9459Szrj    packing under various circumstances.  */
34*a9fa9459Szrj 
35*a9fa9459Szrj #ifndef _ELF_INTERNAL_H
36*a9fa9459Szrj #define _ELF_INTERNAL_H
37*a9fa9459Szrj 
38*a9fa9459Szrj /* Special section indices, which may show up in st_shndx fields, among
39*a9fa9459Szrj    other places.  */
40*a9fa9459Szrj 
41*a9fa9459Szrj #undef SHN_UNDEF
42*a9fa9459Szrj #undef SHN_LORESERVE
43*a9fa9459Szrj #undef SHN_LOPROC
44*a9fa9459Szrj #undef SHN_HIPROC
45*a9fa9459Szrj #undef SHN_LOOS
46*a9fa9459Szrj #undef SHN_HIOS
47*a9fa9459Szrj #undef SHN_ABS
48*a9fa9459Szrj #undef SHN_COMMON
49*a9fa9459Szrj #undef SHN_XINDEX
50*a9fa9459Szrj #undef SHN_HIRESERVE
51*a9fa9459Szrj #define SHN_UNDEF	0		/* Undefined section reference */
52*a9fa9459Szrj #define SHN_LORESERVE	(-0x100u)	/* Begin range of reserved indices */
53*a9fa9459Szrj #define SHN_LOPROC	(-0x100u)	/* Begin range of appl-specific */
54*a9fa9459Szrj #define SHN_HIPROC	(-0xE1u)	/* End range of appl-specific */
55*a9fa9459Szrj #define SHN_LOOS	(-0xE0u)	/* OS specific semantics, lo */
56*a9fa9459Szrj #define SHN_HIOS	(-0xC1u)	/* OS specific semantics, hi */
57*a9fa9459Szrj #define SHN_ABS		(-0xFu)		/* Associated symbol is absolute */
58*a9fa9459Szrj #define SHN_COMMON	(-0xEu)		/* Associated symbol is in common */
59*a9fa9459Szrj #define SHN_XINDEX	(-0x1u)		/* Section index is held elsewhere */
60*a9fa9459Szrj #define SHN_HIRESERVE	(-0x1u)		/* End range of reserved indices */
61*a9fa9459Szrj #define SHN_BAD		(-0x101u)	/* Used internally by bfd */
62*a9fa9459Szrj 
63*a9fa9459Szrj /* ELF Header */
64*a9fa9459Szrj 
65*a9fa9459Szrj #define EI_NIDENT	16		/* Size of e_ident[] */
66*a9fa9459Szrj 
67*a9fa9459Szrj typedef struct elf_internal_ehdr {
68*a9fa9459Szrj   unsigned char		e_ident[EI_NIDENT]; /* ELF "magic number" */
69*a9fa9459Szrj   bfd_vma		e_entry;	/* Entry point virtual address */
70*a9fa9459Szrj   bfd_size_type		e_phoff;	/* Program header table file offset */
71*a9fa9459Szrj   bfd_size_type		e_shoff;	/* Section header table file offset */
72*a9fa9459Szrj   unsigned long		e_version;	/* Identifies object file version */
73*a9fa9459Szrj   unsigned long		e_flags;	/* Processor-specific flags */
74*a9fa9459Szrj   unsigned short	e_type;		/* Identifies object file type */
75*a9fa9459Szrj   unsigned short	e_machine;	/* Specifies required architecture */
76*a9fa9459Szrj   unsigned int		e_ehsize;	/* ELF header size in bytes */
77*a9fa9459Szrj   unsigned int		e_phentsize;	/* Program header table entry size */
78*a9fa9459Szrj   unsigned int		e_phnum;	/* Program header table entry count */
79*a9fa9459Szrj   unsigned int		e_shentsize;	/* Section header table entry size */
80*a9fa9459Szrj   unsigned int		e_shnum;	/* Section header table entry count */
81*a9fa9459Szrj   unsigned int		e_shstrndx;	/* Section header string table index */
82*a9fa9459Szrj } Elf_Internal_Ehdr;
83*a9fa9459Szrj 
84*a9fa9459Szrj /* Program header */
85*a9fa9459Szrj 
86*a9fa9459Szrj struct elf_internal_phdr {
87*a9fa9459Szrj   unsigned long	p_type;			/* Identifies program segment type */
88*a9fa9459Szrj   unsigned long	p_flags;		/* Segment flags */
89*a9fa9459Szrj   bfd_vma	p_offset;		/* Segment file offset */
90*a9fa9459Szrj   bfd_vma	p_vaddr;		/* Segment virtual address */
91*a9fa9459Szrj   bfd_vma	p_paddr;		/* Segment physical address */
92*a9fa9459Szrj   bfd_vma	p_filesz;		/* Segment size in file */
93*a9fa9459Szrj   bfd_vma	p_memsz;		/* Segment size in memory */
94*a9fa9459Szrj   bfd_vma	p_align;		/* Segment alignment, file & memory */
95*a9fa9459Szrj };
96*a9fa9459Szrj 
97*a9fa9459Szrj typedef struct elf_internal_phdr Elf_Internal_Phdr;
98*a9fa9459Szrj 
99*a9fa9459Szrj /* Section header */
100*a9fa9459Szrj 
101*a9fa9459Szrj typedef struct elf_internal_shdr {
102*a9fa9459Szrj   unsigned int	sh_name;		/* Section name, index in string tbl */
103*a9fa9459Szrj   unsigned int	sh_type;		/* Type of section */
104*a9fa9459Szrj   bfd_vma	sh_flags;		/* Miscellaneous section attributes */
105*a9fa9459Szrj   bfd_vma	sh_addr;		/* Section virtual addr at execution */
106*a9fa9459Szrj   file_ptr	sh_offset;		/* Section file offset */
107*a9fa9459Szrj   bfd_size_type	sh_size;		/* Size of section in bytes */
108*a9fa9459Szrj   unsigned int	sh_link;		/* Index of another section */
109*a9fa9459Szrj   unsigned int	sh_info;		/* Additional section information */
110*a9fa9459Szrj   bfd_vma	sh_addralign;		/* Section alignment */
111*a9fa9459Szrj   bfd_size_type	sh_entsize;		/* Entry size if section holds table */
112*a9fa9459Szrj 
113*a9fa9459Szrj   /* The internal rep also has some cached info associated with it. */
114*a9fa9459Szrj   asection *	bfd_section;		/* Associated BFD section.  */
115*a9fa9459Szrj   unsigned char *contents;		/* Section contents.  */
116*a9fa9459Szrj } Elf_Internal_Shdr;
117*a9fa9459Szrj 
118*a9fa9459Szrj /* Compression header */
119*a9fa9459Szrj 
120*a9fa9459Szrj typedef struct elf_internal_chdr {
121*a9fa9459Szrj   unsigned int	ch_type;		/* Type of compression */
122*a9fa9459Szrj   bfd_size_type	ch_size;		/* Size of uncompressed data in bytes */
123*a9fa9459Szrj   bfd_vma	ch_addralign;		/* Alignment of uncompressed data */
124*a9fa9459Szrj } Elf_Internal_Chdr;
125*a9fa9459Szrj 
126*a9fa9459Szrj /* Symbol table entry */
127*a9fa9459Szrj 
128*a9fa9459Szrj struct elf_internal_sym {
129*a9fa9459Szrj   bfd_vma	st_value;		/* Value of the symbol */
130*a9fa9459Szrj   bfd_vma	st_size;		/* Associated symbol size */
131*a9fa9459Szrj   unsigned long	st_name;		/* Symbol name, index in string tbl */
132*a9fa9459Szrj   unsigned char	st_info;		/* Type and binding attributes */
133*a9fa9459Szrj   unsigned char	st_other;		/* Visibilty, and target specific */
134*a9fa9459Szrj   unsigned char st_target_internal;	/* Internal-only information */
135*a9fa9459Szrj   unsigned int  st_shndx;		/* Associated section index */
136*a9fa9459Szrj };
137*a9fa9459Szrj 
138*a9fa9459Szrj typedef struct elf_internal_sym Elf_Internal_Sym;
139*a9fa9459Szrj 
140*a9fa9459Szrj /* Note segments */
141*a9fa9459Szrj 
142*a9fa9459Szrj typedef struct elf_internal_note {
143*a9fa9459Szrj   unsigned long	namesz;			/* Size of entry's owner string */
144*a9fa9459Szrj   unsigned long	descsz;			/* Size of the note descriptor */
145*a9fa9459Szrj   unsigned long	type;			/* Interpretation of the descriptor */
146*a9fa9459Szrj   char *	namedata;		/* Start of the name+desc data */
147*a9fa9459Szrj   char *	descdata;		/* Start of the desc data */
148*a9fa9459Szrj   bfd_vma	descpos;		/* File offset of the descdata */
149*a9fa9459Szrj } Elf_Internal_Note;
150*a9fa9459Szrj 
151*a9fa9459Szrj /* Relocation Entries */
152*a9fa9459Szrj 
153*a9fa9459Szrj typedef struct elf_internal_rela {
154*a9fa9459Szrj   bfd_vma	r_offset;	/* Location at which to apply the action */
155*a9fa9459Szrj   bfd_vma	r_info;		/* Index and Type of relocation */
156*a9fa9459Szrj   bfd_vma	r_addend;	/* Constant addend used to compute value */
157*a9fa9459Szrj } Elf_Internal_Rela;
158*a9fa9459Szrj 
159*a9fa9459Szrj /* dynamic section structure */
160*a9fa9459Szrj 
161*a9fa9459Szrj typedef struct elf_internal_dyn {
162*a9fa9459Szrj   /* This needs to support 64-bit values in elf64.  */
163*a9fa9459Szrj   bfd_vma d_tag;		/* entry tag value */
164*a9fa9459Szrj   union {
165*a9fa9459Szrj     /* This needs to support 64-bit values in elf64.  */
166*a9fa9459Szrj     bfd_vma	d_val;
167*a9fa9459Szrj     bfd_vma	d_ptr;
168*a9fa9459Szrj   } d_un;
169*a9fa9459Szrj } Elf_Internal_Dyn;
170*a9fa9459Szrj 
171*a9fa9459Szrj /* This structure appears in a SHT_GNU_verdef section.  */
172*a9fa9459Szrj 
173*a9fa9459Szrj typedef struct elf_internal_verdef {
174*a9fa9459Szrj   unsigned short vd_version;	/* Version number of structure.  */
175*a9fa9459Szrj   unsigned short vd_flags;	/* Flags (VER_FLG_*).  */
176*a9fa9459Szrj   unsigned short vd_ndx;	/* Version index.  */
177*a9fa9459Szrj   unsigned short vd_cnt;	/* Number of verdaux entries.  */
178*a9fa9459Szrj   unsigned long	 vd_hash;	/* Hash of name.  */
179*a9fa9459Szrj   unsigned long	 vd_aux;	/* Offset to verdaux entries.  */
180*a9fa9459Szrj   unsigned long	 vd_next;	/* Offset to next verdef.  */
181*a9fa9459Szrj 
182*a9fa9459Szrj   /* These fields are set up when BFD reads in the structure.  FIXME:
183*a9fa9459Szrj      It would be cleaner to store these in a different structure.  */
184*a9fa9459Szrj   bfd			      *vd_bfd;		/* BFD.  */
185*a9fa9459Szrj   const char		      *vd_nodename;	/* Version name.  */
186*a9fa9459Szrj   struct elf_internal_verdef  *vd_nextdef;	/* vd_next as pointer.  */
187*a9fa9459Szrj   struct elf_internal_verdaux *vd_auxptr;	/* vd_aux as pointer.  */
188*a9fa9459Szrj   unsigned int		       vd_exp_refno;	/* Used by the linker.  */
189*a9fa9459Szrj } Elf_Internal_Verdef;
190*a9fa9459Szrj 
191*a9fa9459Szrj /* This structure appears in a SHT_GNU_verdef section.  */
192*a9fa9459Szrj 
193*a9fa9459Szrj typedef struct elf_internal_verdaux {
194*a9fa9459Szrj   unsigned long vda_name;	/* String table offset of name.  */
195*a9fa9459Szrj   unsigned long vda_next;	/* Offset to next verdaux.  */
196*a9fa9459Szrj 
197*a9fa9459Szrj   /* These fields are set up when BFD reads in the structure.  FIXME:
198*a9fa9459Szrj      It would be cleaner to store these in a different structure.  */
199*a9fa9459Szrj   const char *vda_nodename;			/* vda_name as pointer.  */
200*a9fa9459Szrj   struct elf_internal_verdaux *vda_nextptr;	/* vda_next as pointer.  */
201*a9fa9459Szrj } Elf_Internal_Verdaux;
202*a9fa9459Szrj 
203*a9fa9459Szrj /* This structure appears in a SHT_GNU_verneed section.  */
204*a9fa9459Szrj 
205*a9fa9459Szrj typedef struct elf_internal_verneed {
206*a9fa9459Szrj   unsigned short vn_version;	/* Version number of structure.  */
207*a9fa9459Szrj   unsigned short vn_cnt;	/* Number of vernaux entries.  */
208*a9fa9459Szrj   unsigned long	 vn_file;	/* String table offset of library name.  */
209*a9fa9459Szrj   unsigned long	 vn_aux;	/* Offset to vernaux entries.  */
210*a9fa9459Szrj   unsigned long	 vn_next;	/* Offset to next verneed.  */
211*a9fa9459Szrj 
212*a9fa9459Szrj   /* These fields are set up when BFD reads in the structure.  FIXME:
213*a9fa9459Szrj      It would be cleaner to store these in a different structure.  */
214*a9fa9459Szrj   bfd			      *vn_bfd;		/* BFD.  */
215*a9fa9459Szrj   const char                  *vn_filename;	/* vn_file as pointer.  */
216*a9fa9459Szrj   struct elf_internal_vernaux *vn_auxptr;	/* vn_aux as pointer.  */
217*a9fa9459Szrj   struct elf_internal_verneed *vn_nextref;	/* vn_nextref as pointer.  */
218*a9fa9459Szrj } Elf_Internal_Verneed;
219*a9fa9459Szrj 
220*a9fa9459Szrj /* This structure appears in a SHT_GNU_verneed section.  */
221*a9fa9459Szrj 
222*a9fa9459Szrj typedef struct elf_internal_vernaux {
223*a9fa9459Szrj   unsigned long	 vna_hash;	/* Hash of dependency name.  */
224*a9fa9459Szrj   unsigned short vna_flags;	/* Flags (VER_FLG_*).  */
225*a9fa9459Szrj   unsigned short vna_other;	/* Unused.  */
226*a9fa9459Szrj   unsigned long	 vna_name;	/* String table offset to version name.  */
227*a9fa9459Szrj   unsigned long	 vna_next;	/* Offset to next vernaux.  */
228*a9fa9459Szrj 
229*a9fa9459Szrj   /* These fields are set up when BFD reads in the structure.  FIXME:
230*a9fa9459Szrj      It would be cleaner to store these in a different structure.  */
231*a9fa9459Szrj   const char                  *vna_nodename;	/* vna_name as pointer.  */
232*a9fa9459Szrj   struct elf_internal_vernaux *vna_nextptr;	/* vna_next as pointer.  */
233*a9fa9459Szrj } Elf_Internal_Vernaux;
234*a9fa9459Szrj 
235*a9fa9459Szrj /* This structure appears in a SHT_GNU_versym section.  This is not a
236*a9fa9459Szrj    standard ELF structure; ELF just uses Elf32_Half.  */
237*a9fa9459Szrj 
238*a9fa9459Szrj typedef struct elf_internal_versym {
239*a9fa9459Szrj   unsigned short vs_vers;
240*a9fa9459Szrj } Elf_Internal_Versym;
241*a9fa9459Szrj 
242*a9fa9459Szrj /* Structure for syminfo section.  */
243*a9fa9459Szrj typedef struct
244*a9fa9459Szrj {
245*a9fa9459Szrj   unsigned short int 	si_boundto;
246*a9fa9459Szrj   unsigned short int	si_flags;
247*a9fa9459Szrj } Elf_Internal_Syminfo;
248*a9fa9459Szrj 
249*a9fa9459Szrj /* This structure appears on the stack and in NT_AUXV core file notes.  */
250*a9fa9459Szrj typedef struct
251*a9fa9459Szrj {
252*a9fa9459Szrj   bfd_vma a_type;
253*a9fa9459Szrj   bfd_vma a_val;
254*a9fa9459Szrj } Elf_Internal_Auxv;
255*a9fa9459Szrj 
256*a9fa9459Szrj 
257*a9fa9459Szrj /* This structure is used to describe how sections should be assigned
258*a9fa9459Szrj    to program segments.  */
259*a9fa9459Szrj 
260*a9fa9459Szrj struct elf_segment_map
261*a9fa9459Szrj {
262*a9fa9459Szrj   /* Next program segment.  */
263*a9fa9459Szrj   struct elf_segment_map *next;
264*a9fa9459Szrj   /* Program segment type.  */
265*a9fa9459Szrj   unsigned long p_type;
266*a9fa9459Szrj   /* Program segment flags.  */
267*a9fa9459Szrj   unsigned long p_flags;
268*a9fa9459Szrj   /* Program segment physical address.  */
269*a9fa9459Szrj   bfd_vma p_paddr;
270*a9fa9459Szrj   /* Program segment virtual address offset from section vma.  */
271*a9fa9459Szrj   bfd_vma p_vaddr_offset;
272*a9fa9459Szrj   /* Program segment alignment.  */
273*a9fa9459Szrj   bfd_vma p_align;
274*a9fa9459Szrj   /* Segment size in file and memory */
275*a9fa9459Szrj   bfd_vma p_size;
276*a9fa9459Szrj   /* Required size of filehdr + phdrs, if non-zero */
277*a9fa9459Szrj   bfd_vma header_size;
278*a9fa9459Szrj   /* Whether the p_flags field is valid; if not, the flags are based
279*a9fa9459Szrj      on the section flags.  */
280*a9fa9459Szrj   unsigned int p_flags_valid : 1;
281*a9fa9459Szrj   /* Whether the p_paddr field is valid; if not, the physical address
282*a9fa9459Szrj      is based on the section lma values.  */
283*a9fa9459Szrj   unsigned int p_paddr_valid : 1;
284*a9fa9459Szrj   /* Whether the p_align field is valid; if not, PT_LOAD segment
285*a9fa9459Szrj      alignment is based on the default maximum page size.  */
286*a9fa9459Szrj   unsigned int p_align_valid : 1;
287*a9fa9459Szrj   /* Whether the p_size field is valid; if not, the size are based
288*a9fa9459Szrj      on the section sizes.  */
289*a9fa9459Szrj   unsigned int p_size_valid : 1;
290*a9fa9459Szrj   /* Whether this segment includes the file header.  */
291*a9fa9459Szrj   unsigned int includes_filehdr : 1;
292*a9fa9459Szrj   /* Whether this segment includes the program headers.  */
293*a9fa9459Szrj   unsigned int includes_phdrs : 1;
294*a9fa9459Szrj   /* Number of sections (may be 0).  */
295*a9fa9459Szrj   unsigned int count;
296*a9fa9459Szrj   /* Sections.  Actual number of elements is in count field.  */
297*a9fa9459Szrj   asection *sections[1];
298*a9fa9459Szrj };
299*a9fa9459Szrj 
300*a9fa9459Szrj /* .tbss is special.  It doesn't contribute memory space to normal
301*a9fa9459Szrj    segments and it doesn't take file space in normal segments.  */
302*a9fa9459Szrj #define ELF_TBSS_SPECIAL(sec_hdr, segment)			\
303*a9fa9459Szrj   (((sec_hdr)->sh_flags & SHF_TLS) != 0				\
304*a9fa9459Szrj    && (sec_hdr)->sh_type == SHT_NOBITS				\
305*a9fa9459Szrj    && (segment)->p_type != PT_TLS)
306*a9fa9459Szrj 
307*a9fa9459Szrj #define ELF_SECTION_SIZE(sec_hdr, segment)			\
308*a9fa9459Szrj   (ELF_TBSS_SPECIAL(sec_hdr, segment) ? 0 : (sec_hdr)->sh_size)
309*a9fa9459Szrj 
310*a9fa9459Szrj /* Decide if the section SEC_HDR is in SEGMENT.  If CHECK_VMA, then
311*a9fa9459Szrj    VMAs are checked for alloc sections.  If STRICT, then a zero size
312*a9fa9459Szrj    section won't match at the end of a segment, unless the segment
313*a9fa9459Szrj    is also zero size.  Regardless of STRICT and CHECK_VMA, zero size
314*a9fa9459Szrj    sections won't match at the start or end of PT_DYNAMIC, unless
315*a9fa9459Szrj    PT_DYNAMIC is itself zero sized.  */
316*a9fa9459Szrj #define ELF_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma, strict)	\
317*a9fa9459Szrj   ((/* Only PT_LOAD, PT_GNU_RELRO and PT_TLS segments can contain	\
318*a9fa9459Szrj        SHF_TLS sections.  */						\
319*a9fa9459Szrj     ((((sec_hdr)->sh_flags & SHF_TLS) != 0)				\
320*a9fa9459Szrj      && ((segment)->p_type == PT_TLS					\
321*a9fa9459Szrj 	 || (segment)->p_type == PT_GNU_RELRO				\
322*a9fa9459Szrj 	 || (segment)->p_type == PT_LOAD))				\
323*a9fa9459Szrj     /* PT_TLS segment contains only SHF_TLS sections, PT_PHDR no	\
324*a9fa9459Szrj        sections at all.  */						\
325*a9fa9459Szrj     || (((sec_hdr)->sh_flags & SHF_TLS) == 0				\
326*a9fa9459Szrj 	&& (segment)->p_type != PT_TLS					\
327*a9fa9459Szrj 	&& (segment)->p_type != PT_PHDR))				\
328*a9fa9459Szrj    /* PT_LOAD and similar segments only have SHF_ALLOC sections.  */	\
329*a9fa9459Szrj    && !(((sec_hdr)->sh_flags & SHF_ALLOC) == 0				\
330*a9fa9459Szrj 	&& ((segment)->p_type == PT_LOAD				\
331*a9fa9459Szrj 	    || (segment)->p_type == PT_DYNAMIC				\
332*a9fa9459Szrj 	    || (segment)->p_type == PT_GNU_EH_FRAME			\
333*a9fa9459Szrj 	    || (segment)->p_type == PT_GNU_RELRO			\
334*a9fa9459Szrj 	    || (segment)->p_type == PT_GNU_STACK))			\
335*a9fa9459Szrj    /* Any section besides one of type SHT_NOBITS must have file		\
336*a9fa9459Szrj       offsets within the segment.  */					\
337*a9fa9459Szrj    && ((sec_hdr)->sh_type == SHT_NOBITS					\
338*a9fa9459Szrj        || ((bfd_vma) (sec_hdr)->sh_offset >= (segment)->p_offset	\
339*a9fa9459Szrj 	   && (!(strict)						\
340*a9fa9459Szrj 	       || ((sec_hdr)->sh_offset - (segment)->p_offset		\
341*a9fa9459Szrj 		   <= (segment)->p_filesz - 1))				\
342*a9fa9459Szrj 	   && (((sec_hdr)->sh_offset - (segment)->p_offset		\
343*a9fa9459Szrj 		+ ELF_SECTION_SIZE(sec_hdr, segment))			\
344*a9fa9459Szrj 	       <= (segment)->p_filesz)))				\
345*a9fa9459Szrj    /* SHF_ALLOC sections must have VMAs within the segment.  */		\
346*a9fa9459Szrj    && (!(check_vma)							\
347*a9fa9459Szrj        || ((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
348*a9fa9459Szrj        || ((sec_hdr)->sh_addr >= (segment)->p_vaddr			\
349*a9fa9459Szrj 	   && (!(strict)						\
350*a9fa9459Szrj 	       || ((sec_hdr)->sh_addr - (segment)->p_vaddr		\
351*a9fa9459Szrj 		   <= (segment)->p_memsz - 1))				\
352*a9fa9459Szrj 	   && (((sec_hdr)->sh_addr - (segment)->p_vaddr			\
353*a9fa9459Szrj 		+ ELF_SECTION_SIZE(sec_hdr, segment))			\
354*a9fa9459Szrj 	       <= (segment)->p_memsz)))					\
355*a9fa9459Szrj    /* No zero size sections at start or end of PT_DYNAMIC.  */		\
356*a9fa9459Szrj    && ((segment)->p_type != PT_DYNAMIC					\
357*a9fa9459Szrj        || (sec_hdr)->sh_size != 0					\
358*a9fa9459Szrj        || (segment)->p_memsz == 0					\
359*a9fa9459Szrj        || (((sec_hdr)->sh_type == SHT_NOBITS				\
360*a9fa9459Szrj 	    || ((bfd_vma) (sec_hdr)->sh_offset > (segment)->p_offset	\
361*a9fa9459Szrj 	        && ((sec_hdr)->sh_offset - (segment)->p_offset		\
362*a9fa9459Szrj 		    < (segment)->p_filesz)))				\
363*a9fa9459Szrj 	   && (((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
364*a9fa9459Szrj 	       || ((sec_hdr)->sh_addr > (segment)->p_vaddr		\
365*a9fa9459Szrj 		   && ((sec_hdr)->sh_addr - (segment)->p_vaddr		\
366*a9fa9459Szrj 		       < (segment)->p_memsz))))))
367*a9fa9459Szrj 
368*a9fa9459Szrj #define ELF_SECTION_IN_SEGMENT(sec_hdr, segment)			\
369*a9fa9459Szrj   (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 0))
370*a9fa9459Szrj 
371*a9fa9459Szrj #define ELF_SECTION_IN_SEGMENT_STRICT(sec_hdr, segment)			\
372*a9fa9459Szrj   (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 1))
373*a9fa9459Szrj 
374*a9fa9459Szrj #endif /* _ELF_INTERNAL_H */
375