summaryrefslogtreecommitdiff
path: root/src/format/elf/elf_def.h
blob: 0d91e002c4ff7806f67b5fd9f880f3ae66370689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

/* Chrysalide - Outil d'analyse de fichiers binaires
 * elf_def.h - liste des structures et constantes utilisées par le format ELF
 *
 * Copyright (C) 2009-2017 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _FORMAT_ELF_ELF_DEF_H
#define _FORMAT_ELF_ELF_DEF_H


#include <stdint.h>



/* ---------------------------- EN-TETE DES FICHIERS ELF ---------------------------- */


#define EI_NIDENT   16


/* En-tête de fichier ELF (32 et 64 bits) */

typedef struct _elf32_header
{
    uint8_t e_ident[EI_NIDENT];             /* Magic number + informations */
    uint16_t e_type;                        /* Type de fichier             */
    uint16_t e_machine;                     /* Architecture                */
    uint32_t e_version;                     /* Version du type de fichier  */
    uint32_t e_entry;                       /* Point d'entrée du programme */
    uint32_t e_phoff;                       /* Début de la table 'Program' */
    uint32_t e_shoff;                       /* Début de la table 'Section' */
    uint32_t e_flags;                       /* Prop. spécifiques au proc.  */
    uint16_t e_ehsize;                      /* Taille de l'en-tête en oct. */
    uint16_t e_phentsize;                   /* Taille d'une entrée Program */
    uint16_t e_phnum;                       /* Nombre d'éléments 'Program' */
    uint16_t e_shentsize;                   /* Taille d'une entrée Section */
    uint16_t e_shnum;                       /* Nombre d'éléments 'Section' */
    uint16_t e_shstrndx;                    /* Indice de la section chaînes*/

} elf32_header;

typedef struct _elf64_header
{
    uint8_t e_ident[EI_NIDENT];             /* Magic number + informations */
    uint16_t e_type;                        /* Type de fichier             */
    uint16_t e_machine;                     /* Architecture                */
    uint32_t e_version;                     /* Version du type de fichier  */
    uint64_t e_entry;                       /* Point d'entrée du programme */
    uint64_t e_phoff;                       /* Début de la table 'Program' */
    uint64_t e_shoff;                       /* Début de la table 'Section' */
    uint32_t e_flags;                       /* Prop. spécifiques au proc.  */
    uint16_t e_ehsize;                      /* Taille de l'en-tête en oct. */
    uint16_t e_phentsize;                   /* Taille d'une entrée Program */
    uint16_t e_phnum;                       /* Nombre d'éléments 'Program' */
    uint16_t e_shentsize;                   /* Taille d'une entrée Section */
    uint16_t e_shnum;                       /* Nombre d'éléments 'Section' */
    uint16_t e_shstrndx;                    /* Indice de la section chaînes*/

} elf64_header;

typedef union _elf_header
{
    elf32_header hdr32;                     /* Version 32 bits             */
    elf64_header hdr64;                     /* Version 64 bits             */

} elf_header;


#define ELF_HDR(fmt, hdr, fld) (fmt->is_32b ? (hdr).hdr32.fld : (hdr).hdr64.fld)

#define ELF_HDR_SET(fmt, hdr, fld, val)             \
    do                                              \
    {                                               \
        if (fmt->is_32b) (hdr).hdr32.fld = val;     \
        else (hdr).hdr64.fld = val;                 \
    }                                               \
    while (0)

#define ELF_HDR_OFFSET_OF(fmt, fld) (fmt->is_32b ? offsetof(elf32_header, fld) : offsetof(elf64_header, fld))

#define ELF_SIZEOF_HDR(fmt) (fmt->is_32b ? sizeof(elf32_header) : sizeof(elf64_header))


/* Composition du champ e_ident */


#define EI_CLASS        4                   /* Indice de classe du fichier */
#define EI_DATA         5                   /* Indice de l'encodage        */
#define EI_VERSION      6                   /* Version de fichier ELF      */
#define EI_OSABI        7                   /* Identification de l'ABI OS  */


/* ... EI_CLASS */

