binary: Check in linux binary image
[sdk-tools/dspcoreparse.git] / elf32.h
1 /*
2 * elf32.h
3 *
4 * Basic Data Structures for 32-bit ELF Object Format Files
5 *
6 * The data structures in this file come primarily from this specification:
7 *
8 *    Tool Interface Standard (TIS)
9 *    Executable and Linking Format (ELF) Specification
10 *    Version 1.2
11 *
12 *    TIS Committee
13 *    May 1995
14 *
15 * Additions and enhancements from this specification are also included:
16 *
17 *    System V Application Binary Interface
18 *    DRAFT 17
19 *    December 2003
20 *
21 *    http://sco.com/developers/gabi/2003-12-17/contents.html
22 *
23 *
24 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
25 *
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 *
31 * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 *
34 * Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the
37 * distribution.
38 *
39 * Neither the name of Texas Instruments Incorporated nor the names of
40 * its contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
55 */
57 #ifndef ELF32_H
58 #define ELF32_H
60 #include <stdint.h>
62 /*---------------------------------------------------------------------------*/
63 /* 32-Bit Data Types (Figure 1-2, page 1-2)                                  */
64 /*---------------------------------------------------------------------------*/
65 typedef uint32_t Elf32_Addr;
66 typedef uint16_t Elf32_Half;
67 typedef uint32_t Elf32_Off;
68 typedef  int32_t Elf32_Sword;
69 typedef uint32_t Elf32_Word;
72 /*****************************************************************************/
73 /* ELF Header                                                                */
74 /* PP. 1-4                                                                   */
75 /*****************************************************************************/
77 /*---------------------------------------------------------------------------*/
78 /* ELF Identification Indexes (indexes into Elf32_Ehdr.e_ident[] below)      */
79 /*---------------------------------------------------------------------------*/
80 enum
81 {
82    EI_MAG0       = 0,   /* File identification          */
83    EI_MAG1       = 1,   /* File identification          */
84    EI_MAG2       = 2,   /* File identification          */
85    EI_MAG3       = 3,   /* File identification          */
86    EI_CLASS      = 4,   /* File class                   */
87    EI_DATA       = 5,   /* Data encoding                */
88    EI_VERSION    = 6,   /* File version                 */
89    EI_OSABI      = 7,   /* Operating system / ABI       */
90    EI_ABIVERSION = 8,   /* ABI version                  */
91    EI_PAD        = 9,   /* Start of padding bytes       */
92    EI_NIDENT     = 16   /* Size of Elf32_Ehdr.e_ident[] */
93 };
96 /*---------------------------------------------------------------------------*/
97 /* ELF Header Data Structure                                                 */
98 /*---------------------------------------------------------------------------*/
99 struct Elf32_Ehdr
101    uint8_t     e_ident[EI_NIDENT];   /* ELF Magic Number                     */
102    Elf32_Half  e_type;               /* Object File Type                     */
103    Elf32_Half  e_machine;            /* Target Processor                     */
104    Elf32_Word  e_version;            /* Object File Version                  */
105    Elf32_Addr  e_entry;              /* Entry Point                          */
106    Elf32_Off   e_phoff;              /* Program Header Table Offset          */
107    Elf32_Off   e_shoff;              /* Section Header Table Offset          */
108    Elf32_Word  e_flags;              /* Processor-Specific Flags             */
109    Elf32_Half  e_ehsize;             /* Size of ELF header                   */
110    Elf32_Half  e_phentsize;          /* Size of a Program Header             */
111    Elf32_Half  e_phnum;              /* # Entries in Program Header Table    */
112    Elf32_Half  e_shentsize;          /* Size of a Section Header             */
113    Elf32_Half  e_shnum;              /* # Entries in Section Header Table    */
114    Elf32_Half  e_shstrndx;           /* Section Name String Table Section    */
115 };
118 /*---------------------------------------------------------------------------*/
119 /* Object File Types (value of "e_type")                                     */
120 /*---------------------------------------------------------------------------*/
121 enum
123    ET_NONE   = 0,       /* No file type                   */
124    ET_REL    = 1,       /* Relocatable file               */
125    ET_EXEC   = 2,       /* Executable file                */
126    ET_DYN    = 3,       /* Shared object file             */
127    ET_CORE   = 4,       /* Core file                      */
128    ET_LOOS   = 0xfe00,  /* First OS-specific value        */
129    ET_HIPS   = 0xfeff,  /* Last  OS-specific value        */
130    ET_LOPROC = 0xff00,  /* First processor-specific value */
131    ET_HIPROC = 0xffff   /* Last  processor-specific value */
132 };
135 /*---------------------------------------------------------------------------*/
136 /* Target Processors (value of "e_machine")                                  */
137 /*---------------------------------------------------------------------------*/
138 enum
140    EM_NONE        =   0,  /* No machine                                      */
141    EM_M32         =   1,  /* AT&T WE 32100                                   */
142    EM_SPARC       =   2,  /* SPARC                                           */
143    EM_386         =   3,  /* Intel 80386                                     */
144    EM_68K         =   4,  /* Motorola 68000                                  */
145    EM_88K         =   5,  /* Motorola 88000                                  */
146    EM_860         =   7,  /* Intel 80860                                     */
147    EM_MIPS        =   8,  /* MIPS I Architecture                             */
148    EM_S370        =   9,  /* IBM System/370 Processor                        */
149    EM_MIPS_RS3_LE =  10,  /* MIPS RS3000 Little-endian                       */
150    EM_PARISC      =  15,  /* Hewlett-Packard PA-RISC                         */
151    EM_VPP500      =  17,  /* Fujitsu VPP500                                  */
152    EM_SPARC32PLUS =  18,  /* Enhanced instruction set SPARC                  */
153    EM_960         =  19,  /* Intel 80960                                     */
154    EM_PPC         =  20,  /* PowerPC                                         */
155    EM_PPC64       =  21,  /* 64-bit PowerPC                                  */
156    EM_S390        =  22,  /* IBM System/390 Processor                        */
157    EM_V800        =  36,  /* NEC V800                                        */
158    EM_FR20        =  37,  /* Fujitsu FR20                                    */
159    EM_RH32        =  38,  /* TRW RH-32                                       */
160    EM_RCE         =  39,  /* Motorola RCE                                    */
161    EM_ARM         =  40,  /* Advanced RISC Machines ARM                      */
162    EM_ALPHA       =  41,  /* Digital Alpha                                   */
163    EM_SH          =  42,  /* Hitachi SH                                      */
164    EM_SPARCV9     =  43,  /* SPARC Version 9                                 */
165    EM_TRICORE     =  44,  /* Siemens TriCore embedded processor              */
166    EM_ARC         =  45,  /* "Argonaut RISC Core, Argonaut Technologies Inc. */
167    EM_H8_300      =  46,  /* Hitachi H8/300                                  */
168    EM_H8_300H     =  47,  /* Hitachi H8/300H                                 */
169    EM_H8S         =  48,  /* Hitachi H8S                                     */
170    EM_H8_500      =  49,  /* Hitachi H8/500                                  */
171    EM_IA_64       =  50,  /* Intel IA-64 processor architecture              */
172    EM_MIPS_X      =  51,  /* Stanford MIPS-X                                 */
173    EM_COLDFIRE    =  52,  /* Motorola ColdFire                               */
174    EM_68HC12      =  53,  /* Motorola M68HC12                                */
175    EM_MMA         =  54,  /* Fujitsu MMA Multimedia Accelerator              */
176    EM_PCP         =  55,  /* Siemens PCP                                     */
177    EM_NCPU        =  56,  /* Sony nCPU embedded RISC processor               */
178    EM_NDR1        =  57,  /* Denso NDR1 microprocessor                       */
179    EM_STARCORE    =  58,  /* Motorola Star*Core processor                    */
180    EM_ME16        =  59,  /* Toyota ME16 processor                           */
181    EM_ST100       =  60,  /* STMicroelectronics ST100 processor              */
182    EM_TINYJ       =  61,  /* Advanced Logic Corp. TinyJ embedded processor f */
183    EM_X86_64      =  62,  /* AMD x86-64 architecture                         */
184    EM_PDSP        =  63,  /* Sony DSP Processor                              */
185    EM_PDP10       =  64,  /* Digital Equipment Corp. PDP-10                  */
186    EM_PDP11       =  65,  /* Digital Equipment Corp. PDP-11                  */
187    EM_FX66        =  66,  /* Siemens FX66 microcontroller                    */
188    EM_ST9PLUS     =  67,  /* STMicroelectronics ST9+ 8/16 bit microcontrolle */
189    EM_ST7         =  68,  /* STMicroelectronics ST7 8-bit microcontroller    */
190    EM_68HC16      =  69,  /* Motorola MC68HC16 Microcontroller               */
191    EM_68HC11      =  70,  /* Motorola MC68HC11 Microcontroller               */
192    EM_68HC08      =  71,  /* Motorola MC68HC08 Microcontroller               */
193    EM_68HC05      =  72,  /* Motorola MC68HC05 Microcontroller               */
194    EM_SVX         =  73,  /* Silicon Graphics SVx                            */
195    EM_ST19        =  74,  /* STMicroelectronics ST19 8-bit microcontroller   */
196    EM_VAX         =  75,  /* Digital VAX                                     */
197    EM_CRIS        =  76,  /* Axis Communications 32-bit embedded processor   */
198    EM_JAVELIN     =  77,  /* Infineon Technologies 32-bit embedded processor */
199    EM_FIREPATH    =  78,  /* Element 14 64-bit DSP Processor                 */
200    EM_ZSP         =  79,  /* LSI Logic 16-bit DSP Processor                  */
201    EM_MMIX        =  80,  /* Donald Knuth's educational 64-bit processor     */
202    EM_HUANY       =  81,  /* Harvard University machine-independent object f */
203    EM_PRISM       =  82,  /* SiTera Prism                                    */
204    EM_AVR         =  83,  /* Atmel AVR 8-bit microcontroller                 */
205    EM_FR30        =  84,  /* Fujitsu FR30                                    */
206    EM_D10V        =  85,  /* Mitsubishi D10V                                 */
207    EM_D30V        =  86,  /* Mitsubishi D30V                                 */
208    EM_V850        =  87,  /* NEC v850                                        */
209    EM_M32R        =  88,  /* Mitsubishi M32R                                 */
210    EM_MN10300     =  89,  /* Matsushita MN10300                              */
211    EM_MN10200     =  90,  /* Matsushita MN10200                              */
212    EM_PJ          =  91,  /* picoJava                                        */
213    EM_OPENRISC    =  92,  /* OpenRISC 32-bit embedded processor              */
214    EM_ARC_A5      =  93,  /* ARC Cores Tangent-A5                            */
215    EM_XTENSA      =  94,  /* Tensilica Xtensa Architecture                   */
216    EM_VIDEOCORE   =  95,  /* Alphamosaic VideoCore processor                 */
217    EM_TMM_GPP     =  96,  /* Thompson Multimedia General Purpose Processor   */
218    EM_NS32K       =  97,  /* National Semiconductor 32000 series             */
219    EM_TPC         =  98,  /* Tenor Network TPC processor                     */
220    EM_SNP1K       =  99,  /* Trebia SNP 1000 processor                       */
221    EM_ST200       = 100,  /* STMicroelectronics (www.st.com) ST200 microcont */
222    EM_IP2K        = 101,  /* Ubicom IP2xxx microcontroller family            */
223    EM_MAX         = 102,  /* MAX Processor                                   */
224    EM_CR          = 103,  /* National Semiconductor CompactRISC microprocess */
225    EM_F2MC16      = 104,  /* Fujitsu F2MC16                                  */
226    EM_MSP430      = 105,  /* Texas Instruments embedded microcontroller msp4 */
227    EM_BLACKFIN    = 106,  /* Analog Devices Blackfin (DSP) processor         */
228    EM_SE_C33      = 107,  /* S1C33 Family of Seiko Epson processors          */
229    EM_SEP         = 108,  /* Sharp embedded microprocessor                   */
230    EM_ARCA        = 109,  /* Arca RISC Microprocessor                        */
231    EM_UNICORE     = 110,  /* Microprocessor series from PKU-Unity Ltd. and M */
233    /*------------------------------------------------------------------------*/
234    /* ELF Magic Numbers Reserved For Texas Instruments                       */
235    /*                                                                        */
236    /*   The magic numbers 140-159 were reserved through SCO to be included   */
237    /*   in the official ELF specification.  Please see Don Darling           */
238    /*   regarding any changes or allocation of the numbers below.            */
239    /*                                                                        */
240    /*   When we allocate a number for use, SCO needs to be notified so they  */
241    /*   can update the ELF specification accordingly.                        */
242    /*------------------------------------------------------------------------*/
243    EM_TI_C6000    = 140,  /* Reserved for Texas Instruments; unused          */
244    EM_TI_UNUSED02 = 141,  /* Reserved for Texas Instruments; unused          */
245    EM_TI_UNUSED03 = 142,  /* Reserved for Texas Instruments; unused          */
246    EM_TI_UNUSED04 = 143,  /* Reserved for Texas Instruments; unused          */
247    EM_TI_UNUSED05 = 144,  /* Reserved for Texas Instruments; unused          */
248    EM_TI_UNUSED06 = 145,  /* Reserved for Texas Instruments; unused          */
249    EM_TI_UNUSED07 = 146,  /* Reserved for Texas Instruments; unused          */
250    EM_TI_UNUSED08 = 147,  /* Reserved for Texas Instruments; unused          */
251    EM_TI_UNUSED09 = 148,  /* Reserved for Texas Instruments; unused          */
252    EM_TI_UNUSED10 = 149,  /* Reserved for Texas Instruments; unused          */
253    EM_TI_UNUSED11 = 150,  /* Reserved for Texas Instruments; unused          */
254    EM_TI_UNUSED12 = 151,  /* Reserved for Texas Instruments; unused          */
255    EM_TI_UNUSED13 = 152,  /* Reserved for Texas Instruments; unused          */
256    EM_TI_UNUSED14 = 153,  /* Reserved for Texas Instruments; unused          */
257    EM_TI_UNUSED15 = 154,  /* Reserved for Texas Instruments; unused          */
258    EM_TI_UNUSED16 = 155,  /* Reserved for Texas Instruments; unused          */
259    EM_TI_UNUSED17 = 156,  /* Reserved for Texas Instruments; unused          */
260    EM_TI_UNUSED18 = 157,  /* Reserved for Texas Instruments; unused          */
261    EM_TI_UNUSED19 = 158,  /* Reserved for Texas Instruments; unused          */
262    EM_TI_UNUSED20 = 159   /* Reserved for Texas Instruments; unused          */
263 };
266 /*---------------------------------------------------------------------------*/
267 /* Object File Version (value of "e_version")                                */
268 /*---------------------------------------------------------------------------*/
269 enum
271    EV_NONE    = 0,  /* Invalid version */
272    EV_CURRENT = 1   /* Current version */
273 };
276 /*****************************************************************************/
277 /* ELF Identification                                                        */
278 /* PP. 1-6                                                                   */
279 /*****************************************************************************/
281 /*---------------------------------------------------------------------------*/
282 /* Identification Values for ELF Files                                       */
283 /*---------------------------------------------------------------------------*/
285 /* EI_MAG0 to EI_MAG3 */
286 enum
288    ELFMAG0 = 0x7f,  /* e_ident[EI_MAG0] */
289    ELFMAG1 = 'E',   /* e_ident[EI_MAG1] */
290    ELFMAG2 = 'L',   /* e_ident[EI_MAG2] */
291    ELFMAG3 = 'F'    /* e_ident[EI_MAG3] */
292 };
294 /* EI_CLASS */
295 enum
297    ELFCLASSNONE = 0,  /* Invalid class  */
298    ELFCLASS32   = 1,  /* 32-bit objects */
299    ELFCLASS64   = 2   /* 64-bit objects */
300 };
302 /* EI_DATA */
303 enum
305    ELFDATANONE = 0,  /* Invalid data encoding */
306    ELFDATA2LSB = 1,  /* Little-endian data    */
307    ELFDATA2MSB = 2   /* Big-endian data       */
308 };
310 /* EI_OSABI */
311 enum
313    ELFOSABI_NONE       = 0,   /* No extensions or unspecified       */
314    ELFOSABI_HPUX       = 1,   /* Hewlett-Packard HP-UX              */
315    ELFOSABI_NETBSD     = 2,   /* NetBSD                             */
316    ELFOSABI_LINUX      = 3,   /* Linux                              */
317    ELFOSABI_SOLARIS    = 6,   /* Sun Solaris                        */
318    ELFOSABI_AIX        = 7,   /* AIX                                */
319    ELFOSABI_IRIX       = 8,   /* IRIX                               */
320    ELFOSABI_FREEBSD    = 9,   /* FreeBSD                            */
321    ELFOSABI_TRU64      = 10,  /* Compaq TRU64 UNIX                  */
322    ELFOSABI_MODESTO    = 11,  /* Novell Modesto                     */
323    ELFOSABI_OPENBSD    = 12,  /* Open BSD                           */
324    ELFOSABI_OPENVMS    = 13,  /* Open VMS                           */
325    ELFOSABI_NSK        = 14,  /* Hewlett-Packard Non-Stop Kernel    */
326    ELFOSABI_AROS       = 15   /* Amiga Research OS                  */
327 };
329 /*****************************************************************************/
330 /* Program Header                                                            */
331 /* PP. 2-2                                                                   */
332 /*****************************************************************************/
334 /*---------------------------------------------------------------------------*/
335 /* Program Header Data Structure                                             */
336 /*---------------------------------------------------------------------------*/
337 struct Elf32_Phdr
339    Elf32_Word  p_type;    /* Segment type              */
340    Elf32_Off   p_offset;  /* Segment file offset       */
341    Elf32_Addr  p_vaddr;   /* Segment virtual address   */
342    Elf32_Addr  p_paddr;   /* Segment physical address  */
343    Elf32_Word  p_filesz;  /* Segment file image size   */
344    Elf32_Word  p_memsz;   /* Segment memory image size */
345    Elf32_Word  p_flags;   /* Segment flags             */
346    Elf32_Word  p_align;   /* Segment alignment         */
347 };
349 /*---------------------------------------------------------------------------*/
350 /* Segment Types (value of "p_type")                                         */
351 /*---------------------------------------------------------------------------*/
352 enum
354    PT_NULL    = 0,           /* Unused table entry                           */
355    PT_LOAD    = 1,           /* Loadable segment                             */
356    PT_DYNAMIC = 2,           /* Dynamic linking information                  */
357    PT_INTERP  = 3,           /* Interpreter path string location             */
358    PT_NOTE    = 4,           /* Location and size of auxiliary information   */
359    PT_SHLIB   = 5,           /* Shared library information                   */
360    PT_PHDR    = 6,           /* Location and size of program header table    */
361    PT_TLS     = 7,           /* Specifies the Thread-Local Storage template  */
362    PT_LOOS    = 0x60000000,  /* First OS-specific value                      */
363    PT_HIOS    = 0x6fffffff,  /* Last  OS-specific value                      */
364    PT_LOPROC  = 0x70000000,  /* First processor-specific value               */
365    PT_HIPROC  = 0x7fffffff   /* Last  processor-specific value               */
366 };
368 /*---------------------------------------------------------------------------*/
369 /* Segment Permissions (value of "p_flags")                                  */
370 /*---------------------------------------------------------------------------*/
371 enum
373    PF_X        = 0x1,         /* Execute                 */
374    PF_W        = 0x2,         /* Write                   */
375    PF_R        = 0x4,         /* Read                    */
376    PF_MASKOS   = 0x0ff00000,  /* OS-specific mask        */
377    PF_MASKPROC = 0xf0000000   /* Processor-specific mask */
378 };
380 /*****************************************************************************/
381 /* Sections                                                                  */
382 /* PP. 1-9                                                                   */
383 /*****************************************************************************/
385 /*---------------------------------------------------------------------------*/
386 /* Section Header Data Structure                                             */
387 /*---------------------------------------------------------------------------*/
388 struct Elf32_Shdr
390    Elf32_Word  sh_name;       /* Section name (offset into string section)   */
391    Elf32_Word  sh_type;       /* Section type                                */
392    Elf32_Word  sh_flags;      /* Section flags                               */
393    Elf32_Addr  sh_addr;       /* Address in memory image                     */
394    Elf32_Off   sh_offset;     /* File offset of section data                 */
395    Elf32_Word  sh_size;       /* Size of the section in bytes                */
396    Elf32_Word  sh_link;       /* Link to the section header table            */
397    Elf32_Word  sh_info;       /* Extra information depending on section type */
398    Elf32_Word  sh_addralign;  /* Address alignment constraints               */
399    Elf32_Word  sh_entsize;    /* Size of fixed-size entries in section       */
400 };
402 /*---------------------------------------------------------------------------*/
403 /* Special Section Indexes                                                   */
404 /*---------------------------------------------------------------------------*/
405 enum
407    SHN_UNDEF     = 0,       /* Referenced by undefined values          */
408    SHN_LORESERVE = 0xff00,  /* First reserved index                    */
409    SHN_LOPROC    = 0xff00,  /* First processor-specific index          */
410    SHN_HIPROC    = 0xff1f,  /* Last  processor-specific index          */
411    SHN_LOOS      = 0xff20,  /* First OS-specific index                 */
412    SHN_HIOS      = 0xff3f,  /* Last  OS-specific index                 */
413    SHN_ABS       = 0xfff1,  /* Referenced by absolute values           */
414    SHN_COMMON    = 0xfff2,  /* Referenced by common values             */
415    SHN_XINDEX    = 0xffff,  /* Indirect index reference (escape value) */
416    SHN_HIRESERVE = 0xffff   /* Last reserved index                     */
417 };
419 /*---------------------------------------------------------------------------*/
420 /* Section Types (value of "sh_type")                                        */
421 /*---------------------------------------------------------------------------*/
422 enum
424    SHT_NULL          = 0,           /* Inactive section                      */
425    SHT_PROGBITS      = 1,           /* Application-specific information      */
426    SHT_SYMTAB        = 2,           /* Symbol table                          */
427    SHT_STRTAB        = 3,           /* String table                          */
428    SHT_RELA          = 4,           /* Relocation entries (explicit addends) */
429    SHT_HASH          = 5,           /* Symbol hash table                     */
430    SHT_DYNAMIC       = 6,           /* Dynamic linking information           */
431    SHT_NOTE          = 7,           /* Miscellaneous information             */
432    SHT_NOBITS        = 8,           /* Contains no data in file              */
433    SHT_REL           = 9,           /* Relocation entries (no expl. addends) */
434    SHT_SHLIB         = 10,          /* Shared library                        */
435    SHT_DYNSYM        = 11,          /* Dynamic symbol table                  */
436    SHT_INIT_ARRAY    = 14,          /* Pointers to initialization functions  */
437    SHT_FINI_ARRAY    = 15,          /* Pointers to termination functions     */
438    SHT_PREINIT_ARRAY = 16,          /* Pointers to pre-init functions        */
439    SHT_GROUP         = 17,          /* Section group                         */
440    SHT_SYMTAB_SHNDX  = 18,          /* Section indexes for SHN_XINDEX refs.  */
441    SHT_LOOS          = 0x60000000,  /* First OS-specific type                */
442    SHT_HIOS          = 0x6fffffff,  /* Last  OS-specific type                */
443    SHT_LOPROC        = 0x70000000,  /* First processor-specific type         */
444    SHT_HIPROC        = 0x7fffffff,  /* Last  processor-specific type         */
445    SHT_LOUSER        = 0x80000000,  /* First application-specific type       */
446    SHT_HIUSER        = 0xffffffff   /* Last  application-specific type       */
447 };
449 /*---------------------------------------------------------------------------*/
450 /* Section Attribute Flags (value of "sh_flags")                             */
451 /*---------------------------------------------------------------------------*/
452 enum
454    SHF_WRITE            = 0x1,         /* Writable during process execution  */
455    SHF_ALLOC            = 0x2,         /* Loaded into processor memory       */
456    SHF_EXECINSTR        = 0x4,         /* Contains executable instructions   */
457    SHF_MERGE            = 0x10,        /* Can be merged                      */
458    SHF_STRINGS          = 0x20,        /* Contains null-terminated strings   */
459    SHF_INFO_LINK        = 0x40,        /* sh_info contains a section index   */
460    SHF_LINK_ORDER       = 0x80,        /* Maintain section ordering          */
461    SHF_OS_NONCONFORMING = 0x100,       /* OS-specific processing required    */
462    SHF_GROUP            = 0x200,       /* Member of a section group          */
463    SHF_TLS              = 0x400,       /* Contains Thread-Local Storage      */
464    SHF_MASKOS           = 0x0ff00000,  /* Mask of OS-specific flags          */
465    SHF_MASKPROC         = 0xf0000000   /* Mask for processor-specific flags  */
466 };
468 /*---------------------------------------------------------------------------*/
469 /* Section Group Flags                                                       */
470 /*---------------------------------------------------------------------------*/
471 enum
473    GRP_COMDAT   = 0x1,         /* Common data; only one is kept by linker */
474    GRP_MASKOS   = 0x0ff00000,  /* Mask for OS-specific group flags        */
475    GRP_MASKPROC = 0xf0000000   /* Mask for processor-specific group flags */
476 };
479 /*****************************************************************************/
480 /* Symbol Table                                                              */
481 /* PP. 1-18                                                                  */
482 /*****************************************************************************/
484 /*---------------------------------------------------------------------------*/
485 /* Symbol Table Entry Data Structure                                         */
486 /*---------------------------------------------------------------------------*/
487 struct Elf32_Sym
489    Elf32_Word  st_name;   /* String table offset for symbol name */
490    Elf32_Addr  st_value;  /* Symbol value                        */
491    Elf32_Word  st_size;   /* Symbol size                         */
492    uint8_t     st_info;   /* Symbol type and binding             */
493    uint8_t     st_other;  /* Symbol visibility                   */
494    Elf32_Half  st_shndx;  /* Symbol type / defining section      */
495 };
497 /*---------------------------------------------------------------------------*/
498 /* Undefined Symbol Index                                                    */
499 /*---------------------------------------------------------------------------*/
500 enum
502    STN_UNDEF = 0   /* First symbol table entry is always undefined */
503 };
505 /*---------------------------------------------------------------------------*/
506 /* Symbol Binding and Type Utility Functions.                                */
507 /*---------------------------------------------------------------------------*/
508 static inline uint8_t ELF32_ST_BIND(uint8_t i)       { return (i >> 4);      }
509 static inline uint8_t ELF32_ST_TYPE(uint8_t i)       { return (i & 0xf);     }
510 static inline uint8_t ELF32_ST_INFO(uint8_t b, uint8_t t) 
511                                             { return ((b << 4) + (t & 0xf)); }
512 static inline uint8_t ELF32_ST_VISIBILITY(uint8_t o) { return (o & 0x3);     }
515 /*---------------------------------------------------------------------------*/
516 /* Symbol Binding (value returned by ELF32_ST_BIND())                        */
517 /*---------------------------------------------------------------------------*/
518 enum
520    STB_LOCAL  = 0,   /* Symbol does not have external linkage */
521    STB_GLOBAL = 1,   /* Symbol has external linkage           */
522    STB_WEAK   = 2,   /* Symbol has weak external linkage      */
523    STB_LOOS   = 10,  /* First OS-specific binding             */
524    STB_HIOS   = 12,  /* Last  OS-specific binding             */
525    STB_LOPROC = 13,  /* First processor-specific binding      */
526    STB_HIPROC = 15   /* Last  processor-specific binding      */
527 };
529 /*---------------------------------------------------------------------------*/
530 /* Symbol Types (value returned by ELF32_ST_TYPE())                          */
531 /*---------------------------------------------------------------------------*/
532 enum
534    STT_NOTYPE  = 0,   /* Unspecified type                        */
535    STT_OBJECT  = 1,   /* Associated with a data object           */
536    STT_FUNC    = 2,   /* Associated with executable code         */
537    STT_SECTION = 3,   /* Associated with a section               */
538    STT_FILE    = 4,   /* Associated with a source file           */
539    STT_COMMON  = 5,   /* Labels an uninitialized common block    */
540    STT_TLS     = 6,   /* Specifies a thread-local storage entity */
541    STT_LOOS    = 10,  /* First OS-specific type                  */
542    STT_HIOS    = 12,  /* Last  OS-specific type                  */
543    STT_LOPROC  = 13,  /* First processor-specific type           */
544    STT_HIPROC  = 15   /* Last  processor-specific type           */
545 };
547 /*---------------------------------------------------------------------------*/
548 /* Symbol Visibility (value returned by ELF32_ST_VISIBILITY())               */
549 /*---------------------------------------------------------------------------*/
550 enum
552    STV_DEFAULT   = 0,  /* Visibility specified by binding type               */
553    STV_INTERNAL  = 1,  /* Like STV_HIDDEN, with processor-specific semantics */
554    STV_HIDDEN    = 2,  /* Not visible to other components                    */
555    STV_PROTECTED = 3   /* Visible in other components but not preemptable    */
556 };
558 /*---------------------------------------------------------------------------*/
559 /* Note header in a PT_NOTE section                                          */
560 /*---------------------------------------------------------------------------*/
561 struct Elf32_Nhdr
563   Elf32_Word    n_namesz;       /* Name size                                 */
564   Elf32_Word    n_descsz;       /* Content size                              */
565   Elf32_Word    n_type;         /* Content type                              */
566 };
568 /*****************************************************************************/
569 /* Relocation                                                                */
570 /* PP. 1-22                                                                  */
571 /*****************************************************************************/
573 /*---------------------------------------------------------------------------*/
574 /* Relocation Entries Data Structures                                        */
575 /*---------------------------------------------------------------------------*/
576 struct Elf32_Rel
578    Elf32_Addr  r_offset;  /* Offset of the relocatable value in the section */
579    Elf32_Word  r_info;    /* Symbol table index and relocation type         */
580 };
582 struct Elf32_Rela
584    Elf32_Addr  r_offset;  /* Offset of the relocatable value in the section */
585    Elf32_Word  r_info;    /* Symbol table index and relocation type         */
586    Elf32_Sword r_addend;  /* Constant addend used to compute new value      */
587 };
589 /*---------------------------------------------------------------------------*/
590 /* Relocation Symbol and Type Utility Functions.                             */
591 /*---------------------------------------------------------------------------*/
592 static inline uint32_t ELF32_R_SYM(uint32_t i)  { return (i >> 8);            }
593 static inline uint8_t  ELF32_R_TYPE(uint32_t i) { return (i & 0xFF);          }
594 static inline uint32_t ELF32_R_INFO(uint32_t s, uint8_t t) 
595                                                 { return ((s << 8) + t);      }
598 /*****************************************************************************/
599 /* Dynamic Section                                                           */
600 /* PP. 2-8                                                                   */
601 /*****************************************************************************/
602 struct Elf32_Dyn
604    Elf32_Sword  d_tag;
605    union
606    {
607       Elf32_Word  d_val;
608       Elf32_Addr  d_ptr;
609    } d_un;
610 };
612 /* Name                 Value           d_un        Executable  Shared Obj. */
613 /* ----                 -----           ----        ----------  ----------- */
614 enum
616    DT_NULL            = 0,           /* ignored     mandatory   mandatory   */
617    DT_NEEDED          = 1,           /* d_val       optional    optional    */
618    DT_PLTRELSZ        = 2,           /* d_val       optional    optional    */
619    DT_PLTGOT          = 3,           /* d_ptr       optional    optional    */
620    DT_HASH            = 4,           /* d_ptr       mandatory   mandatory   */
621    DT_STRTAB          = 5,           /* d_ptr       mandatory   mandatory   */
622    DT_SYMTAB          = 6,           /* d_ptr       mandatory   mandatory   */
623    DT_RELA            = 7,           /* d_ptr       mandatory   optional    */
624    DT_RELASZ          = 8,           /* d_val       mandatory   optional    */
625    DT_RELAENT         = 9,           /* d_val       mandatory   optional    */
626    DT_STRSZ           = 10,          /* d_val       mandatory   mandatory   */
627    DT_SYMENT          = 11,          /* d_val       mandatory   mandatory   */
628    DT_INIT            = 12,          /* d_ptr       optional    optional    */
629    DT_FINI            = 13,          /* d_ptr       optional    optional    */
630    DT_SONAME          = 14,          /* d_val       ignored     optional    */
631    DT_RPATH           = 15,          /* d_val       optional    ignored     */
632    DT_SYMBOLIC        = 16,          /* ignored     ignored     optional    */
633    DT_REL             = 17,          /* d_ptr       mandatory   optional    */
634    DT_RELSZ           = 18,          /* d_val       mandatory   optional    */
635    DT_RELENT          = 19,          /* d_val       mandatory   optional    */
636    DT_PLTREL          = 20,          /* d_val       optional    optional    */
637    DT_DEBUG           = 21,          /* d_ptr       optional    ignored     */
638    DT_TEXTREL         = 22,          /* ignored     optional    optional    */
639    DT_JMPREL          = 23,          /* d_ptr       optional    optional    */
640    DT_BIND_NOW        = 24,          /* ignored     optional    optional    */
641    DT_INIT_ARRAY      = 25,          /* d_ptr       optional    optional    */
642    DT_FINI_ARRAY      = 26,          /* d_ptr       optional    optional    */
643    DT_INIT_ARRAYSZ    = 27,          /* d_val       optional    optional    */
644    DT_FINI_ARRAYSZ    = 28,          /* d_val       optional    optional    */
645    DT_RUNPATH         = 29,          /* d_val       optional    optional    */
646    DT_FLAGS           = 30,          /* d_val       optional    optional    */
647    DT_ENCODING        = 32,          /* unspecified unspecified unspecified */
648    DT_PREINIT_ARRAY   = 32,          /* d_ptr       optional    ignored     */
649    DT_PREINIT_ARRAYSZ = 33,          /* d_val       optional    ignored     */
650    DT_LOOS            = 0x60000000,  /* unspecified unspecified unspecified */
651    DT_HIOS            = 0x6ffff000,  /* unspecified unspecified unspecified */
652    DT_LOPROC          = 0x70000000,  /* unspecified unspecified unspecified */
653    DT_HIPROC          = 0x7fffffff   /* unspecified unspecified unspecified */
654 }; 
657 /*---------------------------------------------------------------------------*/
658 /* DT_FLAGS values.                                                          */
659 /*---------------------------------------------------------------------------*/
660 enum
662   DF_ORIGIN     = 0x01, /* loaded object may reference $ORIGIN subst. string */
663   DF_SYMBOLIC   = 0x02, /* changes dynamic linker symbol resolution          */
664   DF_TEXTREL    = 0x04, /* do not allow relocation of non-writable segments  */
665   DF_BIND_NOW   = 0x08, /* don't use lazy binding                            */
666   DF_STATIC_TLS = 0x10, /* do not load this file dynamically                 */
667   DF_DIRECT_DEPENDENT = 0x20, /* limit global sym lookup to dependent list   */
668   DF_WORLD      = 0x40  /* Linux style global sym lookup, breadth-first      */
669 };
672 /*---------------------------------------------------------------------------*/
673 /* Dynamic Tag Database.                                                     */
674 /*---------------------------------------------------------------------------*/
676 /* Specifiers for which d_un union member to use                             */
678 enum
680    EDYN_UNTYPE_IGNORED,
681    EDYN_UNTYPE_VAL,
682    EDYN_UNTYPE_PTR,
683    EDYN_UNTYPE_UNSPECIFIED
684 };
687 /* Specifiers for executable/shared object file requirements                 */
689 enum
691    EDYN_TAGREQ_IGNORED,
692    EDYN_TAGREQ_MANDATORY,
693    EDYN_TAGREQ_OPTIONAL,
694    EDYN_TAGREQ_UNSPECIFIED
695 };
698 /* Data structure for one dynamic tag database entry                         */
700 struct EDYN_TAG
702    const char* d_tag_name;   /* tag name string                     */
703    Elf32_Sword d_tag_value;  /* DT_* tag value                      */
704    Elf32_Word  d_untype;     /* which d_un union member to use      */
705    Elf32_Word  d_exec_req;   /* requirement for executable files    */
706    Elf32_Word  d_shared_req; /* requirement for shared object files */
707 };
709 extern const struct EDYN_TAG EDYN_TAG_DB[];
711 /*****************************************************************************/
712 /* Special Section Database                                                  */
713 /*****************************************************************************/
715 /*---------------------------------------------------------------------------*/
716 /* Special Section Names                                                     */
717 /*---------------------------------------------------------------------------*/
718 #define ESCN_BSS_name            ".bss"
719 #define ESCN_COMMENT_name        ".comment"
720 #define ESCN_DATA1_name          ".data1"
721 #define ESCN_DATA_name           ".data"
722 #define ESCN_DEBUG_name          ".debug"
723 #define ESCN_DYNAMIC_name        ".dynamic"
724 #define ESCN_DYNSTR_name         ".dynstr"
725 #define ESCN_DYNSYM_name         ".dynsym"
726 #define ESCN_FINI_ARRAY_name     ".fini_array"
727 #define ESCN_FINI_name           ".fini"
728 #define ESCN_GOT_name            ".got"
729 #define ESCN_HASH_name           ".hash"
730 #define ESCN_INIT_ARRAY_name     ".init_array"
731 #define ESCN_INIT_name           ".init"
732 #define ESCN_INTERP_name         ".interp"
733 #define ESCN_LINE_name           ".line"
734 #define ESCN_NOTE_name           ".note"
735 #define ESCN_PLT_name            ".plt"
736 #define ESCN_PREINIT_ARRAY_name  ".preinit_array"
737 #define ESCN_RELA_name           ".rela"
738 #define ESCN_REL_name            ".rel"
739 #define ESCN_RODATA1_name        ".rodata1"
740 #define ESCN_RODATA_name         ".rodata"
741 #define ESCN_SHSTRTAB_name       ".shstrtab"
742 #define ESCN_STRTAB_name         ".strtab"
743 #define ESCN_SYMTAB_SHNDX_name   ".symtab_shndx"
744 #define ESCN_SYMTAB_name         ".symtab"
745 #define ESCN_TBSS_name           ".tbss"
746 #define ESCN_TDATA1_name         ".tdata1"
747 #define ESCN_TDATA_name          ".tdata"
748 #define ESCN_TEXT_name           ".text"
749 #define ESCN_ATTRIBUTES_name     "__TI_build_attributes"
750 #define ESCN_ICODE_name          "__TI_ICODE"
751 #define ESCN_XREF_name           "__TI_XREF"
753 /*---------------------------------------------------------------------------*/
754 /* Special Section Information Data Structure.                               */
755 /*---------------------------------------------------------------------------*/
756 struct ESCN
758    const char *name;
759    Elf32_Word  sh_type;
760    Elf32_Word  sh_entsize;
761    Elf32_Word  sh_flags;
762 };
764 extern const struct ESCN ESCN_DB[];
766 #endif /* ELF32_H */