internal.h revision 33965
133965Sjdp/* ELF support for BFD.
233965Sjdp   Copyright (C) 1991, 92, 93, 94, 95, 1997 Free Software Foundation, Inc.
333965Sjdp
433965Sjdp   Written by Fred Fish @ Cygnus Support, from information published
533965Sjdp   in "UNIX System V Release 4, Programmers Guide: ANSI C and
633965Sjdp   Programming Support Tools".
733965Sjdp
833965SjdpThis file is part of BFD, the Binary File Descriptor library.
933965Sjdp
1033965SjdpThis program is free software; you can redistribute it and/or modify
1133965Sjdpit under the terms of the GNU General Public License as published by
1233965Sjdpthe Free Software Foundation; either version 2 of the License, or
1333965Sjdp(at your option) any later version.
1433965Sjdp
1533965SjdpThis program is distributed in the hope that it will be useful,
1633965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1733965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1833965SjdpGNU General Public License for more details.
1933965Sjdp
2033965SjdpYou should have received a copy of the GNU General Public License
2133965Sjdpalong with this program; if not, write to the Free Software
2233965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2333965Sjdp
2433965Sjdp
2533965Sjdp/* This file is part of ELF support for BFD, and contains the portions
2633965Sjdp   that describe how ELF is represented internally in the BFD library.
2733965Sjdp   I.E. it describes the in-memory representation of ELF.  It requires
2833965Sjdp   the elf-common.h file which contains the portions that are common to
2933965Sjdp   both the internal and external representations. */
3033965Sjdp
3133965Sjdp
3233965Sjdp/* NOTE that these structures are not kept in the same order as they appear
3333965Sjdp   in the object file.  In some cases they've been reordered for more optimal
3433965Sjdp   packing under various circumstances.  */
3533965Sjdp
3633965Sjdp#ifndef _ELF_INTERNAL_H
3733965Sjdp#define _ELF_INTERNAL_H
3833965Sjdp
3933965Sjdp/* ELF Header */
4033965Sjdp
4133965Sjdp#define EI_NIDENT	16		/* Size of e_ident[] */
4233965Sjdp
4333965Sjdptypedef struct elf_internal_ehdr {
4433965Sjdp  unsigned char		e_ident[EI_NIDENT];	/* ELF "magic number" */
4533965Sjdp  bfd_vma		e_entry;		/* Entry point virtual address */
4633965Sjdp  bfd_signed_vma	e_phoff;		/* Program header table file offset */
4733965Sjdp  bfd_signed_vma	e_shoff;		/* Section header table file offset */
4833965Sjdp  unsigned long		e_version;		/* Identifies object file version */
4933965Sjdp  unsigned long		e_flags;		/* Processor-specific flags */
5033965Sjdp  unsigned short	e_type;			/* Identifies object file type */
5133965Sjdp  unsigned short	e_machine;		/* Specifies required architecture */
5233965Sjdp  unsigned short	e_ehsize;		/* ELF header size in bytes */
5333965Sjdp  unsigned short	e_phentsize;		/* Program header table entry size */
5433965Sjdp  unsigned short	e_phnum;		/* Program header table entry count */
5533965Sjdp  unsigned short	e_shentsize;		/* Section header table entry size */
5633965Sjdp  unsigned short	e_shnum;		/* Section header table entry count */
5733965Sjdp  unsigned short	e_shstrndx;		/* Section header string table index */
5833965Sjdp} Elf_Internal_Ehdr;
5933965Sjdp
6033965Sjdp#define elf32_internal_ehdr elf_internal_ehdr
6133965Sjdp#define Elf32_Internal_Ehdr Elf_Internal_Ehdr
6233965Sjdp#define elf64_internal_ehdr elf_internal_ehdr
6333965Sjdp#define Elf64_Internal_Ehdr Elf_Internal_Ehdr
6433965Sjdp
6533965Sjdp/* Program header */
6633965Sjdp
6733965Sjdpstruct elf_internal_phdr {
6833965Sjdp  unsigned long	p_type;			/* Identifies program segment type */
6933965Sjdp  unsigned long	p_flags;		/* Segment flags */
7033965Sjdp  bfd_vma	p_offset;		/* Segment file offset */
7133965Sjdp  bfd_vma	p_vaddr;		/* Segment virtual address */
7233965Sjdp  bfd_vma	p_paddr;		/* Segment physical address */
7333965Sjdp  bfd_vma	p_filesz;		/* Segment size in file */
7433965Sjdp  bfd_vma	p_memsz;		/* Segment size in memory */
7533965Sjdp  bfd_vma	p_align;		/* Segment alignment, file & memory */
7633965Sjdp};
7733965Sjdp
7833965Sjdptypedef struct elf_internal_phdr Elf_Internal_Phdr;
7933965Sjdp#define elf32_internal_phdr elf_internal_phdr
8033965Sjdp#define Elf32_Internal_Phdr Elf_Internal_Phdr
8133965Sjdp#define elf64_internal_phdr elf_internal_phdr
8233965Sjdp#define Elf64_Internal_Phdr Elf_Internal_Phdr
8333965Sjdp
8433965Sjdp/* Section header */
8533965Sjdp
8633965Sjdptypedef struct elf_internal_shdr {
8733965Sjdp  unsigned int	sh_name;		/* Section name, index in string tbl */
8833965Sjdp  unsigned int	sh_type;		/* Type of section */
8933965Sjdp  bfd_vma	sh_flags;		/* Miscellaneous section attributes */
9033965Sjdp  bfd_vma	sh_addr;		/* Section virtual addr at execution */
9133965Sjdp  bfd_size_type	sh_size;		/* Size of section in bytes */
9233965Sjdp  bfd_size_type	sh_entsize;		/* Entry size if section holds table */
9333965Sjdp  unsigned long	sh_link;		/* Index of another section */
9433965Sjdp  unsigned long	sh_info;		/* Additional section information */
9533965Sjdp  file_ptr	sh_offset;		/* Section file offset */
9633965Sjdp  unsigned int	sh_addralign;		/* Section alignment */
9733965Sjdp
9833965Sjdp  /* The internal rep also has some cached info associated with it. */
9933965Sjdp  asection *	bfd_section;		/* Associated BFD section.  */
10033965Sjdp  PTR		contents;		/* Section contents.  */
10133965Sjdp} Elf_Internal_Shdr;
10233965Sjdp
10333965Sjdp#define elf32_internal_shdr elf_internal_shdr
10433965Sjdp#define Elf32_Internal_Shdr Elf_Internal_Shdr
10533965Sjdp#define elf64_internal_shdr elf_internal_shdr
10633965Sjdp#define Elf64_Internal_Shdr Elf_Internal_Shdr
10733965Sjdp
10833965Sjdp/* Symbol table entry */
10933965Sjdp
11033965Sjdpstruct elf_internal_sym {
11133965Sjdp  bfd_vma	st_value;		/* Value of the symbol */
11233965Sjdp  bfd_vma	st_size;		/* Associated symbol size */
11333965Sjdp  unsigned long	st_name;		/* Symbol name, index in string tbl */
11433965Sjdp  unsigned char	st_info;		/* Type and binding attributes */
11533965Sjdp  unsigned char	st_other;		/* No defined meaning, 0 */
11633965Sjdp  unsigned short st_shndx;		/* Associated section index */
11733965Sjdp};
11833965Sjdp
11933965Sjdptypedef struct elf_internal_sym Elf_Internal_Sym;
12033965Sjdp
12133965Sjdp#define elf32_internal_sym elf_internal_sym
12233965Sjdp#define elf64_internal_sym elf_internal_sym
12333965Sjdp#define Elf32_Internal_Sym Elf_Internal_Sym
12433965Sjdp#define Elf64_Internal_Sym Elf_Internal_Sym
12533965Sjdp
12633965Sjdp/* Note segments */
12733965Sjdp
12833965Sjdptypedef struct elf_internal_note {
12933965Sjdp  unsigned long	namesz;			/* Size of entry's owner string */
13033965Sjdp  unsigned long	descsz;			/* Size of the note descriptor */
13133965Sjdp  unsigned long	type;			/* Interpretation of the descriptor */
13233965Sjdp  char		name[1];		/* Start of the name+desc data */
13333965Sjdp} Elf_Internal_Note;
13433965Sjdp#define Elf32_Internal_Note	Elf_Internal_Note
13533965Sjdp#define elf32_internal_note	elf_internal_note
13633965Sjdp
13733965Sjdp/* Relocation Entries */
13833965Sjdp
13933965Sjdptypedef struct elf_internal_rel {
14033965Sjdp  bfd_vma	r_offset;	/* Location at which to apply the action */
14133965Sjdp  /* This needs to support 64-bit values in elf64.  */
14233965Sjdp  bfd_vma	r_info;		/* index and type of relocation */
14333965Sjdp} Elf_Internal_Rel;
14433965Sjdp
14533965Sjdp#define elf32_internal_rel elf_internal_rel
14633965Sjdp#define Elf32_Internal_Rel Elf_Internal_Rel
14733965Sjdp#define elf64_internal_rel elf_internal_rel
14833965Sjdp#define Elf64_Internal_Rel Elf_Internal_Rel
14933965Sjdp
15033965Sjdptypedef struct elf_internal_rela {
15133965Sjdp  bfd_vma	r_offset;	/* Location at which to apply the action */
15233965Sjdp  bfd_vma	r_info;		/* Index and Type of relocation */
15333965Sjdp  bfd_signed_vma r_addend;	/* Constant addend used to compute value */
15433965Sjdp} Elf_Internal_Rela;
15533965Sjdp
15633965Sjdp#define elf32_internal_rela elf_internal_rela
15733965Sjdp#define elf64_internal_rela elf_internal_rela
15833965Sjdp#define Elf32_Internal_Rela Elf_Internal_Rela
15933965Sjdp#define Elf64_Internal_Rela Elf_Internal_Rela
16033965Sjdp
16133965Sjdp/* dynamic section structure */
16233965Sjdp
16333965Sjdptypedef struct elf_internal_dyn {
16433965Sjdp  /* This needs to support 64-bit values in elf64.  */
16533965Sjdp  bfd_vma d_tag;		/* entry tag value */
16633965Sjdp  union {
16733965Sjdp    /* This needs to support 64-bit values in elf64.  */
16833965Sjdp    bfd_vma	d_val;
16933965Sjdp    bfd_vma	d_ptr;
17033965Sjdp  } d_un;
17133965Sjdp} Elf_Internal_Dyn;
17233965Sjdp
17333965Sjdp#define elf32_internal_dyn elf_internal_dyn
17433965Sjdp#define elf64_internal_dyn elf_internal_dyn
17533965Sjdp#define Elf32_Internal_Dyn Elf_Internal_Dyn
17633965Sjdp#define Elf64_Internal_Dyn Elf_Internal_Dyn
17733965Sjdp
17833965Sjdp/* This structure appears in a SHT_GNU_verdef section.  */
17933965Sjdp
18033965Sjdptypedef struct elf_internal_verdef {
18133965Sjdp  unsigned short vd_version;	/* Version number of structure.  */
18233965Sjdp  unsigned short vd_flags;	/* Flags (VER_FLG_*).  */
18333965Sjdp  unsigned short vd_ndx;	/* Version index.  */
18433965Sjdp  unsigned short vd_cnt;	/* Number of verdaux entries.  */
18533965Sjdp  unsigned long	 vd_hash;	/* Hash of name.  */
18633965Sjdp  unsigned long	 vd_aux;	/* Offset to verdaux entries.  */
18733965Sjdp  unsigned long	 vd_next;	/* Offset to next verdef.  */
18833965Sjdp
18933965Sjdp  /* These fields are set up when BFD reads in the structure.  FIXME:
19033965Sjdp     It would be cleaner to store these in a different structure.  */
19133965Sjdp  bfd			      *vd_bfd;		/* BFD.  */
19233965Sjdp  const char		      *vd_nodename;	/* Version name.  */
19333965Sjdp  struct elf_internal_verdef  *vd_nextdef;	/* vd_next as pointer.  */
19433965Sjdp  struct elf_internal_verdaux *vd_auxptr;	/* vd_aux as pointer.  */
19533965Sjdp  unsigned int		       vd_exp_refno;	/* Used by the linker.  */
19633965Sjdp} Elf_Internal_Verdef;
19733965Sjdp
19833965Sjdp/* This structure appears in a SHT_GNU_verdef section.  */
19933965Sjdp
20033965Sjdptypedef struct elf_internal_verdaux {
20133965Sjdp  unsigned long vda_name;	/* String table offset of name.  */
20233965Sjdp  unsigned long vda_next;	/* Offset to next verdaux.  */
20333965Sjdp
20433965Sjdp  /* These fields are set up when BFD reads in the structure.  FIXME:
20533965Sjdp     It would be cleaner to store these in a different structure.  */
20633965Sjdp  const char *vda_nodename;			/* vda_name as pointer.  */
20733965Sjdp  struct elf_internal_verdaux *vda_nextptr;	/* vda_next as pointer.  */
20833965Sjdp} Elf_Internal_Verdaux;
20933965Sjdp
21033965Sjdp/* This structure appears in a SHT_GNU_verneed section.  */
21133965Sjdp
21233965Sjdptypedef struct elf_internal_verneed {
21333965Sjdp  unsigned short vn_version;	/* Version number of structure.  */
21433965Sjdp  unsigned short vn_cnt;	/* Number of vernaux entries.  */
21533965Sjdp  unsigned long	 vn_file;	/* String table offset of library name.  */
21633965Sjdp  unsigned long	 vn_aux;	/* Offset to vernaux entries.  */
21733965Sjdp  unsigned long	 vn_next;	/* Offset to next verneed.  */
21833965Sjdp
21933965Sjdp  /* These fields are set up when BFD reads in the structure.  FIXME:
22033965Sjdp     It would be cleaner to store these in a different structure.  */
22133965Sjdp  bfd			      *vn_bfd;		/* BFD.  */
22233965Sjdp  const char                  *vn_filename;	/* vn_file as pointer.  */
22333965Sjdp  struct elf_internal_vernaux *vn_auxptr;	/* vn_aux as pointer.  */
22433965Sjdp  struct elf_internal_verneed *vn_nextref;	/* vn_nextref as pointer.  */
22533965Sjdp} Elf_Internal_Verneed;
22633965Sjdp
22733965Sjdp/* This structure appears in a SHT_GNU_verneed section.  */
22833965Sjdp
22933965Sjdptypedef struct elf_internal_vernaux {
23033965Sjdp  unsigned long	 vna_hash;	/* Hash of dependency name.  */
23133965Sjdp  unsigned short vna_flags;	/* Flags (VER_FLG_*).  */
23233965Sjdp  unsigned short vna_other;	/* Unused.  */
23333965Sjdp  unsigned long	 vna_name;	/* String table offset to version name.  */
23433965Sjdp  unsigned long	 vna_next;	/* Offset to next vernaux.  */
23533965Sjdp
23633965Sjdp  /* These fields are set up when BFD reads in the structure.  FIXME:
23733965Sjdp     It would be cleaner to store these in a different structure.  */
23833965Sjdp  const char                  *vna_nodename;	/* vna_name as pointer.  */
23933965Sjdp  struct elf_internal_vernaux *vna_nextptr;	/* vna_next as pointer.  */
24033965Sjdp} Elf_Internal_Vernaux;
24133965Sjdp
24233965Sjdp/* This structure appears in a SHT_GNU_versym section.  This is not a
24333965Sjdp   standard ELF structure; ELF just uses Elf32_Half.  */
24433965Sjdp
24533965Sjdptypedef struct elf_internal_versym {
24633965Sjdp  unsigned short vs_vers;
24733965Sjdp} Elf_Internal_Versym;
24833965Sjdp
24933965Sjdp#define elf32_internal_verdef elf_internal_verdef
25033965Sjdp#define elf64_internal_verdef elf_internal_verdef
25133965Sjdp#define elf32_internal_verdaux elf_internal_verdaux
25233965Sjdp#define elf64_internal_verdaux elf_internal_verdaux
25333965Sjdp#define elf32_internal_verneed elf_internal_verneed
25433965Sjdp#define elf64_internal_verneed elf_internal_verneed
25533965Sjdp#define elf32_internal_vernaux elf_internal_vernaux
25633965Sjdp#define elf64_internal_vernaux elf_internal_vernaux
25733965Sjdp#define elf32_internal_versym elf_internal_versym
25833965Sjdp#define elf64_internal_versym elf_internal_versym
25933965Sjdp
26033965Sjdp#define Elf32_Internal_Verdef Elf_Internal_Verdef
26133965Sjdp#define Elf64_Internal_Verdef Elf_Internal_Verdef
26233965Sjdp#define Elf32_Internal_Verdaux Elf_Internal_Verdaux
26333965Sjdp#define Elf64_Internal_Verdaux Elf_Internal_Verdaux
26433965Sjdp#define Elf32_Internal_Verneed Elf_Internal_Verneed
26533965Sjdp#define Elf64_Internal_Verneed Elf_Internal_Verneed
26633965Sjdp#define Elf32_Internal_Vernaux Elf_Internal_Vernaux
26733965Sjdp#define Elf64_Internal_Vernaux Elf_Internal_Vernaux
26833965Sjdp#define Elf32_Internal_Versym Elf_Internal_Versym
26933965Sjdp#define Elf64_Internal_Versym Elf_Internal_Versym
27033965Sjdp
27133965Sjdp/* This structure is used to describe how sections should be assigned
27233965Sjdp   to program segments.  */
27333965Sjdp
27433965Sjdpstruct elf_segment_map
27533965Sjdp{
27633965Sjdp  /* Next program segment.  */
27733965Sjdp  struct elf_segment_map *next;
27833965Sjdp  /* Program segment type.  */
27933965Sjdp  unsigned long p_type;
28033965Sjdp  /* Program segment flags.  */
28133965Sjdp  unsigned long p_flags;
28233965Sjdp  /* Program segment physical address.  */
28333965Sjdp  bfd_vma p_paddr;
28433965Sjdp  /* Whether the p_flags field is valid; if not, the flags are based
28533965Sjdp     on the section flags.  */
28633965Sjdp  unsigned int p_flags_valid : 1;
28733965Sjdp  /* Whether the p_paddr field is valid; if not, the physical address
28833965Sjdp     is based on the section lma values.  */
28933965Sjdp  unsigned int p_paddr_valid : 1;
29033965Sjdp  /* Whether this segment includes the file header.  */
29133965Sjdp  unsigned int includes_filehdr : 1;
29233965Sjdp  /* Whether this segment includes the program headers.  */
29333965Sjdp  unsigned int includes_phdrs : 1;
29433965Sjdp  /* Number of sections (may be 0).  */
29533965Sjdp  unsigned int count;
29633965Sjdp  /* Sections.  Actual number of elements is in count field.  */
29733965Sjdp  asection *sections[1];
29833965Sjdp};
29933965Sjdp
30033965Sjdp#endif /* _ELF_INTERNAL_H */
301