#define ELFCLASSNONE    0                   /* Objet invalide              */
#define ELFCLASS32      1                   /* Objet 32 bits               */
#define ELFCLASS64      2                   /* Objet 64 bits               */

/* ... EI_DATA */

#define ELFDATANONE     0                   /* Encodage invalide           */
#define ELFDATA2LSB     1                   /* Complément à 2, petit bout. */
#define ELFDATA2MSB     2                   /* Complément à 2, grand bout. */

/* ... EI_VERSION */

#define EV_NONE         0                   /* Version ELF invalide        */
#define EV_CURRENT      1                   /* Version d'ELF courante      */

/* ... EI_OSABI */

#define ELFOSABI_NONE           0           /* UNIX System V ABI */
#define ELFOSABI_SYSV           0           /* Alias.  */
#define ELFOSABI_HPUX           1           /* HP-UX */
#define ELFOSABI_NETBSD         2           /* NetBSD.  */
#define ELFOSABI_GNU            3           /* Object uses GNU ELF extensions.  */
#define ELFOSABI_LINUX          ELFOSABI_GNU /* Compatibility alias.  */
#define ELFOSABI_SOLARIS        6           /* Sun Solaris.  */
#define ELFOSABI_AIX            7           /* IBM AIX.  */
#define ELFOSABI_IRIX           8           /* SGI Irix.  */
#define ELFOSABI_FREEBSD        9           /* FreeBSD.  */
#define ELFOSABI_TRU64          10          /* Compaq TRU64 UNIX.  */
#define ELFOSABI_MODESTO        11          /* Novell Modesto.  */
#define ELFOSABI_OPENBSD        12          /* OpenBSD.  */
#define ELFOSABI_ARM_AEABI      64          /* ARM EABI */
#define ELFOSABI_ARM            97          /* ARM */
#define ELFOSABI_STANDALONE     255         /* Standalone (embedded) application */

/* Valeurs possibles pour e_type */

#define ET_NONE         0                   /* Aucun type défini           */
#define ET_REL          1                   /* Fichier relogeable          */
#define ET_EXEC         2                   /* Fichier exécutable          */
#define ET_DYN          3                   /* Bibliothèque dynamique      */
#define ET_CORE         4                   /* Fichier Core                */
#define ET_LOOS         0xfe00              /* Spécifique OS : début       */
#define ET_HIOS         0xfeff              /* Spécifique OS : fin         */
#define ET_LOPROC       0xff00              /* Spécifique processeur : deb.*/
#define ET_HIPROC       0xffff              /* Spécifique processeur : fin */

/* Valeurs possibles pour e_machine */

