xref: /netbsd-src/external/gpl3/gdb/dist/include/elf/internal.h (revision 02f41505626a9ceb584d30d0789203495760ac88)
198b9484cSchristos /* ELF support for BFD.
2*02f41505Schristos    Copyright (C) 1991-2024 Free Software Foundation, Inc.
398b9484cSchristos 
498b9484cSchristos    Written by Fred Fish @ Cygnus Support, from information published
598b9484cSchristos    in "UNIX System V Release 4, Programmers Guide: ANSI C and
698b9484cSchristos    Programming Support Tools".
798b9484cSchristos 
898b9484cSchristos    This file is part of BFD, the Binary File Descriptor library.
998b9484cSchristos 
1098b9484cSchristos    This program is free software; you can redistribute it and/or modify
1198b9484cSchristos    it under the terms of the GNU General Public License as published by
1298b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
1398b9484cSchristos    (at your option) any later version.
1498b9484cSchristos 
1598b9484cSchristos    This program is distributed in the hope that it will be useful,
1698b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1798b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1898b9484cSchristos    GNU General Public License for more details.
1998b9484cSchristos 
2098b9484cSchristos    You should have received a copy of the GNU General Public License
2198b9484cSchristos    along with this program; if not, write to the Free Software
2298b9484cSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2398b9484cSchristos    MA 02110-1301, USA.  */
2498b9484cSchristos 
2598b9484cSchristos /* This file is part of ELF support for BFD, and contains the portions
2698b9484cSchristos    that describe how ELF is represented internally in the BFD library.
2798b9484cSchristos    I.E. it describes the in-memory representation of ELF.  It requires
2898b9484cSchristos    the elf-common.h file which contains the portions that are common to
2998b9484cSchristos    both the internal and external representations.  */
3098b9484cSchristos 
3198b9484cSchristos /* NOTE that these structures are not kept in the same order as they appear
3298b9484cSchristos    in the object file.  In some cases they've been reordered for more optimal
3398b9484cSchristos    packing under various circumstances.  */
3498b9484cSchristos 
3598b9484cSchristos #ifndef _ELF_INTERNAL_H
3698b9484cSchristos #define _ELF_INTERNAL_H
3798b9484cSchristos 
3898b9484cSchristos /* Special section indices, which may show up in st_shndx fields, among
3998b9484cSchristos    other places.  */
4098b9484cSchristos 
4198b9484cSchristos #undef SHN_UNDEF
4298b9484cSchristos #undef SHN_LORESERVE
4398b9484cSchristos #undef SHN_LOPROC
4498b9484cSchristos #undef SHN_HIPROC
4598b9484cSchristos #undef SHN_LOOS
4698b9484cSchristos #undef SHN_HIOS
4798b9484cSchristos #undef SHN_ABS
4898b9484cSchristos #undef SHN_COMMON
4998b9484cSchristos #undef SHN_XINDEX
5098b9484cSchristos #undef SHN_HIRESERVE
5198b9484cSchristos #define SHN_UNDEF	0		/* Undefined section reference */
5298b9484cSchristos #define SHN_LORESERVE	(-0x100u)	/* Begin range of reserved indices */
5398b9484cSchristos #define SHN_LOPROC	(-0x100u)	/* Begin range of appl-specific */
5498b9484cSchristos #define SHN_HIPROC	(-0xE1u)	/* End range of appl-specific */
5598b9484cSchristos #define SHN_LOOS	(-0xE0u)	/* OS specific semantics, lo */
5698b9484cSchristos #define SHN_HIOS	(-0xC1u)	/* OS specific semantics, hi */
5798b9484cSchristos #define SHN_ABS		(-0xFu)		/* Associated symbol is absolute */
5898b9484cSchristos #define SHN_COMMON	(-0xEu)		/* Associated symbol is in common */
5998b9484cSchristos #define SHN_XINDEX	(-0x1u)		/* Section index is held elsewhere */
6098b9484cSchristos #define SHN_HIRESERVE	(-0x1u)		/* End range of reserved indices */
6198b9484cSchristos #define SHN_BAD		(-0x101u)	/* Used internally by bfd */
6298b9484cSchristos 
6398b9484cSchristos /* ELF Header */
6498b9484cSchristos 
6598b9484cSchristos #define EI_NIDENT	16		/* Size of e_ident[] */
6698b9484cSchristos 
6798b9484cSchristos typedef struct elf_internal_ehdr {
6898b9484cSchristos   unsigned char		e_ident[EI_NIDENT]; /* ELF "magic number" */
6998b9484cSchristos   bfd_vma		e_entry;	/* Entry point virtual address */
7098b9484cSchristos   bfd_size_type		e_phoff;	/* Program header table file offset */
7198b9484cSchristos   bfd_size_type		e_shoff;	/* Section header table file offset */
7298b9484cSchristos   unsigned long		e_version;	/* Identifies object file version */
7398b9484cSchristos   unsigned long		e_flags;	/* Processor-specific flags */
7498b9484cSchristos   unsigned short	e_type;		/* Identifies object file type */
7598b9484cSchristos   unsigned short	e_machine;	/* Specifies required architecture */
7698b9484cSchristos   unsigned int		e_ehsize;	/* ELF header size in bytes */
7798b9484cSchristos   unsigned int		e_phentsize;	/* Program header table entry size */
7898b9484cSchristos   unsigned int		e_phnum;	/* Program header table entry count */
7998b9484cSchristos   unsigned int		e_shentsize;	/* Section header table entry size */
8098b9484cSchristos   unsigned int		e_shnum;	/* Section header table entry count */
8198b9484cSchristos   unsigned int		e_shstrndx;	/* Section header string table index */
8298b9484cSchristos } Elf_Internal_Ehdr;
8398b9484cSchristos 
8498b9484cSchristos /* Program header */
8598b9484cSchristos 
8698b9484cSchristos struct elf_internal_phdr {
878dffb485Schristos   unsigned long	p_type;		     /* Identifies program segment type.  */
888dffb485Schristos   unsigned long	p_flags;	     /* Segment flags.  */
898dffb485Schristos   bfd_vma	p_offset;	     /* Segment file offset in octets.  */
908dffb485Schristos   bfd_vma	p_vaddr;	     /* Segment virtual address in octets.  */
918dffb485Schristos   bfd_vma	p_paddr;	     /* Segment physical address in octets.  */
928dffb485Schristos   bfd_vma	p_filesz;	     /* Segment size in file in octets.  */
938dffb485Schristos   bfd_vma	p_memsz;	     /* Segment size in memory in octets.  */
948dffb485Schristos   bfd_vma	p_align;	     /* Segment alignment in bytes, file
958dffb485Schristos 					& memory */
9698b9484cSchristos };
9798b9484cSchristos 
9898b9484cSchristos typedef struct elf_internal_phdr Elf_Internal_Phdr;
9998b9484cSchristos 
10098b9484cSchristos /* Section header */
10198b9484cSchristos 
10298b9484cSchristos typedef struct elf_internal_shdr {
10398b9484cSchristos   unsigned int	sh_name;		/* Section name, index in string tbl */
10498b9484cSchristos   unsigned int	sh_type;		/* Type of section */
10598b9484cSchristos   bfd_vma	sh_flags;		/* Miscellaneous section attributes */
1068dffb485Schristos   bfd_vma	sh_addr;		/* Section virtual addr at execution in
1078dffb485Schristos 					   octets.  */
1088dffb485Schristos   file_ptr	sh_offset;		/* Section file offset in octets.  */
1098dffb485Schristos   bfd_size_type	sh_size;		/* Size of section in octets.  */
11098b9484cSchristos   unsigned int	sh_link;		/* Index of another section */
11198b9484cSchristos   unsigned int	sh_info;		/* Additional section information */
11298b9484cSchristos   bfd_vma	sh_addralign;		/* Section alignment */
11398b9484cSchristos   bfd_size_type	sh_entsize;		/* Entry size if section holds table */
11498b9484cSchristos 
11598b9484cSchristos   /* The internal rep also has some cached info associated with it. */
11698b9484cSchristos   asection *	bfd_section;		/* Associated BFD section.  */
11798b9484cSchristos   unsigned char *contents;		/* Section contents.  */
11898b9484cSchristos } Elf_Internal_Shdr;
11998b9484cSchristos 
120212397c6Schristos /* Compression header */
121212397c6Schristos 
122212397c6Schristos typedef struct elf_internal_chdr {
123212397c6Schristos   unsigned int	ch_type;		/* Type of compression */
124212397c6Schristos   bfd_size_type	ch_size;		/* Size of uncompressed data in bytes */
125212397c6Schristos   bfd_vma	ch_addralign;		/* Alignment of uncompressed data */
126212397c6Schristos } Elf_Internal_Chdr;
127212397c6Schristos 
12898b9484cSchristos /* Symbol table entry */
12998b9484cSchristos 
13098b9484cSchristos struct elf_internal_sym {
13198b9484cSchristos   bfd_vma	st_value;		/* Value of the symbol */
13298b9484cSchristos   bfd_vma	st_size;		/* Associated symbol size */
13398b9484cSchristos   unsigned long	st_name;		/* Symbol name, index in string tbl */
13498b9484cSchristos   unsigned char	st_info;		/* Type and binding attributes */
13598b9484cSchristos   unsigned char	st_other;		/* Visibilty, and target specific */
13698b9484cSchristos   unsigned char st_target_internal;	/* Internal-only information */
13798b9484cSchristos   unsigned int  st_shndx;		/* Associated section index */
13898b9484cSchristos };
13998b9484cSchristos 
14098b9484cSchristos typedef struct elf_internal_sym Elf_Internal_Sym;
14198b9484cSchristos 
14298b9484cSchristos /* Note segments */
14398b9484cSchristos 
14498b9484cSchristos typedef struct elf_internal_note {
14598b9484cSchristos   unsigned long	namesz;			/* Size of entry's owner string */
14698b9484cSchristos   unsigned long	descsz;			/* Size of the note descriptor */
14798b9484cSchristos   unsigned long	type;			/* Interpretation of the descriptor */
14898b9484cSchristos   char *	namedata;		/* Start of the name+desc data */
14998b9484cSchristos   char *	descdata;		/* Start of the desc data */
15098b9484cSchristos   bfd_vma	descpos;		/* File offset of the descdata */
15198b9484cSchristos } Elf_Internal_Note;
15298b9484cSchristos 
15398b9484cSchristos /* Relocation Entries */
15498b9484cSchristos 
15598b9484cSchristos typedef struct elf_internal_rela {
15698b9484cSchristos   bfd_vma	r_offset;	/* Location at which to apply the action */
15798b9484cSchristos   bfd_vma	r_info;		/* Index and Type of relocation */
15898b9484cSchristos   bfd_vma	r_addend;	/* Constant addend used to compute value */
15998b9484cSchristos } Elf_Internal_Rela;
16098b9484cSchristos 
16198b9484cSchristos /* dynamic section structure */
16298b9484cSchristos 
16398b9484cSchristos typedef struct elf_internal_dyn {
16498b9484cSchristos   /* This needs to support 64-bit values in elf64.  */
16598b9484cSchristos   bfd_vma d_tag;		/* entry tag value */
16698b9484cSchristos   union {
16798b9484cSchristos     /* This needs to support 64-bit values in elf64.  */
16898b9484cSchristos     bfd_vma	d_val;
16998b9484cSchristos     bfd_vma	d_ptr;
17098b9484cSchristos   } d_un;
17198b9484cSchristos } Elf_Internal_Dyn;
17298b9484cSchristos 
17398b9484cSchristos /* This structure appears in a SHT_GNU_verdef section.  */
17498b9484cSchristos 
17598b9484cSchristos typedef struct elf_internal_verdef {
17698b9484cSchristos   unsigned short vd_version;	/* Version number of structure.  */
17798b9484cSchristos   unsigned short vd_flags;	/* Flags (VER_FLG_*).  */
17898b9484cSchristos   unsigned short vd_ndx;	/* Version index.  */
17998b9484cSchristos   unsigned short vd_cnt;	/* Number of verdaux entries.  */
18098b9484cSchristos   unsigned long	 vd_hash;	/* Hash of name.  */
18198b9484cSchristos   unsigned long	 vd_aux;	/* Offset to verdaux entries.  */
18298b9484cSchristos   unsigned long	 vd_next;	/* Offset to next verdef.  */
18398b9484cSchristos 
18498b9484cSchristos   /* These fields are set up when BFD reads in the structure.  FIXME:
18598b9484cSchristos      It would be cleaner to store these in a different structure.  */
18698b9484cSchristos   bfd			      *vd_bfd;		/* BFD.  */
18798b9484cSchristos   const char		      *vd_nodename;	/* Version name.  */
18898b9484cSchristos   struct elf_internal_verdef  *vd_nextdef;	/* vd_next as pointer.  */
18998b9484cSchristos   struct elf_internal_verdaux *vd_auxptr;	/* vd_aux as pointer.  */
19098b9484cSchristos   unsigned int		       vd_exp_refno;	/* Used by the linker.  */
19198b9484cSchristos } Elf_Internal_Verdef;
19298b9484cSchristos 
19398b9484cSchristos /* This structure appears in a SHT_GNU_verdef section.  */
19498b9484cSchristos 
19598b9484cSchristos typedef struct elf_internal_verdaux {
19698b9484cSchristos   unsigned long vda_name;	/* String table offset of name.  */
19798b9484cSchristos   unsigned long vda_next;	/* Offset to next verdaux.  */
19898b9484cSchristos 
19998b9484cSchristos   /* These fields are set up when BFD reads in the structure.  FIXME:
20098b9484cSchristos      It would be cleaner to store these in a different structure.  */
20198b9484cSchristos   const char *vda_nodename;			/* vda_name as pointer.  */
20298b9484cSchristos   struct elf_internal_verdaux *vda_nextptr;	/* vda_next as pointer.  */
20398b9484cSchristos } Elf_Internal_Verdaux;
20498b9484cSchristos 
20598b9484cSchristos /* This structure appears in a SHT_GNU_verneed section.  */
20698b9484cSchristos 
20798b9484cSchristos typedef struct elf_internal_verneed {
20898b9484cSchristos   unsigned short vn_version;	/* Version number of structure.  */
20998b9484cSchristos   unsigned short vn_cnt;	/* Number of vernaux entries.  */
21098b9484cSchristos   unsigned long	 vn_file;	/* String table offset of library name.  */
21198b9484cSchristos   unsigned long	 vn_aux;	/* Offset to vernaux entries.  */
21298b9484cSchristos   unsigned long	 vn_next;	/* Offset to next verneed.  */
21398b9484cSchristos 
21498b9484cSchristos   /* These fields are set up when BFD reads in the structure.  FIXME:
21598b9484cSchristos      It would be cleaner to store these in a different structure.  */
21698b9484cSchristos   bfd			      *vn_bfd;		/* BFD.  */
21798b9484cSchristos   const char                  *vn_filename;	/* vn_file as pointer.  */
21898b9484cSchristos   struct elf_internal_vernaux *vn_auxptr;	/* vn_aux as pointer.  */
21998b9484cSchristos   struct elf_internal_verneed *vn_nextref;	/* vn_nextref as pointer.  */
22098b9484cSchristos } Elf_Internal_Verneed;
22198b9484cSchristos 
22298b9484cSchristos /* This structure appears in a SHT_GNU_verneed section.  */
22398b9484cSchristos 
22498b9484cSchristos typedef struct elf_internal_vernaux {
22598b9484cSchristos   unsigned long	 vna_hash;	/* Hash of dependency name.  */
22698b9484cSchristos   unsigned short vna_flags;	/* Flags (VER_FLG_*).  */
22798b9484cSchristos   unsigned short vna_other;	/* Unused.  */
22898b9484cSchristos   unsigned long	 vna_name;	/* String table offset to version name.  */
22998b9484cSchristos   unsigned long	 vna_next;	/* Offset to next vernaux.  */
23098b9484cSchristos 
23198b9484cSchristos   /* These fields are set up when BFD reads in the structure.  FIXME:
23298b9484cSchristos      It would be cleaner to store these in a different structure.  */
23398b9484cSchristos   const char                  *vna_nodename;	/* vna_name as pointer.  */
23498b9484cSchristos   struct elf_internal_vernaux *vna_nextptr;	/* vna_next as pointer.  */
23598b9484cSchristos } Elf_Internal_Vernaux;
23698b9484cSchristos 
23798b9484cSchristos /* This structure appears in a SHT_GNU_versym section.  This is not a
23898b9484cSchristos    standard ELF structure; ELF just uses Elf32_Half.  */
23998b9484cSchristos 
24098b9484cSchristos typedef struct elf_internal_versym {
24198b9484cSchristos   unsigned short vs_vers;
24298b9484cSchristos } Elf_Internal_Versym;
24398b9484cSchristos 
24498b9484cSchristos /* Structure for syminfo section.  */
24598b9484cSchristos typedef struct
24698b9484cSchristos {
24798b9484cSchristos   unsigned short int 	si_boundto;
24898b9484cSchristos   unsigned short int	si_flags;
24998b9484cSchristos } Elf_Internal_Syminfo;
25098b9484cSchristos 
25198b9484cSchristos /* This structure appears on the stack and in NT_AUXV core file notes.  */
25298b9484cSchristos typedef struct
25398b9484cSchristos {
25498b9484cSchristos   bfd_vma a_type;
25598b9484cSchristos   bfd_vma a_val;
25698b9484cSchristos } Elf_Internal_Auxv;
25798b9484cSchristos 
25898b9484cSchristos 
25998b9484cSchristos /* This structure is used to describe how sections should be assigned
26098b9484cSchristos    to program segments.  */
26198b9484cSchristos 
26298b9484cSchristos struct elf_segment_map
26398b9484cSchristos {
26498b9484cSchristos   /* Next program segment.  */
26598b9484cSchristos   struct elf_segment_map *next;
26698b9484cSchristos   /* Program segment type.  */
26798b9484cSchristos   unsigned long p_type;
26898b9484cSchristos   /* Program segment flags.  */
26998b9484cSchristos   unsigned long p_flags;
2708dffb485Schristos   /* Program segment physical address in octets.  */
27198b9484cSchristos   bfd_vma p_paddr;
2728dffb485Schristos   /* Program segment virtual address offset from section vma in bytes.  */
27398b9484cSchristos   bfd_vma p_vaddr_offset;
27498b9484cSchristos   /* Program segment alignment.  */
27598b9484cSchristos   bfd_vma p_align;
2768dffb485Schristos   /* Segment size in file and memory in octets.  */
27798b9484cSchristos   bfd_vma p_size;
27898b9484cSchristos   /* Whether the p_flags field is valid; if not, the flags are based
27998b9484cSchristos      on the section flags.  */
28098b9484cSchristos   unsigned int p_flags_valid : 1;
28198b9484cSchristos   /* Whether the p_paddr field is valid; if not, the physical address
28298b9484cSchristos      is based on the section lma values.  */
28398b9484cSchristos   unsigned int p_paddr_valid : 1;
28498b9484cSchristos   /* Whether the p_align field is valid; if not, PT_LOAD segment
28598b9484cSchristos      alignment is based on the default maximum page size.  */
28698b9484cSchristos   unsigned int p_align_valid : 1;
28798b9484cSchristos   /* Whether the p_size field is valid; if not, the size are based
28898b9484cSchristos      on the section sizes.  */
28998b9484cSchristos   unsigned int p_size_valid : 1;
29098b9484cSchristos   /* Whether this segment includes the file header.  */
29198b9484cSchristos   unsigned int includes_filehdr : 1;
29298b9484cSchristos   /* Whether this segment includes the program headers.  */
29398b9484cSchristos   unsigned int includes_phdrs : 1;
2948dffb485Schristos   /* Assume this PT_LOAD header has an lma of zero when sorting
2958dffb485Schristos      headers before assigning file offsets.  PT_LOAD headers with this
2968dffb485Schristos      flag set are placed after one with includes_filehdr set, and
2978dffb485Schristos      before PT_LOAD headers without this flag set.  */
2988dffb485Schristos   unsigned int no_sort_lma : 1;
2998dffb485Schristos   /* Index holding original order before sorting segments.  */
3008dffb485Schristos   unsigned int idx;
30198b9484cSchristos   /* Number of sections (may be 0).  */
30298b9484cSchristos   unsigned int count;
30398b9484cSchristos   /* Sections.  Actual number of elements is in count field.  */
30498b9484cSchristos   asection *sections[1];
30598b9484cSchristos };
30698b9484cSchristos 
30798b9484cSchristos /* .tbss is special.  It doesn't contribute memory space to normal
30898b9484cSchristos    segments and it doesn't take file space in normal segments.  */
30998b9484cSchristos #define ELF_TBSS_SPECIAL(sec_hdr, segment)			\
31098b9484cSchristos   (((sec_hdr)->sh_flags & SHF_TLS) != 0				\
31198b9484cSchristos    && (sec_hdr)->sh_type == SHT_NOBITS				\
31298b9484cSchristos    && (segment)->p_type != PT_TLS)
31398b9484cSchristos 
31498b9484cSchristos #define ELF_SECTION_SIZE(sec_hdr, segment)			\
31598b9484cSchristos   (ELF_TBSS_SPECIAL(sec_hdr, segment) ? 0 : (sec_hdr)->sh_size)
31698b9484cSchristos 
31798b9484cSchristos /* Decide if the section SEC_HDR is in SEGMENT.  If CHECK_VMA, then
31898b9484cSchristos    VMAs are checked for alloc sections.  If STRICT, then a zero size
31998b9484cSchristos    section won't match at the end of a segment, unless the segment
32098b9484cSchristos    is also zero size.  Regardless of STRICT and CHECK_VMA, zero size
3214559860eSchristos    sections won't match at the start or end of PT_DYNAMIC nor PT_NOTE,
3224559860eSchristos    unless PT_DYNAMIC and PT_NOTE are themselves zero sized.  */
32398b9484cSchristos #define ELF_SECTION_IN_SEGMENT_1(sec_hdr, segment, check_vma, strict)	\
32498b9484cSchristos   ((/* Only PT_LOAD, PT_GNU_RELRO and PT_TLS segments can contain	\
32598b9484cSchristos        SHF_TLS sections.  */						\
32698b9484cSchristos     ((((sec_hdr)->sh_flags & SHF_TLS) != 0)				\
32798b9484cSchristos      && ((segment)->p_type == PT_TLS					\
32898b9484cSchristos 	 || (segment)->p_type == PT_GNU_RELRO				\
32998b9484cSchristos 	 || (segment)->p_type == PT_LOAD))				\
33098b9484cSchristos     /* PT_TLS segment contains only SHF_TLS sections, PT_PHDR no	\
33198b9484cSchristos        sections at all.  */						\
33298b9484cSchristos     || (((sec_hdr)->sh_flags & SHF_TLS) == 0				\
33398b9484cSchristos 	&& (segment)->p_type != PT_TLS					\
33498b9484cSchristos 	&& (segment)->p_type != PT_PHDR))				\
335212397c6Schristos    /* PT_LOAD and similar segments only have SHF_ALLOC sections.  */	\
336212397c6Schristos    && !(((sec_hdr)->sh_flags & SHF_ALLOC) == 0				\
337212397c6Schristos 	&& ((segment)->p_type == PT_LOAD				\
338212397c6Schristos 	    || (segment)->p_type == PT_DYNAMIC				\
339212397c6Schristos 	    || (segment)->p_type == PT_GNU_EH_FRAME			\
3408dffb485Schristos 	    || (segment)->p_type == PT_GNU_STACK			\
341212397c6Schristos 	    || (segment)->p_type == PT_GNU_RELRO			\
3424b169a6bSchristos 	    || (segment)->p_type == PT_GNU_SFRAME			\
3438dffb485Schristos 	    || ((segment)->p_type >= PT_GNU_MBIND_LO			\
3448dffb485Schristos 		&& (segment)->p_type <= PT_GNU_MBIND_HI)))		\
34598b9484cSchristos    /* Any section besides one of type SHT_NOBITS must have file		\
34698b9484cSchristos       offsets within the segment.  */					\
34798b9484cSchristos    && ((sec_hdr)->sh_type == SHT_NOBITS					\
34898b9484cSchristos        || ((bfd_vma) (sec_hdr)->sh_offset >= (segment)->p_offset	\
34998b9484cSchristos 	   && (!(strict)						\
35098b9484cSchristos 	       || ((sec_hdr)->sh_offset - (segment)->p_offset		\
35198b9484cSchristos 		   <= (segment)->p_filesz - 1))				\
35298b9484cSchristos 	   && (((sec_hdr)->sh_offset - (segment)->p_offset		\
35398b9484cSchristos 		+ ELF_SECTION_SIZE(sec_hdr, segment))			\
35498b9484cSchristos 	       <= (segment)->p_filesz)))				\
35598b9484cSchristos    /* SHF_ALLOC sections must have VMAs within the segment.  */		\
35698b9484cSchristos    && (!(check_vma)							\
35798b9484cSchristos        || ((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
35898b9484cSchristos        || ((sec_hdr)->sh_addr >= (segment)->p_vaddr			\
35998b9484cSchristos 	   && (!(strict)						\
36098b9484cSchristos 	       || ((sec_hdr)->sh_addr - (segment)->p_vaddr		\
36198b9484cSchristos 		   <= (segment)->p_memsz - 1))				\
36298b9484cSchristos 	   && (((sec_hdr)->sh_addr - (segment)->p_vaddr			\
36398b9484cSchristos 		+ ELF_SECTION_SIZE(sec_hdr, segment))			\
36498b9484cSchristos 	       <= (segment)->p_memsz)))					\
3654559860eSchristos    /* No zero size sections at start or end of PT_DYNAMIC nor		\
3664559860eSchristos       PT_NOTE.  */							\
3674559860eSchristos    && (((segment)->p_type != PT_DYNAMIC					\
3684559860eSchristos 	&& (segment)->p_type != PT_NOTE)				\
36998b9484cSchristos        || (sec_hdr)->sh_size != 0					\
37098b9484cSchristos        || (segment)->p_memsz == 0					\
37198b9484cSchristos        || (((sec_hdr)->sh_type == SHT_NOBITS				\
37298b9484cSchristos 	    || ((bfd_vma) (sec_hdr)->sh_offset > (segment)->p_offset	\
37398b9484cSchristos 	        && ((sec_hdr)->sh_offset - (segment)->p_offset		\
37498b9484cSchristos 		    < (segment)->p_filesz)))				\
37598b9484cSchristos 	   && (((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
37698b9484cSchristos 	       || ((sec_hdr)->sh_addr > (segment)->p_vaddr		\
37798b9484cSchristos 		   && ((sec_hdr)->sh_addr - (segment)->p_vaddr		\
37898b9484cSchristos 		       < (segment)->p_memsz))))))
37998b9484cSchristos 
38098b9484cSchristos #define ELF_SECTION_IN_SEGMENT(sec_hdr, segment)			\
38198b9484cSchristos   (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 0))
38298b9484cSchristos 
38398b9484cSchristos #define ELF_SECTION_IN_SEGMENT_STRICT(sec_hdr, segment)			\
38498b9484cSchristos   (ELF_SECTION_IN_SEGMENT_1 (sec_hdr, segment, 1, 1))
38598b9484cSchristos 
38698b9484cSchristos #endif /* _ELF_INTERNAL_H */
387