xref: /openbsd-src/gnu/usr.bin/binutils/include/elf/internal.h (revision 007c2a4539b8b8aaa95c5e73e77620090abe113b)
12159047fSniklas /* ELF support for BFD.
2c074d1c9Sdrahn    Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002
3b55d4692Sfgsch    Free Software Foundation, Inc.
42159047fSniklas 
52159047fSniklas    Written by Fred Fish @ Cygnus Support, from information published
62159047fSniklas    in "UNIX System V Release 4, Programmers Guide: ANSI C and
72159047fSniklas    Programming Support Tools".
82159047fSniklas 
92159047fSniklas This file is part of BFD, the Binary File Descriptor library.
102159047fSniklas 
112159047fSniklas This program is free software; you can redistribute it and/or modify
122159047fSniklas it under the terms of the GNU General Public License as published by
132159047fSniklas the Free Software Foundation; either version 2 of the License, or
142159047fSniklas (at your option) any later version.
152159047fSniklas 
162159047fSniklas This program is distributed in the hope that it will be useful,
172159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
182159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
192159047fSniklas GNU General Public License for more details.
202159047fSniklas 
212159047fSniklas You should have received a copy of the GNU General Public License
222159047fSniklas along with this program; if not, write to the Free Software
232159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
242159047fSniklas 
252159047fSniklas 
262159047fSniklas /* This file is part of ELF support for BFD, and contains the portions
272159047fSniklas    that describe how ELF is represented internally in the BFD library.
282159047fSniklas    I.E. it describes the in-memory representation of ELF.  It requires
292159047fSniklas    the elf-common.h file which contains the portions that are common to
302159047fSniklas    both the internal and external representations. */
312159047fSniklas 
322159047fSniklas 
332159047fSniklas /* NOTE that these structures are not kept in the same order as they appear
342159047fSniklas    in the object file.  In some cases they've been reordered for more optimal
352159047fSniklas    packing under various circumstances.  */
362159047fSniklas 
372159047fSniklas #ifndef _ELF_INTERNAL_H
382159047fSniklas #define _ELF_INTERNAL_H
392159047fSniklas 
402159047fSniklas /* ELF Header */
412159047fSniklas 
422159047fSniklas #define EI_NIDENT	16		/* Size of e_ident[] */
432159047fSniklas 
442159047fSniklas typedef struct elf_internal_ehdr {
452159047fSniklas   unsigned char		e_ident[EI_NIDENT]; /* ELF "magic number" */
462159047fSniklas   bfd_vma		e_entry;	/* Entry point virtual address */
47b305b0f1Sespie   bfd_size_type		e_phoff;	/* Program header table file offset */
48b305b0f1Sespie   bfd_size_type		e_shoff;	/* Section header table file offset */
492159047fSniklas   unsigned long		e_version;	/* Identifies object file version */
502159047fSniklas   unsigned long		e_flags;	/* Processor-specific flags */
512159047fSniklas   unsigned short	e_type;		/* Identifies object file type */
522159047fSniklas   unsigned short	e_machine;	/* Specifies required architecture */
53c074d1c9Sdrahn   unsigned int		e_ehsize;	/* ELF header size in bytes */
54c074d1c9Sdrahn   unsigned int		e_phentsize;	/* Program header table entry size */
55c074d1c9Sdrahn   unsigned int		e_phnum;	/* Program header table entry count */
56c074d1c9Sdrahn   unsigned int		e_shentsize;	/* Section header table entry size */
57c074d1c9Sdrahn   unsigned int		e_shnum;	/* Section header table entry count */
58c074d1c9Sdrahn   unsigned int		e_shstrndx;	/* Section header string table index */
592159047fSniklas } Elf_Internal_Ehdr;
602159047fSniklas 
612159047fSniklas /* Program header */
622159047fSniklas 
632159047fSniklas struct elf_internal_phdr {
642159047fSniklas   unsigned long	p_type;			/* Identifies program segment type */
652159047fSniklas   unsigned long	p_flags;		/* Segment flags */
662159047fSniklas   bfd_vma	p_offset;		/* Segment file offset */
672159047fSniklas   bfd_vma	p_vaddr;		/* Segment virtual address */
682159047fSniklas   bfd_vma	p_paddr;		/* Segment physical address */
692159047fSniklas   bfd_vma	p_filesz;		/* Segment size in file */
702159047fSniklas   bfd_vma	p_memsz;		/* Segment size in memory */
712159047fSniklas   bfd_vma	p_align;		/* Segment alignment, file & memory */
722159047fSniklas };
732159047fSniklas 
742159047fSniklas typedef struct elf_internal_phdr Elf_Internal_Phdr;
752159047fSniklas 
762159047fSniklas /* Section header */
772159047fSniklas 
782159047fSniklas typedef struct elf_internal_shdr {
792159047fSniklas   unsigned int	sh_name;		/* Section name, index in string tbl */
802159047fSniklas   unsigned int	sh_type;		/* Type of section */
812159047fSniklas   bfd_vma	sh_flags;		/* Miscellaneous section attributes */
822159047fSniklas   bfd_vma	sh_addr;		/* Section virtual addr at execution */
832159047fSniklas   bfd_size_type	sh_size;		/* Size of section in bytes */
842159047fSniklas   bfd_size_type	sh_entsize;		/* Entry size if section holds table */
852159047fSniklas   unsigned long	sh_link;		/* Index of another section */
862159047fSniklas   unsigned long	sh_info;		/* Additional section information */
872159047fSniklas   file_ptr	sh_offset;		/* Section file offset */
882159047fSniklas   unsigned int	sh_addralign;		/* Section alignment */
892159047fSniklas 
902159047fSniklas   /* The internal rep also has some cached info associated with it. */
912159047fSniklas   asection *	bfd_section;		/* Associated BFD section.  */
92c074d1c9Sdrahn   unsigned char *contents;		/* Section contents.  */
932159047fSniklas } Elf_Internal_Shdr;
942159047fSniklas 
952159047fSniklas /* Symbol table entry */
962159047fSniklas 
972159047fSniklas struct elf_internal_sym {
982159047fSniklas   bfd_vma	st_value;		/* Value of the symbol */
992159047fSniklas   bfd_vma	st_size;		/* Associated symbol size */
1002159047fSniklas   unsigned long	st_name;		/* Symbol name, index in string tbl */
1012159047fSniklas   unsigned char	st_info;		/* Type and binding attributes */
102b55d4692Sfgsch   unsigned char	st_other;		/* Visibilty, and target specific */
103c074d1c9Sdrahn   unsigned int  st_shndx;		/* Associated section index */
1042159047fSniklas };
1052159047fSniklas 
1062159047fSniklas typedef struct elf_internal_sym Elf_Internal_Sym;
1072159047fSniklas 
1082159047fSniklas /* Note segments */
1092159047fSniklas 
1102159047fSniklas typedef struct elf_internal_note {
1112159047fSniklas   unsigned long	namesz;			/* Size of entry's owner string */
1122159047fSniklas   unsigned long	descsz;			/* Size of the note descriptor */
1132159047fSniklas   unsigned long	type;			/* Interpretation of the descriptor */
114b305b0f1Sespie   char *	namedata;		/* Start of the name+desc data */
115b305b0f1Sespie   char *	descdata;		/* Start of the desc data */
116b305b0f1Sespie   bfd_vma	descpos;		/* File offset of the descdata */
1172159047fSniklas } Elf_Internal_Note;
1182159047fSniklas 
1192159047fSniklas /* Relocation Entries */
1202159047fSniklas 
1212159047fSniklas typedef struct elf_internal_rela {
1222159047fSniklas   bfd_vma	r_offset;	/* Location at which to apply the action */
1232159047fSniklas   bfd_vma	r_info;		/* Index and Type of relocation */
124c074d1c9Sdrahn   bfd_vma	r_addend;	/* Constant addend used to compute value */
1252159047fSniklas } Elf_Internal_Rela;
1262159047fSniklas 
1272159047fSniklas /* dynamic section structure */
1282159047fSniklas 
1292159047fSniklas typedef struct elf_internal_dyn {
1302159047fSniklas   /* This needs to support 64-bit values in elf64.  */
1312159047fSniklas   bfd_vma d_tag;		/* entry tag value */
1322159047fSniklas   union {
1332159047fSniklas     /* This needs to support 64-bit values in elf64.  */
1342159047fSniklas     bfd_vma	d_val;
1352159047fSniklas     bfd_vma	d_ptr;
1362159047fSniklas   } d_un;
1372159047fSniklas } Elf_Internal_Dyn;
1382159047fSniklas 
139b305b0f1Sespie /* This structure appears in a SHT_GNU_verdef section.  */
140b305b0f1Sespie 
141b305b0f1Sespie typedef struct elf_internal_verdef {
142b305b0f1Sespie   unsigned short vd_version;	/* Version number of structure.  */
143b305b0f1Sespie   unsigned short vd_flags;	/* Flags (VER_FLG_*).  */
144b305b0f1Sespie   unsigned short vd_ndx;	/* Version index.  */
145b305b0f1Sespie   unsigned short vd_cnt;	/* Number of verdaux entries.  */
146b305b0f1Sespie   unsigned long	 vd_hash;	/* Hash of name.  */
147b305b0f1Sespie   unsigned long	 vd_aux;	/* Offset to verdaux entries.  */
148b305b0f1Sespie   unsigned long	 vd_next;	/* Offset to next verdef.  */
149b305b0f1Sespie 
150b305b0f1Sespie   /* These fields are set up when BFD reads in the structure.  FIXME:
151b305b0f1Sespie      It would be cleaner to store these in a different structure.  */
152b305b0f1Sespie   bfd			      *vd_bfd;		/* BFD.  */
153b305b0f1Sespie   const char		      *vd_nodename;	/* Version name.  */
154b305b0f1Sespie   struct elf_internal_verdef  *vd_nextdef;	/* vd_next as pointer.  */
155b305b0f1Sespie   struct elf_internal_verdaux *vd_auxptr;	/* vd_aux as pointer.  */
156b305b0f1Sespie   unsigned int		       vd_exp_refno;	/* Used by the linker.  */
157b305b0f1Sespie } Elf_Internal_Verdef;
158b305b0f1Sespie 
159b305b0f1Sespie /* This structure appears in a SHT_GNU_verdef section.  */
160b305b0f1Sespie 
161b305b0f1Sespie typedef struct elf_internal_verdaux {
162b305b0f1Sespie   unsigned long vda_name;	/* String table offset of name.  */
163b305b0f1Sespie   unsigned long vda_next;	/* Offset to next verdaux.  */
164b305b0f1Sespie 
165b305b0f1Sespie   /* These fields are set up when BFD reads in the structure.  FIXME:
166b305b0f1Sespie      It would be cleaner to store these in a different structure.  */
167b305b0f1Sespie   const char *vda_nodename;			/* vda_name as pointer.  */
168b305b0f1Sespie   struct elf_internal_verdaux *vda_nextptr;	/* vda_next as pointer.  */
169b305b0f1Sespie } Elf_Internal_Verdaux;
170b305b0f1Sespie 
171b305b0f1Sespie /* This structure appears in a SHT_GNU_verneed section.  */
172b305b0f1Sespie 
173b305b0f1Sespie typedef struct elf_internal_verneed {
174b305b0f1Sespie   unsigned short vn_version;	/* Version number of structure.  */
175b305b0f1Sespie   unsigned short vn_cnt;	/* Number of vernaux entries.  */
176b305b0f1Sespie   unsigned long	 vn_file;	/* String table offset of library name.  */
177b305b0f1Sespie   unsigned long	 vn_aux;	/* Offset to vernaux entries.  */
178b305b0f1Sespie   unsigned long	 vn_next;	/* Offset to next verneed.  */
179b305b0f1Sespie 
180b305b0f1Sespie   /* These fields are set up when BFD reads in the structure.  FIXME:
181b305b0f1Sespie      It would be cleaner to store these in a different structure.  */
182b305b0f1Sespie   bfd			      *vn_bfd;		/* BFD.  */
183b305b0f1Sespie   const char                  *vn_filename;	/* vn_file as pointer.  */
184b305b0f1Sespie   struct elf_internal_vernaux *vn_auxptr;	/* vn_aux as pointer.  */
185b305b0f1Sespie   struct elf_internal_verneed *vn_nextref;	/* vn_nextref as pointer.  */
186b305b0f1Sespie } Elf_Internal_Verneed;
187b305b0f1Sespie 
188b305b0f1Sespie /* This structure appears in a SHT_GNU_verneed section.  */
189b305b0f1Sespie 
190b305b0f1Sespie typedef struct elf_internal_vernaux {
191b305b0f1Sespie   unsigned long	 vna_hash;	/* Hash of dependency name.  */
192b305b0f1Sespie   unsigned short vna_flags;	/* Flags (VER_FLG_*).  */
193b305b0f1Sespie   unsigned short vna_other;	/* Unused.  */
194b305b0f1Sespie   unsigned long	 vna_name;	/* String table offset to version name.  */
195b305b0f1Sespie   unsigned long	 vna_next;	/* Offset to next vernaux.  */
196b305b0f1Sespie 
197b305b0f1Sespie   /* These fields are set up when BFD reads in the structure.  FIXME:
198b305b0f1Sespie      It would be cleaner to store these in a different structure.  */
199b305b0f1Sespie   const char                  *vna_nodename;	/* vna_name as pointer.  */
200b305b0f1Sespie   struct elf_internal_vernaux *vna_nextptr;	/* vna_next as pointer.  */
201b305b0f1Sespie } Elf_Internal_Vernaux;
202b305b0f1Sespie 
203b305b0f1Sespie /* This structure appears in a SHT_GNU_versym section.  This is not a
204b305b0f1Sespie    standard ELF structure; ELF just uses Elf32_Half.  */
205b305b0f1Sespie 
206b305b0f1Sespie typedef struct elf_internal_versym {
207b305b0f1Sespie   unsigned short vs_vers;
208b305b0f1Sespie } Elf_Internal_Versym;
209b305b0f1Sespie 
210b305b0f1Sespie /* Structure for syminfo section.  */
211b305b0f1Sespie typedef struct
212b305b0f1Sespie {
213b305b0f1Sespie   unsigned short int 	si_boundto;
214b305b0f1Sespie   unsigned short int	si_flags;
215b305b0f1Sespie } Elf_Internal_Syminfo;
216b305b0f1Sespie 
217*007c2a45Smiod /* This structure appears on the stack and in NT_AUXV core file notes.  */
218*007c2a45Smiod typedef struct
219*007c2a45Smiod {
220*007c2a45Smiod   bfd_vma a_type;
221*007c2a45Smiod   bfd_vma a_val;
222*007c2a45Smiod } Elf_Internal_Auxv;
223*007c2a45Smiod 
224b305b0f1Sespie 
225c88b1d6cSniklas /* This structure is used to describe how sections should be assigned
226c88b1d6cSniklas    to program segments.  */
227c88b1d6cSniklas 
228c88b1d6cSniklas struct elf_segment_map
229c88b1d6cSniklas {
230c88b1d6cSniklas   /* Next program segment.  */
231c88b1d6cSniklas   struct elf_segment_map *next;
232c88b1d6cSniklas   /* Program segment type.  */
233c88b1d6cSniklas   unsigned long p_type;
234c88b1d6cSniklas   /* Program segment flags.  */
235c88b1d6cSniklas   unsigned long p_flags;
236c88b1d6cSniklas   /* Program segment physical address.  */
237c88b1d6cSniklas   bfd_vma p_paddr;
238c88b1d6cSniklas   /* Whether the p_flags field is valid; if not, the flags are based
239c88b1d6cSniklas      on the section flags.  */
240c88b1d6cSniklas   unsigned int p_flags_valid : 1;
241c88b1d6cSniklas   /* Whether the p_paddr field is valid; if not, the physical address
242c88b1d6cSniklas      is based on the section lma values.  */
243c88b1d6cSniklas   unsigned int p_paddr_valid : 1;
244c88b1d6cSniklas   /* Whether this segment includes the file header.  */
245c88b1d6cSniklas   unsigned int includes_filehdr : 1;
246c88b1d6cSniklas   /* Whether this segment includes the program headers.  */
247c88b1d6cSniklas   unsigned int includes_phdrs : 1;
248c88b1d6cSniklas   /* Number of sections (may be 0).  */
249c88b1d6cSniklas   unsigned int count;
250c88b1d6cSniklas   /* Sections.  Actual number of elements is in count field.  */
251c88b1d6cSniklas   asection *sections[1];
252c88b1d6cSniklas };
253c88b1d6cSniklas 
2542159047fSniklas #endif /* _ELF_INTERNAL_H */
255