#define EM_NONE          0                  /* No machine */
#define EM_M32           1                  /* AT&T WE 32100 */
#define EM_SPARC         2                  /* SUN SPARC */
#define EM_386           3                  /* Intel 80386 */
#define EM_68K           4                  /* Motorola m68k family */
#define EM_88K           5                  /* Motorola m88k family */
#define EM_860           7                  /* Intel 80860 */
#define EM_MIPS          8                  /* MIPS R3000 big-endian */
#define EM_S370          9                  /* IBM System/370 */
#define EM_MIPS_RS3_LE  10                  /* MIPS R3000 little-endian */
#define EM_PARISC       15                  /* HPPA */
#define EM_VPP500       17                  /* Fujitsu VPP500 */
#define EM_SPARC32PLUS  18                  /* Sun's "v8plus" */
#define EM_960          19                  /* Intel 80960 */
#define EM_PPC          20                  /* PowerPC */
#define EM_PPC64        21                  /* PowerPC 64-bit */
#define EM_S390         22                  /* IBM S390 */
#define EM_V800         36                  /* NEC V800 series */
#define EM_FR20         37                  /* Fujitsu FR20 */
#define EM_RH32         38                  /* TRW RH-32 */
#define EM_RCE          39                  /* Motorola RCE */
#define EM_ARM          40                  /* ARM */
#define EM_FAKE_ALPHA   41                  /* Digital Alpha */
#define EM_SH           42                  /* Hitachi SH */
#define EM_SPARCV9      43                  /* SPARC v9 64-bit */
#define EM_TRICORE      44                  /* Siemens Tricore */
#define EM_ARC          45                  /* Argonaut RISC Core */
#define EM_H8_300       46                  /* Hitachi H8/300 */
#define EM_H8_300H      47                  /* Hitachi H8/300H */
#define EM_H8S          48                  /* Hitachi H8S */
#define EM_H8_500       49                  /* Hitachi H8/500 */
#define EM_IA_64        50                  /* Intel Merced */
#define EM_MIPS_X       51                  /* Stanford MIPS-X */
#define EM_COLDFIRE     52                  /* Motorola Coldfire */
#define EM_68HC12       53                  /* Motorola M68HC12 */
#define EM_MMA          54                  /* Fujitsu MMA Multimedia Accelerator*/
#define EM_PCP          55                  /* Siemens PCP */
#define EM_NCPU         56                  /* Sony nCPU embeeded RISC */
#define EM_NDR1         57                  /* Denso NDR1 microprocessor */
#define EM_STARCORE     58                  /* Motorola Start*Core processor */
#define EM_ME16         59                  /* Toyota ME16 processor */
#define EM_ST100        60                  /* STMicroelectronic ST100 processor */
#define EM_TINYJ        61                  /* Advanced Logic Corp. Tinyj emb.fam*/
#define EM_X86_64       62                  /* AMD x86-64 architecture */
#define EM_PDSP         63                  /* Sony DSP Processor */
#define EM_FX66         66                  /* Siemens FX66 microcontroller */
#define EM_ST9PLUS      67                  /* STMicroelectronics ST9+ 8/16 mc */
#define EM_ST7          68                  /* STmicroelectronics ST7 8 bit mc */
#define EM_68HC16       69                  /* Motorola MC68HC16 microcontroller */
#define EM_68HC11       70                  /* Motorola MC68HC11 microcontroller */
#define EM_68HC08       71                  /* Motorola MC68HC08 microcontroller */
#define EM_68HC05       72                  /* Motorola MC68HC05 microcontroller */
#define EM_SVX          73                  /* Silicon Graphics SVx */
#define EM_ST19         74                  /* STMicroelectronics ST19 8 bit mc */
#define EM_VAX          75                  /* Digital VAX */
#define EM_CRIS         76                  /* Axis Communications 32-bit embedded processor */
#define EM_JAVELIN      77                  /* Infineon Technologies 32-bit embedded processor */
#define EM_FIREPATH     78                  /* Element 14 64-bit DSP Processor */
#define EM_ZSP          79                  /* LSI Logic 16-bit DSP Processor */
#define EM_MMIX         80                  /* Donald Knuth's educational 64-bit processor */
#define EM_HUANY        81                  /* Harvard University machine-independent object files */
#define EM_PRISM        82                  /* SiTera Prism */
#define EM_AVR          83                  /* Atmel AVR 8-bit microcontroller */
#define EM_FR30         84                  /* Fujitsu FR30 */
#define EM_D10V         85                  /* Mitsubishi D10V */
#define EM_D30V         86                  /* Mitsubishi D30V */
#define EM_V850         87                  /* NEC v850 */
#define EM_M32R         88                  /* Mitsubishi M32R */
#define EM_MN10300      89                  /* Matsushita MN10300 */
#define EM_MN10200      90                  /* Matsushita MN10200 */
#define EM_PJ           91                  /* picoJava */
#define EM_OPENRISC     92                  /* OpenRISC 32-bit embedded processor */
#define EM_ARC_A5       93                  /* ARC Cores Tangent-A5 */
#define EM_XTENSA       94                  /* Tensilica Xtensa Architecture */
#define EM_AARCH64      183                 /* ARM AARCH64 */
#define EM_TILEPRO      188                 /* Tilera TILEPro */
#define EM_MICROBLAZE   189                 /* Xilinx MicroBlaze */
#define EM_TILEGX       191                 /* Tilera TILE-Gx */



/* --------------------------- EN-TETE DES PROGRAMMES ELF --------------------------- */


/* Version 32 et 64 bits */


