133965Sjdp/* ELF support for BFD.
2218822Sdim   Copyright 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2001, 2003, 2005
378828Sobrien   Free Software Foundation, Inc.
433965Sjdp
533965Sjdp   Written by Fred Fish @ Cygnus Support, from information published
633965Sjdp   in "UNIX System V Release 4, Programmers Guide: ANSI C and
733965Sjdp   Programming Support Tools".
833965Sjdp
933965SjdpThis file is part of BFD, the Binary File Descriptor library.
1033965Sjdp
1133965SjdpThis program is free software; you can redistribute it and/or modify
1233965Sjdpit under the terms of the GNU General Public License as published by
1333965Sjdpthe Free Software Foundation; either version 2 of the License, or
1433965Sjdp(at your option) any later version.
1533965Sjdp
1633965SjdpThis program is distributed in the hope that it will be useful,
1733965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1833965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1933965SjdpGNU General Public License for more details.
2033965Sjdp
2133965SjdpYou should have received a copy of the GNU General Public License
2233965Sjdpalong with this program; if not, write to the Free Software
23218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2433965Sjdp
2533965Sjdp
2633965Sjdp/* This file is part of ELF support for BFD, and contains the portions
2733965Sjdp   that describe how ELF is represented externally by the BFD library.
2833965Sjdp   I.E. it describes the in-file representation of ELF.  It requires
2978828Sobrien   the elf/common.h file which contains the portions that are common to
3033965Sjdp   both the internal and external representations. */
3160484Sobrien
3233965Sjdp/* The 64-bit stuff is kind of random.  Perhaps someone will publish a
3333965Sjdp   spec someday.  */
3433965Sjdp
3533965Sjdp#ifndef _ELF_EXTERNAL_H
3633965Sjdp#define _ELF_EXTERNAL_H
3733965Sjdp
3833965Sjdp/* ELF Header (32-bit implementations) */
3933965Sjdp
4033965Sjdptypedef struct {
4133965Sjdp  unsigned char	e_ident[16];		/* ELF "magic number" */
4233965Sjdp  unsigned char	e_type[2];		/* Identifies object file type */
4333965Sjdp  unsigned char	e_machine[2];		/* Specifies required architecture */
4433965Sjdp  unsigned char	e_version[4];		/* Identifies object file version */
4533965Sjdp  unsigned char	e_entry[4];		/* Entry point virtual address */
4633965Sjdp  unsigned char	e_phoff[4];		/* Program header table file offset */
4733965Sjdp  unsigned char	e_shoff[4];		/* Section header table file offset */
4833965Sjdp  unsigned char	e_flags[4];		/* Processor-specific flags */
4933965Sjdp  unsigned char	e_ehsize[2];		/* ELF header size in bytes */
5033965Sjdp  unsigned char	e_phentsize[2];		/* Program header table entry size */
5133965Sjdp  unsigned char	e_phnum[2];		/* Program header table entry count */
5233965Sjdp  unsigned char	e_shentsize[2];		/* Section header table entry size */
5333965Sjdp  unsigned char	e_shnum[2];		/* Section header table entry count */
5433965Sjdp  unsigned char	e_shstrndx[2];		/* Section header string table index */
5533965Sjdp} Elf32_External_Ehdr;
5633965Sjdp
5733965Sjdptypedef struct {
5833965Sjdp  unsigned char	e_ident[16];		/* ELF "magic number" */
5933965Sjdp  unsigned char	e_type[2];		/* Identifies object file type */
6033965Sjdp  unsigned char	e_machine[2];		/* Specifies required architecture */
6133965Sjdp  unsigned char	e_version[4];		/* Identifies object file version */
6233965Sjdp  unsigned char	e_entry[8];		/* Entry point virtual address */
6333965Sjdp  unsigned char	e_phoff[8];		/* Program header table file offset */
6433965Sjdp  unsigned char	e_shoff[8];		/* Section header table file offset */
6533965Sjdp  unsigned char	e_flags[4];		/* Processor-specific flags */
6633965Sjdp  unsigned char	e_ehsize[2];		/* ELF header size in bytes */
6733965Sjdp  unsigned char	e_phentsize[2];		/* Program header table entry size */
6833965Sjdp  unsigned char	e_phnum[2];		/* Program header table entry count */
6933965Sjdp  unsigned char	e_shentsize[2];		/* Section header table entry size */
7033965Sjdp  unsigned char	e_shnum[2];		/* Section header table entry count */
7133965Sjdp  unsigned char	e_shstrndx[2];		/* Section header string table index */
7233965Sjdp} Elf64_External_Ehdr;
7333965Sjdp
7433965Sjdp/* Program header */
7533965Sjdp
7633965Sjdptypedef struct {
7733965Sjdp  unsigned char	p_type[4];		/* Identifies program segment type */
7833965Sjdp  unsigned char	p_offset[4];		/* Segment file offset */
7933965Sjdp  unsigned char	p_vaddr[4];		/* Segment virtual address */
8033965Sjdp  unsigned char	p_paddr[4];		/* Segment physical address */
8133965Sjdp  unsigned char	p_filesz[4];		/* Segment size in file */
8233965Sjdp  unsigned char	p_memsz[4];		/* Segment size in memory */
8333965Sjdp  unsigned char	p_flags[4];		/* Segment flags */
8433965Sjdp  unsigned char	p_align[4];		/* Segment alignment, file & memory */
8533965Sjdp} Elf32_External_Phdr;
8633965Sjdp
8733965Sjdptypedef struct {
8833965Sjdp  unsigned char	p_type[4];		/* Identifies program segment type */
8933965Sjdp  unsigned char	p_flags[4];		/* Segment flags */
9033965Sjdp  unsigned char	p_offset[8];		/* Segment file offset */
9133965Sjdp  unsigned char	p_vaddr[8];		/* Segment virtual address */
9233965Sjdp  unsigned char	p_paddr[8];		/* Segment physical address */
9333965Sjdp  unsigned char	p_filesz[8];		/* Segment size in file */
9433965Sjdp  unsigned char	p_memsz[8];		/* Segment size in memory */
9533965Sjdp  unsigned char	p_align[8];		/* Segment alignment, file & memory */
9633965Sjdp} Elf64_External_Phdr;
9733965Sjdp
9833965Sjdp/* Section header */
9933965Sjdp
10033965Sjdptypedef struct {
10133965Sjdp  unsigned char	sh_name[4];		/* Section name, index in string tbl */
10233965Sjdp  unsigned char	sh_type[4];		/* Type of section */
10333965Sjdp  unsigned char	sh_flags[4];		/* Miscellaneous section attributes */
10433965Sjdp  unsigned char	sh_addr[4];		/* Section virtual addr at execution */
10533965Sjdp  unsigned char	sh_offset[4];		/* Section file offset */
10633965Sjdp  unsigned char	sh_size[4];		/* Size of section in bytes */
10733965Sjdp  unsigned char	sh_link[4];		/* Index of another section */
10833965Sjdp  unsigned char	sh_info[4];		/* Additional section information */
10933965Sjdp  unsigned char	sh_addralign[4];	/* Section alignment */
11033965Sjdp  unsigned char	sh_entsize[4];		/* Entry size if section holds table */
11133965Sjdp} Elf32_External_Shdr;
11233965Sjdp
11333965Sjdptypedef struct {
11433965Sjdp  unsigned char	sh_name[4];		/* Section name, index in string tbl */
11533965Sjdp  unsigned char	sh_type[4];		/* Type of section */
11633965Sjdp  unsigned char	sh_flags[8];		/* Miscellaneous section attributes */
11733965Sjdp  unsigned char	sh_addr[8];		/* Section virtual addr at execution */
11833965Sjdp  unsigned char	sh_offset[8];		/* Section file offset */
11933965Sjdp  unsigned char	sh_size[8];		/* Size of section in bytes */
12033965Sjdp  unsigned char	sh_link[4];		/* Index of another section */
12133965Sjdp  unsigned char	sh_info[4];		/* Additional section information */
12233965Sjdp  unsigned char	sh_addralign[8];	/* Section alignment */
12333965Sjdp  unsigned char	sh_entsize[8];		/* Entry size if section holds table */
12433965Sjdp} Elf64_External_Shdr;
12533965Sjdp
12633965Sjdp/* Symbol table entry */
12733965Sjdp
12833965Sjdptypedef struct {
12933965Sjdp  unsigned char	st_name[4];		/* Symbol name, index in string tbl */
13033965Sjdp  unsigned char	st_value[4];		/* Value of the symbol */
13133965Sjdp  unsigned char	st_size[4];		/* Associated symbol size */
13233965Sjdp  unsigned char	st_info[1];		/* Type and binding attributes */
13333965Sjdp  unsigned char	st_other[1];		/* No defined meaning, 0 */
13433965Sjdp  unsigned char	st_shndx[2];		/* Associated section index */
13533965Sjdp} Elf32_External_Sym;
13633965Sjdp
13733965Sjdptypedef struct {
13833965Sjdp  unsigned char	st_name[4];		/* Symbol name, index in string tbl */
13933965Sjdp  unsigned char	st_info[1];		/* Type and binding attributes */
14033965Sjdp  unsigned char	st_other[1];		/* No defined meaning, 0 */
14133965Sjdp  unsigned char	st_shndx[2];		/* Associated section index */
14233965Sjdp  unsigned char	st_value[8];		/* Value of the symbol */
14333965Sjdp  unsigned char	st_size[8];		/* Associated symbol size */
14433965Sjdp} Elf64_External_Sym;
14533965Sjdp
14689857Sobrientypedef struct {
14789857Sobrien  unsigned char est_shndx[4];		/* Section index */
14889857Sobrien} Elf_External_Sym_Shndx;
14989857Sobrien
15033965Sjdp/* Note segments */
15133965Sjdp
15233965Sjdptypedef struct {
15333965Sjdp  unsigned char	namesz[4];		/* Size of entry's owner string */
15433965Sjdp  unsigned char	descsz[4];		/* Size of the note descriptor */
15533965Sjdp  unsigned char	type[4];		/* Interpretation of the descriptor */
15633965Sjdp  char		name[1];		/* Start of the name+desc data */
15733965Sjdp} Elf_External_Note;
15833965Sjdp
15933965Sjdp/* Relocation Entries */
16033965Sjdptypedef struct {
16133965Sjdp  unsigned char r_offset[4];	/* Location at which to apply the action */
16233965Sjdp  unsigned char	r_info[4];	/* index and type of relocation */
16333965Sjdp} Elf32_External_Rel;
16433965Sjdp
16533965Sjdptypedef struct {
16633965Sjdp  unsigned char r_offset[4];	/* Location at which to apply the action */
16733965Sjdp  unsigned char	r_info[4];	/* index and type of relocation */
16833965Sjdp  unsigned char	r_addend[4];	/* Constant addend used to compute value */
16933965Sjdp} Elf32_External_Rela;
17033965Sjdp
17133965Sjdptypedef struct {
17233965Sjdp  unsigned char r_offset[8];	/* Location at which to apply the action */
17333965Sjdp  unsigned char	r_info[8];	/* index and type of relocation */
17433965Sjdp} Elf64_External_Rel;
17533965Sjdp
17633965Sjdptypedef struct {
17733965Sjdp  unsigned char r_offset[8];	/* Location at which to apply the action */
17833965Sjdp  unsigned char	r_info[8];	/* index and type of relocation */
17933965Sjdp  unsigned char	r_addend[8];	/* Constant addend used to compute value */
18033965Sjdp} Elf64_External_Rela;
18133965Sjdp
18233965Sjdp/* dynamic section structure */
18333965Sjdp
18433965Sjdptypedef struct {
18533965Sjdp  unsigned char	d_tag[4];		/* entry tag value */
18633965Sjdp  union {
18733965Sjdp    unsigned char	d_val[4];
18833965Sjdp    unsigned char	d_ptr[4];
18933965Sjdp  } d_un;
19033965Sjdp} Elf32_External_Dyn;
19133965Sjdp
19233965Sjdptypedef struct {
19333965Sjdp  unsigned char	d_tag[8];		/* entry tag value */
19433965Sjdp  union {
19533965Sjdp    unsigned char	d_val[8];
19633965Sjdp    unsigned char	d_ptr[8];
19733965Sjdp  } d_un;
19833965Sjdp} Elf64_External_Dyn;
19933965Sjdp
20033965Sjdp/* The version structures are currently size independent.  They are
20133965Sjdp   named without a 32 or 64.  If that ever changes, these structures
20233965Sjdp   will need to be renamed.  */
20333965Sjdp
20433965Sjdp/* This structure appears in a SHT_GNU_verdef section.  */
20533965Sjdp
20633965Sjdptypedef struct {
20733965Sjdp  unsigned char		vd_version[2];
20833965Sjdp  unsigned char		vd_flags[2];
20933965Sjdp  unsigned char		vd_ndx[2];
21033965Sjdp  unsigned char		vd_cnt[2];
21133965Sjdp  unsigned char		vd_hash[4];
21233965Sjdp  unsigned char		vd_aux[4];
21333965Sjdp  unsigned char		vd_next[4];
21433965Sjdp} Elf_External_Verdef;
21533965Sjdp
21633965Sjdp/* This structure appears in a SHT_GNU_verdef section.  */
21733965Sjdp
21833965Sjdptypedef struct {
21933965Sjdp  unsigned char		vda_name[4];
22033965Sjdp  unsigned char		vda_next[4];
22133965Sjdp} Elf_External_Verdaux;
22233965Sjdp
22333965Sjdp/* This structure appears in a SHT_GNU_verneed section.  */
22433965Sjdp
22533965Sjdptypedef struct {
22633965Sjdp  unsigned char		vn_version[2];
22733965Sjdp  unsigned char		vn_cnt[2];
22833965Sjdp  unsigned char		vn_file[4];
22933965Sjdp  unsigned char		vn_aux[4];
23033965Sjdp  unsigned char		vn_next[4];
23133965Sjdp} Elf_External_Verneed;
23233965Sjdp
23333965Sjdp/* This structure appears in a SHT_GNU_verneed section.  */
23433965Sjdp
23533965Sjdptypedef struct {
23633965Sjdp  unsigned char		vna_hash[4];
23733965Sjdp  unsigned char		vna_flags[2];
23833965Sjdp  unsigned char		vna_other[2];
23933965Sjdp  unsigned char		vna_name[4];
24033965Sjdp  unsigned char		vna_next[4];
24133965Sjdp} Elf_External_Vernaux;
24233965Sjdp
24333965Sjdp/* This structure appears in a SHT_GNU_versym section.  This is not a
24433965Sjdp   standard ELF structure; ELF just uses Elf32_Half.  */
24533965Sjdp
24633965Sjdptypedef struct {
24733965Sjdp  unsigned char		vs_vers[2];
248218822Sdim} ATTRIBUTE_PACKED  Elf_External_Versym;
24933965Sjdp
25060484Sobrien/* Structure for syminfo section.  */
25160484Sobrientypedef struct
25260484Sobrien{
25360484Sobrien  unsigned char		si_boundto[2];
25460484Sobrien  unsigned char		si_flags[2];
25560484Sobrien} Elf_External_Syminfo;
25660484Sobrien
257130561Sobrien
258130561Sobrien/* This structure appears on the stack and in NT_AUXV core file notes.  */
259130561Sobrientypedef struct
260130561Sobrien{
261130561Sobrien  unsigned char		a_type[4];
262130561Sobrien  unsigned char		a_val[4];
263130561Sobrien} Elf32_External_Auxv;
264130561Sobrien
265130561Sobrientypedef struct
266130561Sobrien{
267130561Sobrien  unsigned char		a_type[8];
268130561Sobrien  unsigned char		a_val[8];
269130561Sobrien} Elf64_External_Auxv;
270130561Sobrien
271218822Sdim/* Size of SHT_GROUP section entry.  */
272130561Sobrien
273218822Sdim#define GRP_ENTRY_SIZE		4
274218822Sdim
27533965Sjdp#endif /* _ELF_EXTERNAL_H */
276