L4Re - L4 Runtime Environment
elf.h
Go to the documentation of this file.
1 
19 /*
20  * (c) 2008-2009 Author(s)
21  * economic rights: Technische Universit├Ąt Dresden (Germany)
22  * This file is part of TUD:OS and distributed under the terms of the
23  * GNU Lesser General Public License 2.1.
24  * Please see the COPYING-LGPL-2.1 file for details.
25  */
26 
27 /* (c) 2003-2006 Technische Universitaet Dresden
28  * This file is part of the exec package, which is distributed under
29  * the terms of the GNU General Public License 2. Please see the
30  * COPYING file for details. */
31 
32 #ifndef _L4_EXEC_ELF_H
33 #define _L4_EXEC_ELF_H
34 
35 #include <l4/sys/l4int.h>
36 
60 
61 #if L4_MWORD_BITS == 64
62 
66 #define ElfW(type) _ElfW(Elf, 64, type)
67 #else
68 #define ElfW(type) _ElfW(Elf, 32, type)
69 #endif
70 #define _ElfW(e,w,t) __ElfW(e, w, _##t)
71 #define __ElfW(e,w,t) e##w##t
72 
73 #if defined(ARCH_x86)
74 #define L4_ARCH_EI_DATA ELFDATA2LSB
75 #define L4_ARCH_E_MACHINE EM_386
76 #define L4_ARCH_EI_CLASS ELFCLASS32
77 #elif defined(ARCH_amd64)
78 #define L4_ARCH_EI_DATA ELFDATA2LSB
79 #define L4_ARCH_E_MACHINE EM_X86_64
80 #define L4_ARCH_EI_CLASS ELFCLASS64
81 #elif defined(ARCH_arm)
82 #define L4_ARCH_EI_DATA ELFDATA2LSB
83 #define L4_ARCH_E_MACHINE EM_ARM
84 #define L4_ARCH_EI_CLASS ELFCLASS32
85 #elif defined(ARCH_arm64)
86 #define L4_ARCH_EI_DATA ELFDATA2LSB
87 #define L4_ARCH_E_MACHINE EM_AARCH64
88 #define L4_ARCH_EI_CLASS ELFCLASS64
89 #elif defined(ARCH_ppc32)
90 #define L4_ARCH_EI_DATA ELFDATA2MSB
91 #define L4_ARCH_E_MACHINE EM_PPC
92 #define L4_ARCH_EI_CLASS ELFCLASS32
93 #elif defined(ARCH_sparc)
94 #define L4_ARCH_EI_DATA ELFDATA2MSB
95 #define L4_ARCH_E_MACHINE EM_SPARC
96 #define L4_ARCH_EI_CLASS ELFCLASS32
97 #elif defined(ARCH_mips)
98 #define L4_ARCH_EI_DATA ELFDATA2LSB
99 #define L4_ARCH_E_MACHINE EM_MIPS
100 #ifdef __mips64
101 #define L4_ARCH_EI_CLASS ELFCLASS64
102 #else
103 #define L4_ARCH_EI_CLASS ELFCLASS32
104 #endif
105 #else
106 #warning elf.h: Unsupported build architecture!
107 #endif
108 
109 
110 /*************************************/
111 /* ELF Header - figure 1-3, page 1-3 */
112 /*************************************/
113 
117 
118 #define EI_NIDENT 16
122 typedef struct {
123  unsigned char e_ident[EI_NIDENT];
137 } Elf32_Ehdr;
138 
142 typedef struct {
143  unsigned char e_ident[EI_NIDENT];
157 } Elf64_Ehdr;
158 
159 #define EI_CLASS 4
160 #define ELFCLASSNONE 0
161 #define ELFCLASS32 1
162 #define ELFCLASS64 2
163 #define ELFCLASSNUM 3
165 #define EI_DATA 5
166 #define ELFDATANONE 0
167 #define ELFDATA2LSB 1
168 #define ELFDATA2MSB 2
169 #define ELFDATANUM 3
170 
171 #define EI_VERSION 6
174 #define EI_OSABI 7
175 #define ELFOSABI_NONE 0
176 #define ELFOSABI_SYSV 0
177 #define ELFOSABI_HPUX 1
178 #define ELFOSABI_NETBSD 2
179 #define ELFOSABI_LINUX 3
180 #define ELFOSABI_SOLARIS 6
181 #define ELFOSABI_AIX 7
182 #define ELFOSABI_IRIX 8
183 #define ELFOSABI_FREEBSD 9
184 #define ELFOSABI_TRU64 10
185 #define ELFOSABI_MODESTO 11
186 #define ELFOSABI_OPENBSD 12
187 #define ELFOSABI_ARM 97
188 #define ELFOSABI_STANDALONE 255
190 #define EI_ABIVERSION 8
192 #define EI_PAD 9
194 /* object file type - page 1-3 (e_type) */
195 
196 #define ET_NONE 0
197 #define ET_REL 1
198 #define ET_EXEC 2
199 #define ET_DYN 3
200 #define ET_CORE 4
201 #define ET_LOPROC 0xff00
202 #define ET_HIPROC 0xffff
204 /* required architecture - page 1-4 (e_machine) */
205 
206 #define EM_NONE 0
207 #define EM_M32 1
208 #define EM_SPARC 2
209 #define EM_386 3
210 #define EM_68K 4
211 #define EM_88K 5
212 #define EM_860 7
213 #define EM_MIPS 8
214 #define EM_MIPS_RS4_BE 10
215 #define EM_SPARC64 11
216 #define EM_PARISC 15
217 #define EM_VPP500 17
218 #define EM_SPARC32PLUS 18
219 #define EM_960 19
220 #define EM_PPC 20
221 #define EM_V800 36
222 #define EM_FR20 37
223 #define EM_RH32 38
224 #define EM_RCE 39
225 #define EM_ARM 40
226 #define EM_ALPHA 41
227 #define EM_SH 42
228 #define EM_SPARCV9 43
229 #define EM_TRICORE 44
230 #define EM_ARC 45
231 #define EM_H8_300 46
232 #define EM_H8_300H 47
233 #define EM_H8S 48
234 #define EM_H8_500 49
235 #define EM_IA_64 50
236 #define EM_MIPS_X 51
237 #define EM_COLDFIRE 52
238 #define EM_68HC12 53
239 #define EM_X86_64 62
240 #define EM_PDSP 63
241 #define EM_FX66 66
242 #define EM_ST9PLUS 67
243 #define EM_ST7 68
244 #define EM_68HC16 69
245 #define EM_68HC11 70
246 #define EM_68HC08 71
247 #define EM_68HC05 72
248 #define EM_SVX 73
249 #define EM_ST19 74
250 #define EM_VAX 75
251 #define EM_CRIS 76
252 #define EM_JAVELIN 77
253 #define EM_FIREPATH 78
254 #define EM_ZSP 79
255 #define EM_MMIX 80
256 #define EM_HUANY 81
257 #define EM_PRISM 82
258 #define EM_AVR 83
259 #define EM_FR30 84
260 #define EM_D10V 85
261 #define EM_D30V 86
262 #define EM_V850 87
263 #define EM_M32R 88
264 #define EM_MN10300 89
265 #define EM_MN10200 90
266 #define EM_PJ 91
267 #define EM_OPENRISC 92
268 #define EM_ARC_A5 93
269 #define EM_XTENSA 94
270 #define EM_ALTERA_NIOS2 113
271 #define EM_AARCH64 183
272 #define EM_TILEPRO 188
273 #define EM_MICROBLAZE 189
274 #define EM_TILEGX 191
275 #define EM_NUM 192
276 
277 #if 0
278 #define EM_ALPHA 0x9026 /* interium value used by Linux until the
279  committee comes up with a final number */
280 #define EM_S390 0xA390 /* interium value used for IBM S390 */
281 #endif
282 
283 /* object file version - page 1-4 (e_version) */
284 
285 #define EV_NONE 0
286 #define EV_CURRENT 1
288 /* e_ident[] Identification Indexes - figure 1-4, page 1-5 */
289 
290 #define EI_MAG0 0
291 #define EI_MAG1 1
292 #define EI_MAG2 2
293 #define EI_MAG3 3
294 #define EI_CLASS 4
295 #define EI_DATA 5
296 #define EI_VERSION 6
297 #define EI_OSABI 7
298 #define EI_ABIVERSION 8
299 #define EI_PAD 9
301 /* magic number - page 1-5 */
302 
303 #define ELFMAG0 0x7f
304 #define ELFMAG1 'E'
305 #define ELFMAG2 'L'
306 #define ELFMAG3 'F'
308 /* file class or capacity - page 1-6 */
309 
310 #define ELFCLASSNONE 0
311 #define ELFCLASSS32 1
312 #define ELFCLASSS64 2
314 /* data encoding - page 1-6 */
315 
316 #define ELFDATANONE 0
317 #define ELFDATA2LSB 1
318 #define ELFDATA2MSB 2
320 /* Identify operating system and ABI to which the object is targeted */
321 
322 #define ELFOSABI_SYSV 0
323 #define ELFOSABI_HPUX 1
324 #define ELFOSABI_STANDALONE 255
327 /***********************/
328 /* Sections - page 1-8 */
329 /***********************/
330 
331 /* special section indexes */
332 
333 #define SHN_UNDEF 0
334 #define SHN_LORESERVE 0xff00
335 #define SHN_LOPROC 0xff00
336 #define SHN_HIPROC 0xff1f
337 #define SHN_ABS 0xfff1
338 #define SHN_COMMON 0xfff2
339 #define SHN_HIRESERVE 0xffff
342 typedef struct {
353 } Elf32_Shdr;
354 
356 typedef struct {
367 } Elf64_Shdr;
368 
369 /* section type - figure 1-10, page 1-10 */
370 
371 #define SHT_NULL 0
372 #define SHT_PROGBITS 1
373 #define SHT_SYMTAB 2
374 #define SHT_STRTAB 3
375 #define SHT_RELA 4
376 #define SHT_HASH 5
377 #define SHT_DYNAMIC 6
378 #define SHT_NOTE 7
379 #define SHT_NOBITS 8
380 #define SHT_REL 9
381 #define SHT_SHLIB 10
382 #define SHT_DYNSYM 11
383 #define SHT_INIT_ARRAY 14
384 #define SHT_FINI_ARRAY 15
385 #define SHT_PREINIT_ARRAY 16
386 #define SHT_GROUP 17
387 #define SHT_SYMTAB_SHNDX 18
388 #define SHT_NUM 19
389 #define SHT_LOOS 0x60000000
390 #define SHT_HIOS 0x6fffffff
391 #define SHT_LOPROC 0x70000000
392 #define SHT_HIPROC 0x7fffffff
393 #define SHT_LOUSER 0x80000000
394 #define SHT_HIUSER 0xffffffff
395 
396 /* section attribute flags - page 1-12, figure 1-12 */
397 
398 #define SHF_WRITE 0x1
399 #define SHF_ALLOC 0x2
400 #define SHF_EXECINSTR 0x4
401 #define SHF_MERGE 0x10
402 #define SHF_STRINGS 0x20
403 #define SHF_INFO_LINK 0x40
404 #define SHF_LINK_ORDER 0x80
405 #define SHF_OS_NONCONFORMING 0x100
407 #define SHF_GROUP 0x200
408 #define SHF_TLS 0x400
409 #define SHF_MASKOS 0x0ff00000
410 #define SHF_MASKPROC 0xf0000000
413 /*****************************************/
414 /* Program Header - figure 2-1, page 2-2 */
415 /*****************************************/
416 
418 typedef struct {
419  Elf32_Word p_type;
420  Elf32_Off p_offset;
421  Elf32_Addr p_vaddr;
422  Elf32_Addr p_paddr;
423  Elf32_Word p_filesz;
424  Elf32_Word p_memsz;
425  Elf32_Word p_flags;
426  Elf32_Word p_align;
428 
430 typedef struct {
431  Elf64_Word p_type;
432  Elf64_Word p_flags;
433  Elf64_Off p_offset;
434  Elf64_Addr p_vaddr;
435  Elf64_Addr p_paddr;
436  Elf64_Xword p_filesz;
437  Elf64_Xword p_memsz;
438  Elf64_Xword p_align;
440 
441 /* segment types - figure 2-2, page 2-3 */
442 
443 #define PT_NULL 0
444 #define PT_LOAD 1
445 #define PT_DYNAMIC 2
446 #define PT_INTERP 3
447 #define PT_NOTE 4
448 #define PT_SHLIB 5
449 #define PT_PHDR 6
450 #define PT_TLS 7
451 #define PT_NUM 8
452 #define PT_LOOS 0x60000000
453 #define PT_HIOS 0x6fffffff
454 #define PT_LOPROC 0x70000000
455 #define PT_HIPROC 0x7fffffff
457 #define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550)
458 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
459 #define PT_GNU_RELRO (PT_LOOS + 0x474e552)
461 #define PT_L4_STACK (PT_LOOS + 0x12)
462 #define PT_L4_KIP (PT_LOOS + 0x13)
463 #define PT_L4_AUX (PT_LOOS + 0x14)
465 /* segment permissions - page 2-3 */
466 
467 #define PF_X 0x1
468 #define PF_W 0x2
469 #define PF_R 0x4
470 #define PF_MASKOS 0x0ff00000
471 #define PF_MASKPROC 0x7fffffff
472 
473 /* Legal values for note segment descriptor types for core files. */
474 
475 #define NT_PRSTATUS 1
476 #define NT_FPREGSET 2
477 #define NT_PRPSINFO 3
478 #define NT_PRXREG 4
479 #define NT_TASKSTRUCT 4
480 #define NT_PLATFORM 5
481 #define NT_AUXV 6
482 #define NT_GWINDOWS 7
483 #define NT_ASRS 8
484 #define NT_PSTATUS 10
485 #define NT_PSINFO 13
486 #define NT_PRCRED 14
487 #define NT_UTSNAME 15
488 #define NT_LWPSTATUS 16
489 #define NT_LWPSINFO 17
490 #define NT_PRFPXREG 20
492 /* Legal values for the note segment descriptor types for object files. */
493 
494 #define NT_VERSION 1
496 /* Dynamic structure - figure 2-9, page 2-12 */
497 
499 typedef struct {
500  Elf32_Sword d_tag;
501  union {
502  Elf32_Word d_val;
503  Elf32_Addr d_ptr;
504  } d_un;
505 } Elf32_Dyn;
506 
508 typedef struct {
509  Elf64_Sxword d_tag;
510  union {
511  Elf64_Xword d_val;
512  Elf64_Addr d_ptr;
513  } d_un;
514 } Elf64_Dyn;
515 
518 #define DT_NULL 0
519 #define DT_NEEDED 1
520 #define DT_PLTRELSZ 2
521 #define DT_PLTGOT 3
522 #define DT_HASH 4
523 #define DT_STRTAB 5
524 #define DT_SYMTAB 6
525 #define DT_RELA 7
526 #define DT_RELASZ 8
527 #define DT_RELAENT 9
528 #define DT_STRSZ 10
529 #define DT_SYMENT 11
530 #define DT_INIT 12
531 #define DT_FINI 13
532 #define DT_SONAME 14
533 #define DT_RPATH 15
534 #define DT_SYMBOLIC 16
535 #define DT_REL 17
536 #define DT_RELSZ 18
537 #define DT_RELENT 19
538 #define DT_PTRREL 20
539 #define DT_DEBUG 21
540 #define DT_TEXTREL 22
541 #define DT_JMPREL 23
542 #define DT_BIND_NOW 24
543 #define DT_INIT_ARRAY 25
544 #define DT_FINI_ARRAY 26
545 #define DT_INIT_ARRAYSZ 27
546 #define DT_FINI_ARRAYSZ 28
547 #define DT_RUNPATH 29
548 #define DT_FLAGS 30
549 #define DT_ENCODING 32
550 #define DT_PREINIT_ARRAY 32
551 #define DT_PREINIT_ARRAYSZ 33
552 #define DT_NUM 34
553 #define DT_LOOS 0x6000000d
554 #define DT_HIOS 0x6ffff000
555 #define DT_LOPROC 0x70000000
556 #define DT_HIPROC 0x7fffffff
558 /* Values of `d_un.d_val' in the DT_FLAGS entry. */
559 #define DF_ORIGIN 0x00000001
560 #define DF_SYMBOLIC 0x00000002
561 #define DF_TEXTREL 0x00000004
562 #define DF_BIND_NOW 0x00000008
563 #define DF_STATIC_TLS 0x00000010
565 /* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
566  entry in the dynamic section. */
567 #define DF_1_NOW 0x00000001
568 #define DF_1_GLOBAL 0x00000002
569 #define DF_1_GROUP 0x00000004
570 #define DF_1_NODELETE 0x00000008
571 #define DF_1_LOADFLTR 0x00000010
572 #define DF_1_INITFIRST 0x00000020
573 #define DF_1_NOOPEN 0x00000040
574 #define DF_1_ORIGIN 0x00000080
575 #define DF_1_DIRECT 0x00000100
576 #define DF_1_TRANS 0x00000200
577 #define DF_1_INTERPOSE 0x00000400
578 #define DF_1_NODEFLIB 0x00000800
579 #define DF_1_NODUMP 0x00001000
580 #define DF_1_CONFALT 0x00002000
581 #define DF_1_ENDFILTEE 0x00004000
582 #define DF_1_DISPRELDNE 0x00008000
583 #define DF_1_DISPRELPND 0x00010000
585 /* Flags for the feature selection in DT_FEATURE_1. */
586 #define DTF_1_PARINIT 0x00000001
587 #define DTF_1_CONFEXP 0x00000002
588 
589 /* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */
590 #define DF_P1_LAZYLOAD 0x00000001
591 #define DF_P1_GROUPPERM 0x00000002
594 /* Relocation - page 1-21, figure 1-20 */
595 
596 typedef struct {
597  Elf32_Addr r_offset;
598  Elf32_Word r_info;
599 } Elf32_Rel;
600 
601 typedef struct {
602  Elf32_Addr r_offset;
603  Elf32_Word r_info;
604  Elf32_Sword r_addend;
605 } Elf32_Rela;
606 
607 typedef struct {
608  Elf64_Addr r_offset;
609  Elf64_Xword r_info;
610 } Elf64_Rel;
611 
612 typedef struct {
613  Elf64_Addr r_offset;
614  Elf64_Xword r_info;
615  Elf64_Sxword r_addend;
616 } Elf64_Rela;
617 
618 #define ELF32_R_SYM(i) ((i)>>8)
619 #define ELF32_R_TYPE(i) ((unsigned char)(i))
620 #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
621 
622 #define ELF64_R_SYM(i) ((i)>>32)
623 #define ELF64_R_TYPE(i) ((i)&0xffffffffL)
624 #define ELF64_R_INFO(s,t) (((s)<<32)+(t)&0xffffffffL)
625 
626 /* Relocation types (processor specific) - page 1-23, figure 1-22 */
627 
628 #define R_386_NONE 0
629 #define R_386_32 1
630 #define R_386_PC32 2
631 #define R_386_GOT32 3
632 #define R_386_PLT32 4
633 #define R_386_COPY 5
634 #define R_386_GLOB_DAT 6
635 #define R_386_JMP_SLOT 7
636 #define R_386_RELATIVE 8
637 #define R_386_GOTOFF 9
638 #define R_386_GOTPC 10
639 #define R_386_32PLT 11
640 #define R_386_TLS_TPOFF 14 /* Offset in static TLS block */
641 #define R_386_TLS_IE 15 /* Address of GOT entry for static TLS
642  block offset */
643 #define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block
644  offset */
645 #define R_386_TLS_LE 17 /* Offset relative to static TLS
646  block */
647 #define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of
648  general dynamic thread local data */
649 #define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of
650  local dynamic thread local data
651  in LE code */
652 #define R_386_16 20
653 #define R_386_PC16 21
654 #define R_386_8 22
655 #define R_386_PC8 23
656 #define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic
657  thread local data */
658 #define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */
659 #define R_386_TLS_GD_CALL 26 /* Relocation for call to
660  __tls_get_addr() */
661 #define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */
662 #define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic
663  thread local data in LE code */
664 #define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */
665 #define R_386_TLS_LDM_CALL 30 /* Relocation for call to
666  __tls_get_addr() in LDM code */
667 #define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */
668 #define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */
669 #define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS
670  block offset */
671 #define R_386_TLS_LE_32 34 /* Negated offset relative to static
672  TLS block */
673 #define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */
674 #define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */
675 #define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */
676 /* Keep this the last entry. */
677 #define R_386_NUM 38
678 
679 /* ARM specific declarations */
680 
681 /* Processor specific flags for the ELF header e_flags field. */
682 #define EF_ARM_RELEXEC 0x01
683 #define EF_ARM_HASENTRY 0x02
684 #define EF_ARM_INTERWORK 0x04
685 #define EF_ARM_APCS_26 0x08
686 #define EF_ARM_APCS_FLOAT 0x10
687 #define EF_ARM_PIC 0x20
688 #define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */
689 #define EF_ARM_NEW_ABI 0x80
690 #define EF_ARM_OLD_ABI 0x100
691 
692 /* Other constants defined in the ARM ELF spec. version B-01. */
693 /* NB. These conflict with values defined above. */
694 #define EF_ARM_SYMSARESORTED 0x04
695 #define EF_ARM_DYNSYMSUSESEGIDX 0x08
696 #define EF_ARM_MAPSYMSFIRST 0x10
697 #define EF_ARM_EABIMASK 0XFF000000
698 
699 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
700 #define EF_ARM_EABI_UNKNOWN 0x00000000
701 #define EF_ARM_EABI_VER1 0x01000000
702 #define EF_ARM_EABI_VER2 0x02000000
703 
704 /* Additional symbol types for Thumb */
705 #define STT_ARM_TFUNC 0xd
706 
707 /* ARM-specific values for sh_flags */
708 #define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */
709 #define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined
710  in the input to a link step */
711 
712 /* ARM-specific program header flags */
713 #define PF_ARM_SB 0x10000000 /* Segment contains the location
714  addressed by the static base */
715 
716 /* ARM relocs. */
717 #define R_ARM_NONE 0 /* No reloc */
718 #define R_ARM_PC24 1 /* PC relative 26 bit branch */
719 #define R_ARM_ABS32 2 /* Direct 32 bit */
720 #define R_ARM_REL32 3 /* PC relative 32 bit */
721 #define R_ARM_PC13 4
722 #define R_ARM_ABS16 5 /* Direct 16 bit */
723 #define R_ARM_ABS12 6 /* Direct 12 bit */
724 #define R_ARM_THM_ABS5 7
725 #define R_ARM_ABS8 8 /* Direct 8 bit */
726 #define R_ARM_SBREL32 9
727 #define R_ARM_THM_PC22 10
728 #define R_ARM_THM_PC8 11
729 #define R_ARM_AMP_VCALL9 12
730 #define R_ARM_SWI24 13
731 #define R_ARM_THM_SWI8 14
732 #define R_ARM_XPC25 15
733 #define R_ARM_THM_XPC22 16
734 #define R_ARM_COPY 20 /* Copy symbol at runtime */
735 #define R_ARM_GLOB_DAT 21 /* Create GOT entry */
736 #define R_ARM_JUMP_SLOT 22 /* Create PLT entry */
737 #define R_ARM_RELATIVE 23 /* Adjust by program base */
738 #define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */
739 #define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */
740 #define R_ARM_GOT32 26 /* 32 bit GOT entry */
741 #define R_ARM_PLT32 27 /* 32 bit PLT address */
742 #define R_ARM_ALU_PCREL_7_0 32
743 #define R_ARM_ALU_PCREL_15_8 33
744 #define R_ARM_ALU_PCREL_23_15 34
745 #define R_ARM_LDR_SBREL_11_0 35
746 #define R_ARM_ALU_SBREL_19_12 36
747 #define R_ARM_ALU_SBREL_27_20 37
748 #define R_ARM_GNU_VTENTRY 100
749 #define R_ARM_GNU_VTINHERIT 101
750 #define R_ARM_THM_PC11 102 /* thumb unconditional branch */
751 #define R_ARM_THM_PC9 103 /* thumb conditional branch */
752 #define R_ARM_RXPC25 249
753 #define R_ARM_RSBREL32 250
754 #define R_ARM_THM_RPC22 251
755 #define R_ARM_RREL32 252
756 #define R_ARM_RABS22 253
757 #define R_ARM_RPC24 254
758 #define R_ARM_RBASE 255
759 /* Keep this the last entry. */
760 #define R_ARM_NUM 256
761 
762 /* AMD x86-64 relocations. */
763 #define R_X86_64_NONE 0 /* No reloc */
764 #define R_X86_64_64 1 /* Direct 64 bit */
765 #define R_X86_64_PC32 2 /* PC relative 32 bit signed */
766 #define R_X86_64_GOT32 3 /* 32 bit GOT entry */
767 #define R_X86_64_PLT32 4 /* 32 bit PLT address */
768 #define R_X86_64_COPY 5 /* Copy symbol at runtime */
769 #define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
770 #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
771 #define R_X86_64_RELATIVE 8 /* Adjust by program base */
772 #define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative
773  offset to GOT */
774 #define R_X86_64_32 10 /* Direct 32 bit zero extended */
775 #define R_X86_64_32S 11 /* Direct 32 bit sign extended */
776 #define R_X86_64_16 12 /* Direct 16 bit zero extended */
777 #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
778 #define R_X86_64_8 14 /* Direct 8 bit sign extended */
779 #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
780 #define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */
781 #define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */
782 #define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */
783 #define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset
784  to two GOT entries for GD symbol */
785 #define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset
786  to two GOT entries for LD symbol */
787 #define R_X86_64_DTPOFF32 21 /* Offset in TLS block */
788 #define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset
789  to GOT entry for IE symbol */
790 #define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */
791 
792 #define R_X86_64_NUM 24
793 
794 /* Symbol Table Entry - page 1-17, figure 1-16 */
795 
796 #define STN_UNDEF 0
797 
799 typedef struct {
800  Elf32_Word st_name;
801  Elf32_Addr st_value;
802  Elf32_Word st_size;
803  unsigned char st_info;
804  unsigned char st_other;
805  Elf32_Half st_shndx;
809 typedef struct {
810  Elf64_Word st_name;
811  unsigned char st_info;
812  unsigned char st_other;
813  Elf64_Half st_shndx;
814  Elf64_Addr st_value;
815  Elf64_Xword st_size;
818 #define ELF32_ST_BIND(i) ((i)>>4)
819 #define ELF32_ST_TYPE(i) ((i)&0xf)
820 #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
821 
822 #define ELF64_ST_BIND(i) ((i)>>4)
823 #define ELF64_ST_TYPE(i) ((i)&0xf)
824 #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
825 
826 /* Symbol Binding - page 1-18, figure 1-17 */
827 
828 #define STB_LOCAL 0
829 #define STB_GLOBAL 1
830 #define STB_WEAK 2
831 #define STB_LOOS 10
832 #define STB_HIOS 12
833 #define STB_LOPROC 13
834 #define STB_HIPROC 15
836 /* Symbol Types - page 1-19, figure 1-18 */
837 
838 #define STT_NOTYPE 0
839 #define STT_OBJECT 1
840 #define STT_FUNC 2
841 #define STT_SECTION 3
842 #define STT_FILE 4
843 #define STT_LOOS 10
844 #define STT_HIOS 12
845 #define STT_LOPROC 13
846 #define STT_HIPROC 15
848 enum Elf_ATs
849 {
850  AT_NULL = 0,
851  AT_IGNORE = 1,
852  AT_EXECFD = 2,
853  AT_PHDR = 3,
854  AT_PHENT = 4,
855  AT_PHNUM = 5,
856  AT_PAGESZ = 6,
857  AT_BASE = 7,
858  AT_FLAGS = 8,
859  AT_ENTRY = 9,
860  AT_NOTELF = 10,
861  AT_UID = 11,
862  AT_EUID = 12,
863  AT_GID = 13,
864  AT_EGID = 14,
865 
866  AT_L4_AUX = 0xf0,
867  AT_L4_ENV = 0xf1,
868 };
869 
870 typedef struct Elf32_Auxv
871 {
872  Elf32_Word atype;
873  Elf32_Word avalue;
874 } Elf32_Auxv;
875 
876 typedef struct Elf64_Auxv
877 {
878  Elf64_Word atype;
879  Elf64_Word avalue;
880 } Elf64_Auxv;
881 
882 /* Some helpers */
883 static inline int l4util_elf_check_magic(ElfW(Ehdr) *hdr);
884 static inline int l4util_elf_check_arch(ElfW(Ehdr) *hdr);
885 static inline ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr);
886 
887 
888 /* Implemeantions */
889 static inline
890 int l4util_elf_check_magic(ElfW(Ehdr) *hdr)
891 {
892  return hdr->e_ident[EI_MAG0] == ELFMAG0
893  && hdr->e_ident[EI_MAG1] == ELFMAG1
894  && hdr->e_ident[EI_MAG2] == ELFMAG2
895  && hdr->e_ident[EI_MAG3] == ELFMAG3;
896 }
897 
898 static inline
899 int l4util_elf_check_arch(ElfW(Ehdr) *hdr)
900 {
901  return hdr->e_ident[EI_CLASS] == L4_ARCH_EI_CLASS
902  && hdr->e_ident[EI_DATA] == L4_ARCH_EI_DATA
903  && hdr->e_machine == L4_ARCH_E_MACHINE;
904 }
905 
906 static inline
907 ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr)
908 {
909  return (ElfW(Phdr) *)((char *)hdr + hdr->e_phoff);
910 }
913 #endif /* _L4_EXEC_ELF_H */
Elf64_Addr e_entry
initial eip
Definition: elf.h:147
l4_uint64_t Elf64_Addr
size 8 align 8
Definition: elf.h:52
Elf64_Word sh_link
idx to associated header section
Definition: elf.h:363
Elf64_Half e_phentsize
size of program header entry
Definition: elf.h:152
l4_uint16_t Elf64_Half
size 2 align 2
Definition: elf.h:54
Elf64_Half e_machine
required architecture
Definition: elf.h:145
Elf32_Word sh_flags
section&#39;s flags
Definition: elf.h:345
Elf32_Off e_shoff
offset of file header table
Definition: elf.h:129
Elf32_Word e_version
file version
Definition: elf.h:126
ELF32 header.
Definition: elf.h:122
Elf32_Word e_flags
processor-specific flags
Definition: elf.h:130
ELF32 section header - figure 1-9, page 1-9.
Definition: elf.h:342
l4_uint32_t Elf32_Word
size 4 align 4
Definition: elf.h:50
#define EI_MAG3
file id
Definition: elf.h:293
Elf32_Half e_type
type of ELF file
Definition: elf.h:124
Elf32_Half e_shnum
of entries in sect.
Definition: elf.h:135
signed int l4_int32_t
Signed 32bit value.
Definition: l4int.h:39
Elf32_Word sh_link
idx to associated header section
Definition: elf.h:349
Elf64_Half e_shentsize
size of section header entry
Definition: elf.h:154
Elf64_Half e_shnum
of entries in sect.
Definition: elf.h:155
ELF32 symbol table entry.
Definition: elf.h:801
Elf64_Xword sh_flags
section&#39;s flags
Definition: elf.h:359
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
l4_int32_t Elf32_Sword
size 4 align 4
Definition: elf.h:51
Elf32_Half e_phentsize
size of program header entry
Definition: elf.h:132
Elf32_Word sh_addralign
address alignment constraints
Definition: elf.h:351
signed long long l4_int64_t
Signed 64bit value.
Definition: l4int.h:41
Elf32_Word sh_info
extra info of header section
Definition: elf.h:350
#define ELFMAG1
e_ident[EI_MAG1]
Definition: elf.h:304
Elf64_Half e_shstrndx
sect.head.tab.idx of strtab
Definition: elf.h:156
Elf64_Xword sh_entsize
size of entry if sect is table
Definition: elf.h:366
l4_int64_t Elf64_Sxword
size 8 align 8
Definition: elf.h:58
l4_uint32_t Elf32_Addr
size 4 align 4
Definition: elf.h:47
#define EI_CLASS
ELF class byte index.
Definition: elf.h:294
ELF32 dynamic entry.
Definition: elf.h:500
#define ELFMAG0
e_ident[EI_MAG0]
Definition: elf.h:303
Elf32_Word sh_size
file size of section
Definition: elf.h:348
Elf32_Addr sh_addr
memory address of section
Definition: elf.h:346
Elf32_Half e_shstrndx
sect.head.tab.idx of strtab
Definition: elf.h:136
Elf64_Word e_flags
processor-specific flags
Definition: elf.h:150
Elf32_Word sh_entsize
size of entry if sect is table
Definition: elf.h:352
#define EI_DATA
Data encoding byte index.
Definition: elf.h:295
#define EI_MAG2
file id
Definition: elf.h:292
Elf64_Off sh_offset
file offset of section
Definition: elf.h:361
l4_uint64_t Elf64_Off
size 8 align 8
Definition: elf.h:53
Elf32_Off e_phoff
offset of program header table
Definition: elf.h:128
Elf64_Xword sh_addralign
address alignment constraints
Definition: elf.h:365
#define ELFMAG3
e_ident[EI_MAG3]
Definition: elf.h:306
Elf64_Half e_type
type of ELF file
Definition: elf.h:144
Elf32_Addr e_entry
initial eip
Definition: elf.h:127
Elf32_Word sh_name
name of sect (idx into strtab)
Definition: elf.h:343
Elf32_Half e_shentsize
size of section header entry
Definition: elf.h:134
Elf64_Word sh_type
section&#39;s type
Definition: elf.h:358
#define EI_MAG1
file id
Definition: elf.h:291
ELF64 dynamic entry.
Definition: elf.h:509
#define EI_MAG0
file id
Definition: elf.h:290
Elf64_Off e_shoff
offset of file header table
Definition: elf.h:149
Elf32_Half e_phnum
of entries in prog.
Definition: elf.h:133
Elf32_Word sh_type
section&#39;s type
Definition: elf.h:344
#define ELFMAG2
e_ident[EI_MAG2]
Definition: elf.h:305
Elf64_Addr sh_addr
memory address of section
Definition: elf.h:360
l4_uint64_t Elf64_Xword
size 8 align 8
Definition: elf.h:57
Elf64_Half e_phnum
of entries in prog.
Definition: elf.h:153
Elf32_Half e_machine
required architecture
Definition: elf.h:125
Elf32_Half e_ehsize
size of ELF header
Definition: elf.h:131
l4_uint32_t Elf32_Off
size 4 align 4
Definition: elf.h:48
Elf64_Word e_version
file version
Definition: elf.h:146
Elf64_Word sh_info
extra info of header section
Definition: elf.h:364
Elf32_Off sh_offset
file offset of section
Definition: elf.h:347
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition: l4int.h:42
l4_uint32_t Elf64_Word
size 4 align 4
Definition: elf.h:55
#define EI_NIDENT
number of characters
Definition: elf.h:118
ELF64 program header.
Definition: elf.h:431
Elf64_Xword sh_size
file size of section
Definition: elf.h:362
l4_uint16_t Elf32_Half
size 2 align 2
Definition: elf.h:49
Elf64_Half e_ehsize
size of ELF header
Definition: elf.h:151
ELF64 symbol table entry.
Definition: elf.h:811
ELF32 program header.
Definition: elf.h:419
Elf64_Word sh_name
name of sect (idx into strtab)
Definition: elf.h:357
l4_int32_t Elf64_Sword
size 4 align 4
Definition: elf.h:56
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
Elf64_Off e_phoff
offset of program header table
Definition: elf.h:148
ELF64 header.
Definition: elf.h:142
ELF64 section header.
Definition: elf.h:356