typedef struct _elf32_phdr
{
    uint32_t p_type;                        /* Type de segment             */
    uint32_t p_offset;                      /* Position dans le fichier    */
    uint32_t p_vaddr;                       /* Adresse virtuelle du segment*/
    uint32_t p_paddr;                       /* Adresse physique du segment */
    uint32_t p_filesz;                      /* Taille dans le fichier      */
    uint32_t p_memsz;                       /* Taille en mémoire           */
    uint32_t p_flags;                       /* Drapeaux pour le segment    */
    uint32_t p_align;                       /* Alignement du segment       */

} elf32_phdr;

typedef struct _elf64_phdr
{
    uint32_t p_type;                        /* Type de segment             */
    uint32_t p_flags;                       /* Drapeaux pour le segment    */
    uint64_t p_offset;                      /* Position dans le fichier    */
    uint64_t p_vaddr;                       /* Adresse virtuelle du segment*/
    uint64_t p_paddr;                       /* Adresse physique du segment */
    uint64_t p_filesz;                      /* Taille dans le fichier      */
    uint64_t p_memsz;                       /* Taille en mémoire           */
    uint64_t p_align;                       /* Alignement du segment       */

} elf64_phdr;

typedef union _elf_phdr
{
    elf32_phdr phdr32;                      /* Version 32 bits             */
    elf64_phdr phdr64;                      /* Version 32 bits             */

} elf_phdr;


#define ELF_PHDR(fmt, hdr, fld) (fmt->is_32b ? (hdr).phdr32.fld : (hdr).phdr64.fld)

#define ELF_SIZEOF_PHDR(fmt) (fmt->is_32b ? sizeof(elf32_phdr) : sizeof(elf64_phdr))

/* Valeurs possibles pour p_type */

#define PT_NULL         0                   /* Program header table entry unused */
#define PT_LOAD         1                   /* Loadable program segment */
#define PT_DYNAMIC      2                   /* Dynamic linking information */
#define PT_INTERP       3                   /* Program interpreter */
#define PT_NOTE         4                   /* Auxiliary information */
#define PT_SHLIB        5                   /* Reserved */
#define PT_PHDR         6                   /* Entry for header table itself */
#define PT_TLS          7                   /* Thread-local storage segment */
#define PT_NUM          8                   /* Number of defined types */
#define PT_LOOS         0x60000000          /* Start of OS-specific */
#define PT_GNU_EH_FRAME 0x6474e550          /* GCC .eh_frame_hdr segment */
#define PT_GNU_STACK    0x6474e551          /* Indicates stack executability */
#define PT_GNU_RELRO    0x6474e552          /* Read-only after relocation */
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa          /* Sun Specific segment */
#define PT_SUNWSTACK    0x6ffffffb          /* Stack segment */
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff          /* End of OS-specific */
#define PT_LOPROC       0x70000000          /* Start of processor-specific */
#define PT_HIPROC       0x7fffffff          /* End of processor-specific */

/* Valeurs possibles pour p_flags */

#define PF_X        (1 << 0)                /* Le segment est exécutable   */
#define PF_W        (1 << 1)                /* Le segment est écrasable    */
#define PF_R        (1 << 2)                /* Le segment est lisible      */
#define PF_MASKOS   0x0ff00000              /* Spécifique à l'OS           */
#define PF_MASKPROC 0xf0000000              /* Spécifique au processeur    */



/* ---------------------------- EN-TETE DES SECTIONS ELF ---------------------------- */


/* Version 32 et 64 bits */

typedef struct _elf32_shdr
{
    uint32_t sh_name;                       /* Indice du nom de la section */
    uint32_t sh_type;                       /* Type de section             */
    uint32_t sh_flags;                      /* Drapeaux pour la section    */
    uint32_t sh_addr;                       /* Adresse virtuelle à l'exec. */
    uint32_t sh_offset;                     /* Position dans le fichier    */
    uint32_t sh_size;                       /* Taille en octets            */
    uint32_t sh_link;                       /* Lien vers une autre section */
    uint32_t sh_info;                       /* Infos. complémentaires      */
    uint32_t sh_addralign;                  /* Alignement de la section    */
    uint32_t sh_entsize;                    /* Eventuelle taille d'élément */

} elf32_shdr;

typedef struct _elf64_shdr
{
    uint32_t sh_name;                       /* Indice du nom de la section */
    uint32_t sh_type;                       /* Type de section             */
    uint64_t sh_flags;                      /* Drapeaux pour la section    */
    uint64_t sh_addr;                       /* Adresse virtuelle à l'exec. */
    uint64_t sh_offset;                     /* Position dans le fichier    */
    uint64_t sh_size;                       /* Taille en octets            */
    uint32_t sh_link;                       /* Lien vers une autre section */
    uint32_t sh_info;                       /* Infos. complémentaires      */
    uint64_t sh_addralign;                  /* Alignement de la section    */
    uint64_t sh_entsize;                    /* Eventuelle taille d'élément */

} elf64_shdr;

typedef union _elf_shdr
{
    elf32_shdr shdr32;                      /* Version 32 bits             */
    elf64_shdr shdr64;                      /* Version 64 bits             */

} elf_shdr;


#define ELF_SHDR(fmt, shdr, fld) (fmt->is_32b ? (shdr).shdr32.fld : (shdr).shdr64.fld)

#define ELF_SIZEOF_SHDR(fmt) (fmt->is_32b ? sizeof(elf32_shdr) : sizeof(elf64_shdr))


/* Valeurs possibles pour sh_type */

#define SHT_NULL        0                   /* Entrée non utilisée         */
#define SHT_PROGBITS    1                   /* Données de programme        */
#define SHT_SYMTAB      2                   /* Table des symboles          */
#define SHT_STRTAB      3                   /* Table de chaînes de carac.  */

#define SHT_RELA          4             /* Relocation entries with addends */
#define SHT_HASH          5             /* Symbol hash table */

#define SHT_DYNAMIC     6                   /* Info. de liaison dynamique  */

#define SHT_NOTE          7             /* Notes */
#define SHT_NOBITS        8             /* Program space with no data (bss) */
#define SHT_REL           9             /* Relocation entries, no addends */
#define SHT_SHLIB         10            /* Reserved */
#define SHT_DYNSYM        11            /* Dynamic linker symbol table */
#define SHT_INIT_ARRAY    14            /* Array of constructors */
#define SHT_FINI_ARRAY    15            /* Array of destructors */
#define SHT_PREINIT_ARRAY 16            /* Array of pre-constructors */
#define SHT_GROUP         17            /* Section group */
#define SHT_SYMTAB_SHNDX  18            /* Extended section indeces */
#define SHT_NUM           19            /* Number of defined types.  */
#define SHT_LOOS          0x60000000    /* Start OS-specific.  */
#define SHT_GNU_ATTRIBUTES 0x6ffffff5   /* Object attributes.  */
#define SHT_GNU_HASH      0x6ffffff6    /* GNU-style hash table.  */
#define SHT_GNU_LIBLIST   0x6ffffff7    /* Prelink library list */
#define SHT_CHECKSUM      0x6ffffff8    /* Checksum for DSO content.  */
#define SHT_LOSUNW        0x6ffffffa    /* Sun-specific low bound.  */
#define SHT_SUNW_move     0x6ffffffa
#define SHT_SUNW_COMDAT   0x6ffffffb
#define SHT_SUNW_syminfo  0x6ffffffc
#define SHT_GNU_verdef    0x6ffffffd    /* Version definition section.  */
#define SHT_GNU_verneed   0x6ffffffe    /* Version needs section.  */
#define SHT_GNU_versym    0x6fffffff    /* Version symbol table.  */
#define SHT_HISUNW        0x6fffffff    /* Sun-specific high bound.  */
#define SHT_HIOS          0x6fffffff    /* End OS-specific type */
#define SHT_LOPROC        0x70000000    /* Start of processor-specific */
#define SHT_HIPROC        0x7fffffff    /* End of processor-specific */
#define SHT_LOUSER        0x80000000    /* Start of application-specific */
#define SHT_HIUSER        0x8fffffff    /* End of application-specific */


/* Valeurs possibles pour sh_flags */

#define SHF_WRITE               (1 << 0)    /* Accessible en écriture      */
#define SHF_ALLOC               (1 << 1)    /* Copie en mémoire pdt l'exec.*/
#define SHF_EXECINSTR           (1 << 2)    /* Section exécutable          */
#define SHF_MERGE               (1 << 4)    /* Peut être fusionné          */
#define SHF_STRINGS             (1 << 5)    /* Contient des chaînes ('\0') */
#define SHF_INFO_LINK           (1 << 6)    /* 'sh_info' contient un index */
#define SHF_LINK_ORDER          (1 << 7)    /* Préservation de l'ordre     */
#define SHF_OS_NONCONFORMING    (1 << 8)    /* Gestion non standard requise*/
#define SHF_GROUP               (1 << 9)    /* Section membre d'un groupe  */
#define SHF_TLS                 (1 << 10)   /* Données pour un thread local*/

#define SHF_MASKOS           0x0ff00000 /* OS-specific.  */
#define SHF_MASKPROC         0xf0000000 /* Processor-specific */
#define SHF_ORDERED          (1 << 30)  /* Special ordering requirement
                                           (Solaris).  */
#define SHF_EXCLUDE          (1 << 31)  /* Section is excluded unless
                                           referenced or allocated (Solaris).*/





/* ----------------------------- DONNEES POUR LE LINKER ----------------------------- */


/* Entrées de la section dynamique (version 32 et 64 bits) */

typedef struct _elf32_dyn
{
    int32_t d_tag;                          /* Type de l'entrée            */

    union
    {
        uint32_t d_val;                     /* Valeur entière              */
        uint32_t d_ptr;                     /* Valeur d'adresse            */

    } d_un;

} elf32_dyn;

typedef struct _elf64_dyn
{
    int64_t d_tag;                          /* Type de l'entrée            */

    union
    {
        uint64_t d_val;                     /* Valeur entière              */
        uint64_t d_ptr;                     /* Valeur d'adresse            */

    } d_un;

} elf64_dyn;

typedef union _elf_dyn
{
    elf32_dyn dyn32;                        /* Version 32 bits             */
    elf64_dyn dyn64;                        /* Version 32 bits             */

} elf_dyn;


#define ELF_DYN(fmt, dyn, fld) (fmt->is_32b ? (dyn).dyn32.fld : (dyn).dyn64.fld)

#define ELF_SIZEOF_DYN(fmt) (fmt->is_32b ? sizeof(elf32_dyn) : sizeof(elf64_dyn))



/* Valeurs possibles pour d_tag */

#define DT_SYMTAB       6                   /* Table des symboles          */
#define DT_JMPREL       23                  /* Relocalisations PLT         */


#define DT_PLTGOT       3               /* Processor defined value */

#define DT_INIT         12              /* Address of init function */
#define DT_FINI         13              /* Address of termination function */

#define DT_INIT_ARRAY   25              /* Array with addresses of init fct */
#define DT_FINI_ARRAY   26              /* Array with addresses of fini fct */
#define DT_INIT_ARRAYSZ 27              /* Size in bytes of DT_INIT_ARRAY */
#define DT_FINI_ARRAYSZ 28              /* Size in bytes of DT_FINI_ARRAY */

#define DT_PREINIT_ARRAY 32             /* Array with addresses of preinit fct*/
#define DT_PREINIT_ARRAYSZ 33           /* size in bytes of DT_PREINIT_ARRAY */



/* ---------------------------- SYMBOLES DE BINAIRES ELF ---------------------------- */


/* Elément de la table des symboles */

typedef struct _elf32_sym
{
    uint32_t st_name;                       /* Indice pour le nom          */
    uint32_t st_value;                      /* Valeur du symbole           */
    uint32_t st_size;                       /* Taille du symbole           */
    unsigned char st_info;                  /* Type et infos. du symbole   */
    unsigned char st_other;                 /* Visibilité du symbole       */
    uint16_t st_shndx;                      /* Indice de la section        */

} elf32_sym;

typedef struct _elf64_sym
{
    uint32_t st_name;                       /* Indice pour le nom          */
    unsigned char st_info;                  /* Type et infos. du symbole   */
    unsigned char st_other;                 /* Visibilité du symbole       */
    uint16_t st_shndx;                      /* Indice de la section        */
    uint64_t st_value;                      /* Valeur du symbole           */
    uint64_t st_size;                       /* Taille du symbole           */

} elf64_sym;

typedef union _elf_sym
{
    elf32_sym sym32;                        /* Version 32 bits             */
    elf64_sym sym64;                        /* Version 64 bits             */

} elf_sym;


#define ELF_SYM(fmt, sb, fld) (fmt->is_32b ? (sb).sym32.fld : (sb).sym64.fld)

#define ELF_ST_BIND(fmt, sym) (fmt->is_32b ? ELF32_ST_BIND(sym.sym32.st_info) : ELF64_ST_BIND(sym.sym64.st_info))
#define ELF_ST_TYPE(fmt, sym) (fmt->is_32b ? ELF32_ST_TYPE(sym.sym32.st_info) : ELF64_ST_TYPE(sym.sym64.st_info))

#define ELF_SIZEOF_SYM(fmt) (fmt->is_32b ? sizeof(elf32_sym) : sizeof(elf64_sym))


/* Extraction des informations de st_info */

#define ELF32_ST_BIND(val)      (((unsigned char)(val)) >> 4)
#define ELF32_ST_TYPE(val)      ((val) & 0xf)

#define ELF64_ST_BIND(val)      ELF32_ST_BIND(val)
#define ELF64_ST_TYPE(val)      ELF32_ST_TYPE(val)

/* Valeurs pour le sous-champ ST_TYPE de st_info  */

#define STT_NOTYPE  0                       /* Type de symbole non spécifié*/
#define STT_OBJECT  1                       /* Symbole, objet de données   */
#define STT_FUNC    2                       /* Symbole, objet de code      */



/* ------------------------- INFORMATIONS DE RELOCALISATION ------------------------- */


/* Entrée de la table de relocalisation */

typedef struct _elf32_rel
{
    uint32_t r_offset;                      /* Adresse                     */
    uint32_t r_info;			            /* Indice de type et symbole   */

} elf32_rel;

typedef struct _elf64_rel
{
    uint64_t r_offset;                      /* Adresse                     */
    uint64_t r_info;			            /* Indice de type et symbole   */

} elf64_rel;

typedef union _elf_rel
{
    elf32_rel rel32;                        /* Version 32 bits             */
    elf64_rel rel64;                        /* Version 64 bits             */

} elf_rel;


#define ELF_REL(fmt, rl, fld) (fmt->is_32b ? (rl).rel32.fld : (rl).rel64.fld)

#define ELF_REL_SYM(fmt, rl) (fmt->is_32b ? ELF32_R_SYM(rl.rel32.r_info) : ELF64_R_SYM(rl.rel64.r_info))
#define ELF_REL_TYPE(fmt, rl) (fmt->is_32b ? ELF32_R_TYPE(rl.rel32.r_info) : ELF64_R_TYPE(rl.rel64.r_info))

#define ELF_SIZEOF_REL(fmt) (fmt->is_32b ? sizeof(elf32_rel) : sizeof(elf64_rel))


/* Extraction des informations de r_info */

#define ELF32_R_SYM(val)        ((val) >> 8)
#define ELF32_R_TYPE(val)       ((val) & 0xff)

#define ELF64_R_SYM(val)        ((val) >> 32)
#define ELF64_R_TYPE(val)       ((val) & 0xffffffff)

/* Type de relocalisation (x86) */

#define R_386_NONE          0               /* Pas de relocalisation       */
#define R_386_JMP_SLOT      7               /* Entrée PLT                  */

/* Type de relocalisation (ARM) */

#define R_ARM_JUMP_SLOT         22          /* Create PLT entry */



/* --------------------------- NOTES ARBITRAIRES LAISSEES --------------------------- */


/**
 * Notes contenues dans un fichier ELF.
 * Se rapporter au chapitre 5, partie "Note Section", des spécifications ABI
 * du Système V pour d'avantage d'informations.
 */

typedef struct _elf_note
{
    uint32_t namesz;                        /* Taille du nom éventuel      */
    uint32_t descsz;                        /* Qté de données éventuelles  */
    uint32_t type;                          /* Indication supplémentaire   */

    const char *name;                       /* Auteur de la note           */
    const void *desc;                       /* Données complémentaires     */

} elf_note;



#endif  /* _FORMAT_ELF_ELF_DEF_H */