Main Page   File List  

elf.h

00001 /* $Id: elf.h 31601 2008-05-12 06:37:53Z adam $ */
00018 /* (c) 2003-2006 Technische Universitaet Dresden
00019  * This file is part of the exec package, which is distributed under
00020  * the terms of the GNU General Public License 2. Please see the
00021  * COPYING file for details. */
00022 
00023 #ifndef _L4_EXEC_ELF_H
00024 #define _L4_EXEC_ELF_H
00025 
00026 #include <l4/sys/l4int.h>
00027 
00028 /* map ELF types to L4 types */
00029 
00030 typedef l4_uint32_t     Elf32_Addr;             /* size 4 align 4 */
00031 typedef l4_uint32_t     Elf32_Off;              /* size 4 align 4 */
00032 typedef l4_uint16_t     Elf32_Half;             /* size 2 align 2 */
00033 typedef l4_uint32_t     Elf32_Word;             /* size 4 align 4 */
00034 typedef l4_int32_t      Elf32_Sword;            /* size 4 align 4 */
00035 
00036 typedef l4_uint64_t     Elf64_Addr;             /* size 8 align 8 */
00037 typedef l4_uint64_t     Elf64_Off;              /* size 8 align 8 */
00038 typedef l4_uint16_t     Elf64_Half;             /* size 2 align 2 */
00039 typedef l4_uint32_t     Elf64_Word;             /* size 4 align 4 */
00040 typedef l4_int32_t      Elf64_Sword;            /* size 4 align 4 */
00041 typedef l4_uint64_t     Elf64_Xword;            /* size 8 align 8 */
00042 typedef l4_int64_t      Elf64_Sxword;           /* size 8 align 8 */
00043 
00044 #if L4_MWORD_BITS == 64
00045 #define ElfW(type)      _ElfW(Elf, 64, type)
00046 #else
00047 #define ElfW(type)      _ElfW(Elf, 32, type)
00048 #endif
00049 #define _ElfW(e,w,t)    __ElfW(e, w, _##t)
00050 #define __ElfW(e,w,t)   e##w##t
00051 
00052 #ifdef ARCH_x86
00053 #define L4_ARCH_EI_DATA      ELFDATA2LSB
00054 #define L4_ARCH_E_MACHINE    EM_386
00055 #define L4_ARCH_EI_CLASS     ELFCLASS32
00056 #else
00057 #ifdef ARCH_amd64
00058 #define L4_ARCH_EI_DATA      ELFDATA2LSB
00059 #define L4_ARCH_E_MACHINE    EM_AMD64
00060 #define L4_ARCH_EI_CLASS     ELFCLASS64
00061 #else
00062 #ifdef ARCH_arm
00063 #define L4_ARCH_EI_DATA      ELFDATA2LSB
00064 #define L4_ARCH_E_MACHINE    EM_ARM
00065 #define L4_ARCH_EI_CLASS     ELFCLASS32
00066 #else
00067 #warning elf.h: Unsupported build architecture!
00068 #endif
00069 #endif
00070 #endif
00071 
00072 
00073 /*************************************/
00074 /* ELF Header - figure 1-3, page 1-3 */
00075 /*************************************/
00076 
00077 #define EI_NIDENT 16                    
00079 typedef struct {
00080     unsigned char       e_ident[EI_NIDENT];
00081     Elf32_Half          e_type;         
00082     Elf32_Half          e_machine;      
00083     Elf32_Word          e_version;      
00084     Elf32_Addr          e_entry;        
00085     Elf32_Off           e_phoff;        
00086     Elf32_Off           e_shoff;        
00087     Elf32_Word          e_flags;        
00088     Elf32_Half          e_ehsize;       
00089     Elf32_Half          e_phentsize;    
00090     Elf32_Half          e_phnum;        
00091     Elf32_Half          e_shentsize;    
00092     Elf32_Half          e_shnum;        
00093     Elf32_Half          e_shstrndx;     
00094 } Elf32_Ehdr;
00095 
00097 typedef struct {
00098     unsigned char       e_ident[EI_NIDENT];
00099     Elf64_Half          e_type;         
00100     Elf64_Half          e_machine;      
00101     Elf64_Word          e_version;      
00102     Elf64_Addr          e_entry;        
00103     Elf64_Off           e_phoff;        
00104     Elf64_Off           e_shoff;        
00105     Elf64_Word          e_flags;        
00106     Elf64_Half          e_ehsize;       
00107     Elf64_Half          e_phentsize;    
00108     Elf64_Half          e_phnum;        
00109     Elf64_Half          e_shentsize;    
00110     Elf64_Half          e_shnum;        
00111     Elf64_Half          e_shstrndx;     
00112 } Elf64_Ehdr;
00113 
00114 #define EI_CLASS        4               /* File class byte index */
00115 #define ELFCLASSNONE    0               /* Invalid class */
00116 #define ELFCLASS32      1               /* 32-bit objects */
00117 #define ELFCLASS64      2               /* 64-bit objects */
00118 #define ELFCLASSNUM     3
00119 
00120 #define EI_DATA         5               /* Data encoding byte index */
00121 #define ELFDATANONE     0               /* Invalid data encoding */
00122 #define ELFDATA2LSB     1               /* 2's complement, little endian */
00123 #define ELFDATA2MSB     2               /* 2's complement, big endian */
00124 #define ELFDATANUM      3
00125 
00126 #define EI_VERSION      6               /* File version byte index */
00127                                         /* Value must be EV_CURRENT */
00128 
00129 #define EI_OSABI        7               /* OS ABI identification */
00130 #define ELFOSABI_NONE           0       /* UNIX System V ABI */
00131 #define ELFOSABI_SYSV           0       /* Alias.  */
00132 #define ELFOSABI_HPUX           1       /* HP-UX */
00133 #define ELFOSABI_NETBSD         2       /* NetBSD.  */
00134 #define ELFOSABI_LINUX          3       /* Linux.  */
00135 #define ELFOSABI_SOLARIS        6       /* Sun Solaris.  */
00136 #define ELFOSABI_AIX            7       /* IBM AIX.  */
00137 #define ELFOSABI_IRIX           8       /* SGI Irix.  */
00138 #define ELFOSABI_FREEBSD        9       /* FreeBSD.  */
00139 #define ELFOSABI_TRU64          10      /* Compaq TRU64 UNIX.  */
00140 #define ELFOSABI_MODESTO        11      /* Novell Modesto.  */
00141 #define ELFOSABI_OPENBSD        12      /* OpenBSD.  */
00142 #define ELFOSABI_ARM            97      /* ARM */
00143 #define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
00144 
00145 #define EI_ABIVERSION   8               /* ABI version */
00146 
00147 #define EI_PAD          9               /* Byte index of padding bytes */
00148 
00149 /* object file type - page 1-3 (e_type) */
00150 
00151 #define ET_NONE         0       
00152 #define ET_REL          1       
00153 #define ET_EXEC         2       
00154 #define ET_DYN          3       
00155 #define ET_CORE         4       
00156 #define ET_LOPROC       0xff00  
00157 #define ET_HIPROC       0xffff  
00159 /* required architecture - page 1-4 (e_machine) */
00160 
00161 #define EM_NONE         0       
00162 #define EM_M32          1       
00163 #define EM_SPARC        2       
00164 #define EM_386          3       
00165 #define EM_68K          4       
00166 #define EM_88K          5       
00167 #define EM_860          7       
00168 #define EM_MIPS         8       
00169 #define EM_MIPS_RS4_BE  10      
00170 #define EM_SPARC64      11      
00171 #define EM_PARISC       15      
00172 #define EM_VPP500       17      
00173 #define EM_SPARC32PLUS  18      
00174 #define EM_960          19      
00175 #define EM_PPC          20      
00176 #define EM_V800         36      
00177 #define EM_FR20         37      
00178 #define EM_RH32         38      
00179 #define EM_RCE          39      
00180 #define EM_ARM          40      
00181 #define EM_ALPHA        41      
00182 #define EM_SH           42      
00183 #define EM_SPARCV9      43      
00184 #define EM_TRICORE      44      
00185 #define EM_ARC          45      
00186 #define EM_H8_300       46      
00187 #define EM_H8_300H      47      
00188 #define EM_H8S          48      
00189 #define EM_H8_500       49      
00190 #define EM_IA_64        50      
00191 #define EM_MIPS_X       51      
00192 #define EM_COLDFIRE     52      
00193 #define EM_68HC12       53      
00194 #define EM_AMD64        62
00195 
00196 #if 0
00197 #define EM_ALPHA        0x9026  /* interium value used by Linux until the
00198                                    committee comes up with a final number */
00199 #define EM_S390         0xA390  /* interium value used for IBM S390 */
00200 #endif
00201 
00202 /* object file version - page 1-4 (e_version) */
00203 
00204 #define EV_NONE         0       
00205 #define EV_CURRENT      1       
00207 /* e_ident[] Identification Indexes - figure 1-4, page 1-5 */
00208 
00209 #define EI_MAG0         0       
00210 #define EI_MAG1         1       
00211 #define EI_MAG2         2       
00212 #define EI_MAG3         3       
00213 #define EI_CLASS        4       
00214 #define EI_DATA         5       
00215 #define EI_VERSION      6       
00216 #define EI_OSABI        7       
00217 #define EI_ABIVERSION   8       
00218 #define EI_PAD          9       
00219 #define EI_NIDENT       16      
00221 /* magic number - page 1-5 */
00222 
00223 #define ELFMAG0         0x7f    
00224 #define ELFMAG1         'E'     
00225 #define ELFMAG2         'L'     
00226 #define ELFMAG3         'F'     
00228 /* file class or capacity - page 1-6 */
00229 
00230 #define ELFCLASSNONE    0       
00231 #define ELFCLASSS32     1       
00232 #define ELFCLASSS64     2       
00234 /* data encoding - page 1-6 */
00235 
00236 #define ELFDATANONE     0       
00237 #define ELFDATA2LSB     1       
00238 #define ELFDATA2MSB     2       
00240 /* Identify operating system and ABI to which the object is targeted */
00241 
00242 #define ELFOSABI_SYSV   0       
00243 #define ELFOSABI_HPUX   1       
00244 #define ELFOSABI_STANDALONE 255  
00247 /***********************/
00248 /* Sections - page 1-8 */
00249 /***********************/
00250 
00251 /* special section indexes */
00252 
00253 #define SHN_UNDEF       0               
00254 #define SHN_LORESERVE   0xff00          
00255 #define SHN_LOPROC      0xff00          
00256 #define SHN_HIPROC      0xff1f          
00257 #define SHN_ABS         0xfff1          
00258 #define SHN_COMMON      0xfff2          
00259 #define SHN_HIRESERVE   0xffff          
00262 typedef struct {
00263     Elf32_Word          sh_name;        
00264     Elf32_Word          sh_type;        
00265     Elf32_Word          sh_flags;       
00266     Elf32_Addr          sh_addr;        
00267     Elf32_Off           sh_offset;      
00268     Elf32_Word          sh_size;        
00269     Elf32_Word          sh_link;        
00270     Elf32_Word          sh_info;        
00271     Elf32_Word          sh_addralign;   
00272     Elf32_Word          sh_entsize;     
00273 } Elf32_Shdr;
00274 
00276 typedef struct {
00277     Elf64_Word          sh_name;        
00278     Elf64_Word          sh_type;        
00279     Elf64_Xword         sh_flags;       
00280     Elf64_Addr          sh_addr;        
00281     Elf64_Off           sh_offset;      
00282     Elf64_Xword         sh_size;        
00283     Elf64_Word          sh_link;        
00284     Elf64_Word          sh_info;        
00285     Elf64_Xword         sh_addralign;   
00286     Elf64_Xword         sh_entsize;     
00287 } Elf64_Shdr;
00288 
00289 /* section type - figure 1-10, page 1-10 */
00290 
00291 #define SHT_NULL        0
00292 #define SHT_PROGBITS    1
00293 #define SHT_SYMTAB      2
00294 #define SHT_STRTAB      3
00295 #define SHT_RELA        4
00296 #define SHT_HASH        5
00297 #define SHT_DYNAMIC     6
00298 #define SHT_NOTE        7
00299 #define SHT_NOBITS      8
00300 #define SHT_REL         9
00301 #define SHT_SHLIB       10
00302 #define SHT_DYNSYM      11
00303 #define SHT_INIT_ARRAY    14            
00304 #define SHT_FINI_ARRAY    15            
00305 #define SHT_PREINIT_ARRAY 16            
00306 #define SHT_GROUP         17            
00307 #define SHT_SYMTAB_SHNDX  18            
00308 #define SHT_NUM           19            
00309 #define SHT_LOOS        0x60000000
00310 #define SHT_HIOS        0x6fffffff
00311 #define SHT_LOPROC      0x70000000
00312 #define SHT_HIPROC      0x7fffffff
00313 #define SHT_LOUSER      0x80000000
00314 #define SHT_HIUSER      0xffffffff
00315 
00316 /* section attribute flags - page 1-12, figure 1-12 */
00317 
00318 #define SHF_WRITE       0x1             
00319 #define SHF_ALLOC       0x2             
00320 #define SHF_EXECINSTR   0x4             
00321 #define SHF_MERGE       0x10            
00322 #define SHF_STRINGS     0x20            
00323 #define SHF_INFO_LINK   0x40            
00324 #define SHF_LINK_ORDER  0x80            
00325 #define SHF_OS_NONCONFORMING 0x100      
00327 #define SHF_GROUP       0x200           
00328 #define SHF_TLS         0x400           
00329 #define SHF_MASKOS      0x0ff00000      
00330 #define SHF_MASKPROC    0xf0000000      
00333 /*****************************************/
00334 /* Program Header - figure 2-1, page 2-2 */
00335 /*****************************************/
00336 
00338 typedef struct {
00339     Elf32_Word          p_type;         
00340     Elf32_Off           p_offset;       
00341     Elf32_Addr          p_vaddr;        
00342     Elf32_Addr          p_paddr;        
00343     Elf32_Word          p_filesz;       
00344     Elf32_Word          p_memsz;        
00345     Elf32_Word          p_flags;        
00346     Elf32_Word          p_align;        
00347 } Elf32_Phdr;
00348 
00350 typedef struct {
00351     Elf64_Word          p_type;         
00352     Elf64_Word          p_flags;        
00353     Elf64_Off           p_offset;       
00354     Elf64_Addr          p_vaddr;        
00355     Elf64_Addr          p_paddr;        
00356     Elf64_Xword         p_filesz;       
00357     Elf64_Xword         p_memsz;        
00358     Elf64_Xword         p_align;        
00359 } Elf64_Phdr;
00360 
00361 /* segment types - figure 2-2, page 2-3 */
00362 
00363 #define PT_NULL         0          
00364 #define PT_LOAD         1          
00365 #define PT_DYNAMIC      2          
00366 #define PT_INTERP       3          
00367 #define PT_NOTE         4          
00368 #define PT_SHLIB        5          
00369 #define PT_PHDR         6          
00370 #define PT_TLS          7          
00371 #define PT_NUM          8          
00372 #define PT_LOOS         0x60000000 
00373 #define PT_HIOS         0x6fffffff 
00374 #define PT_LOPROC       0x70000000 
00375 #define PT_HIPROC       0x7fffffff 
00377 /* segment permissions - page 2-3 */
00378 
00379 #define PF_X            0x1
00380 #define PF_W            0x2
00381 #define PF_R            0x4
00382 #define PF_MASKOS       0x0ff00000
00383 #define PF_MASKPROC     0x7fffffff
00384 
00385 /* Legal values for note segment descriptor types for core files. */
00386 
00387 #define NT_PRSTATUS     1       
00388 #define NT_FPREGSET     2       
00389 #define NT_PRPSINFO     3       
00390 #define NT_PRXREG       4       
00391 #define NT_TASKSTRUCT   4       
00392 #define NT_PLATFORM     5       
00393 #define NT_AUXV         6       
00394 #define NT_GWINDOWS     7       
00395 #define NT_ASRS         8       
00396 #define NT_PSTATUS      10      
00397 #define NT_PSINFO       13      
00398 #define NT_PRCRED       14      
00399 #define NT_UTSNAME      15      
00400 #define NT_LWPSTATUS    16      
00401 #define NT_LWPSINFO     17      
00402 #define NT_PRFPXREG     20      
00404 /* Legal values for the note segment descriptor types for object files.  */
00405 
00406 #define NT_VERSION      1       
00408 /* Dynamic structure - figure 2-9, page 2-12 */
00409 
00411 typedef struct {
00412     Elf32_Sword         d_tag;  
00413     union {
00414         Elf32_Word      d_val;  
00415         Elf32_Addr      d_ptr;  
00416     } d_un;
00417 } Elf32_Dyn;
00418 
00420 typedef struct {
00421     Elf64_Sxword        d_tag;  
00422     union {
00423         Elf64_Xword     d_val;  
00424         Elf64_Addr      d_ptr;  
00425     } d_un;
00426 } Elf64_Dyn;
00427 
00430 #define DT_NULL         0       
00431 #define DT_NEEDED       1       
00432 #define DT_PLTRELSZ     2       
00433 #define DT_PLTGOT       3       
00434 #define DT_HASH         4       
00435 #define DT_STRTAB       5       
00436 #define DT_SYMTAB       6       
00437 #define DT_RELA         7       
00438 #define DT_RELASZ       8       
00439 #define DT_RELAENT      9       
00440 #define DT_STRSZ        10      
00441 #define DT_SYMENT       11      
00442 #define DT_INIT         12      
00443 #define DT_FINI         13      
00444 #define DT_SONAME       14      
00445 #define DT_RPATH        15      
00446 #define DT_SYMBOLIC     16      
00447 #define DT_REL          17      
00448 #define DT_RELSZ        18      
00449 #define DT_RELENT       19      
00450 #define DT_PTRREL       20      
00451 #define DT_DEBUG        21      
00452 #define DT_TEXTREL      22      
00453 #define DT_JMPREL       23      
00454 #define DT_BIND_NOW     24      
00455 #define DT_INIT_ARRAY   25      
00456 #define DT_FINI_ARRAY   26      
00457 #define DT_INIT_ARRAYSZ 27      
00458 #define DT_FINI_ARRAYSZ 28      
00459 #define DT_RUNPATH      29      
00460 #define DT_FLAGS        30      
00461 #define DT_ENCODING     32      
00462 #define DT_PREINIT_ARRAY 32     
00463 #define DT_PREINIT_ARRAYSZ 33   
00464 #define DT_NUM          34      
00465 #define DT_LOOS         0x6000000d 
00466 #define DT_HIOS         0x6ffff000 
00467 #define DT_LOPROC       0x70000000 
00468 #define DT_HIPROC       0x7fffffff 
00470 /* Values of `d_un.d_val' in the DT_FLAGS entry.  */
00471 #define DF_ORIGIN       0x00000001      
00472 #define DF_SYMBOLIC     0x00000002      
00473 #define DF_TEXTREL      0x00000004      
00474 #define DF_BIND_NOW     0x00000008      
00475 #define DF_STATIC_TLS   0x00000010      
00477 /* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
00478    entry in the dynamic section.  */
00479 #define DF_1_NOW        0x00000001      
00480 #define DF_1_GLOBAL     0x00000002      
00481 #define DF_1_GROUP      0x00000004      
00482 #define DF_1_NODELETE   0x00000008      
00483 #define DF_1_LOADFLTR   0x00000010      
00484 #define DF_1_INITFIRST  0x00000020      
00485 #define DF_1_NOOPEN     0x00000040      
00486 #define DF_1_ORIGIN     0x00000080      
00487 #define DF_1_DIRECT     0x00000100      
00488 #define DF_1_TRANS      0x00000200
00489 #define DF_1_INTERPOSE  0x00000400      
00490 #define DF_1_NODEFLIB   0x00000800      
00491 #define DF_1_NODUMP     0x00001000      
00492 #define DF_1_CONFALT    0x00002000      
00493 #define DF_1_ENDFILTEE  0x00004000      
00494 #define DF_1_DISPRELDNE 0x00008000      
00495 #define DF_1_DISPRELPND 0x00010000      
00497 /* Flags for the feature selection in DT_FEATURE_1.  */
00498 #define DTF_1_PARINIT   0x00000001
00499 #define DTF_1_CONFEXP   0x00000002
00500 
00501 /* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry.  */
00502 #define DF_P1_LAZYLOAD  0x00000001      
00503 #define DF_P1_GROUPPERM 0x00000002      
00506 /* Relocation - page 1-21, figure 1-20 */
00507 
00508 typedef struct {
00509     Elf32_Addr          r_offset;
00510     Elf32_Word          r_info;
00511 } Elf32_Rel;
00512 
00513 typedef struct {
00514     Elf32_Addr          r_offset;
00515     Elf32_Word          r_info;
00516     Elf32_Sword         r_addend;
00517 } Elf32_Rela;
00518 
00519 typedef struct {
00520     Elf64_Addr          r_offset;
00521     Elf64_Xword         r_info;
00522 } Elf64_Rel;
00523 
00524 typedef struct {
00525     Elf64_Addr          r_offset;
00526     Elf64_Xword         r_info;
00527     Elf64_Sxword        r_addend;
00528 } Elf64_Rela;
00529 
00530 #define ELF32_R_SYM(i)    ((i)>>8)
00531 #define ELF32_R_TYPE(i)   ((unsigned char)(i))
00532 #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
00533 
00534 #define ELF64_R_SYM(i)    ((i)>>32)
00535 #define ELF64_R_TYPE(i)   ((i)&0xffffffffL)
00536 #define ELF64_R_INFO(s,t) (((s)<<32)+(t)&0xffffffffL)
00537 
00538 /* Relocation types (processor specific) - page 1-23, figure 1-22 */
00539 
00540 #define R_386_NONE      0       
00541 #define R_386_32        1       
00542 #define R_386_PC32      2       
00543 #define R_386_GOT32     3       
00544 #define R_386_PLT32     4       
00545 #define R_386_COPY      5       
00546 #define R_386_GLOB_DAT  6       
00547 #define R_386_JMP_SLOT  7       
00548 #define R_386_RELATIVE  8       
00549 #define R_386_GOTOFF    9       
00550 #define R_386_GOTPC     10      
00551 #define R_386_32PLT        11
00552 #define R_386_TLS_TPOFF    14           /* Offset in static TLS block */
00553 #define R_386_TLS_IE       15           /* Address of GOT entry for static TLS
00554                                            block offset */
00555 #define R_386_TLS_GOTIE    16           /* GOT entry for static TLS block
00556                                            offset */
00557 #define R_386_TLS_LE       17           /* Offset relative to static TLS
00558                                            block */
00559 #define R_386_TLS_GD       18           /* Direct 32 bit for GNU version of
00560                                            general dynamic thread local data */
00561 #define R_386_TLS_LDM      19           /* Direct 32 bit for GNU version of
00562                                            local dynamic thread local data
00563                                            in LE code */
00564 #define R_386_16           20
00565 #define R_386_PC16         21
00566 #define R_386_8            22
00567 #define R_386_PC8          23
00568 #define R_386_TLS_GD_32    24           /* Direct 32 bit for general dynamic
00569                                            thread local data */
00570 #define R_386_TLS_GD_PUSH  25           /* Tag for pushl in GD TLS code */
00571 #define R_386_TLS_GD_CALL  26           /* Relocation for call to
00572                                            __tls_get_addr() */
00573 #define R_386_TLS_GD_POP   27           /* Tag for popl in GD TLS code */
00574 #define R_386_TLS_LDM_32   28           /* Direct 32 bit for local dynamic
00575                                            thread local data in LE code */
00576 #define R_386_TLS_LDM_PUSH 29           /* Tag for pushl in LDM TLS code */
00577 #define R_386_TLS_LDM_CALL 30           /* Relocation for call to
00578                                            __tls_get_addr() in LDM code */
00579 #define R_386_TLS_LDM_POP  31           /* Tag for popl in LDM TLS code */
00580 #define R_386_TLS_LDO_32   32           /* Offset relative to TLS block */
00581 #define R_386_TLS_IE_32    33           /* GOT entry for negated static TLS
00582                                            block offset */
00583 #define R_386_TLS_LE_32    34           /* Negated offset relative to static
00584                                            TLS block */
00585 #define R_386_TLS_DTPMOD32 35           /* ID of module containing symbol */
00586 #define R_386_TLS_DTPOFF32 36           /* Offset in TLS block */
00587 #define R_386_TLS_TPOFF32  37           /* Negated offset in static TLS block */
00588 /* Keep this the last entry.  */
00589 #define R_386_NUM          38
00590 
00591 /* ARM specific declarations */
00592 
00593 /* Processor specific flags for the ELF header e_flags field.  */
00594 #define EF_ARM_RELEXEC     0x01
00595 #define EF_ARM_HASENTRY    0x02
00596 #define EF_ARM_INTERWORK   0x04
00597 #define EF_ARM_APCS_26     0x08
00598 #define EF_ARM_APCS_FLOAT  0x10
00599 #define EF_ARM_PIC         0x20
00600 #define EF_ARM_ALIGN8      0x40         /* 8-bit structure alignment is in use */
00601 #define EF_ARM_NEW_ABI     0x80
00602 #define EF_ARM_OLD_ABI     0x100
00603 
00604 /* Other constants defined in the ARM ELF spec. version B-01.  */
00605 /* NB. These conflict with values defined above.  */
00606 #define EF_ARM_SYMSARESORTED    0x04
00607 #define EF_ARM_DYNSYMSUSESEGIDX 0x08
00608 #define EF_ARM_MAPSYMSFIRST     0x10
00609 #define EF_ARM_EABIMASK         0XFF000000
00610 
00611 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
00612 #define EF_ARM_EABI_UNKNOWN  0x00000000
00613 #define EF_ARM_EABI_VER1     0x01000000
00614 #define EF_ARM_EABI_VER2     0x02000000
00615 
00616 /* Additional symbol types for Thumb */
00617 #define STT_ARM_TFUNC      0xd
00618 
00619 /* ARM-specific values for sh_flags */
00620 #define SHF_ARM_ENTRYSECT  0x10000000   /* Section contains an entry point */
00621 #define SHF_ARM_COMDEF     0x80000000   /* Section may be multiply defined
00622                                            in the input to a link step */
00623 
00624 /* ARM-specific program header flags */
00625 #define PF_ARM_SB          0x10000000   /* Segment contains the location
00626                                            addressed by the static base */
00627 
00628 /* ARM relocs.  */
00629 #define R_ARM_NONE              0       /* No reloc */
00630 #define R_ARM_PC24              1       /* PC relative 26 bit branch */
00631 #define R_ARM_ABS32             2       /* Direct 32 bit  */
00632 #define R_ARM_REL32             3       /* PC relative 32 bit */
00633 #define R_ARM_PC13              4
00634 #define R_ARM_ABS16             5       /* Direct 16 bit */
00635 #define R_ARM_ABS12             6       /* Direct 12 bit */
00636 #define R_ARM_THM_ABS5          7
00637 #define R_ARM_ABS8              8       /* Direct 8 bit */
00638 #define R_ARM_SBREL32           9
00639 #define R_ARM_THM_PC22          10
00640 #define R_ARM_THM_PC8           11
00641 #define R_ARM_AMP_VCALL9        12
00642 #define R_ARM_SWI24             13
00643 #define R_ARM_THM_SWI8          14
00644 #define R_ARM_XPC25             15
00645 #define R_ARM_THM_XPC22         16
00646 #define R_ARM_COPY              20      /* Copy symbol at runtime */
00647 #define R_ARM_GLOB_DAT          21      /* Create GOT entry */
00648 #define R_ARM_JUMP_SLOT         22      /* Create PLT entry */
00649 #define R_ARM_RELATIVE          23      /* Adjust by program base */
00650 #define R_ARM_GOTOFF            24      /* 32 bit offset to GOT */
00651 #define R_ARM_GOTPC             25      /* 32 bit PC relative offset to GOT */
00652 #define R_ARM_GOT32             26      /* 32 bit GOT entry */
00653 #define R_ARM_PLT32             27      /* 32 bit PLT address */
00654 #define R_ARM_ALU_PCREL_7_0     32
00655 #define R_ARM_ALU_PCREL_15_8    33
00656 #define R_ARM_ALU_PCREL_23_15   34
00657 #define R_ARM_LDR_SBREL_11_0    35
00658 #define R_ARM_ALU_SBREL_19_12   36
00659 #define R_ARM_ALU_SBREL_27_20   37
00660 #define R_ARM_GNU_VTENTRY       100
00661 #define R_ARM_GNU_VTINHERIT     101
00662 #define R_ARM_THM_PC11          102     /* thumb unconditional branch */
00663 #define R_ARM_THM_PC9           103     /* thumb conditional branch */
00664 #define R_ARM_RXPC25            249
00665 #define R_ARM_RSBREL32          250
00666 #define R_ARM_THM_RPC22         251
00667 #define R_ARM_RREL32            252
00668 #define R_ARM_RABS22            253
00669 #define R_ARM_RPC24             254
00670 #define R_ARM_RBASE             255
00671 /* Keep this the last entry.  */
00672 #define R_ARM_NUM               256
00673 
00674 /* AMD x86-64 relocations.  */
00675 #define R_X86_64_NONE           0       /* No reloc */
00676 #define R_X86_64_64             1       /* Direct 64 bit  */
00677 #define R_X86_64_PC32           2       /* PC relative 32 bit signed */
00678 #define R_X86_64_GOT32          3       /* 32 bit GOT entry */
00679 #define R_X86_64_PLT32          4       /* 32 bit PLT address */
00680 #define R_X86_64_COPY           5       /* Copy symbol at runtime */
00681 #define R_X86_64_GLOB_DAT       6       /* Create GOT entry */
00682 #define R_X86_64_JUMP_SLOT      7       /* Create PLT entry */
00683 #define R_X86_64_RELATIVE       8       /* Adjust by program base */
00684 #define R_X86_64_GOTPCREL       9       /* 32 bit signed PC relative
00685                                            offset to GOT */
00686 #define R_X86_64_32             10      /* Direct 32 bit zero extended */
00687 #define R_X86_64_32S            11      /* Direct 32 bit sign extended */
00688 #define R_X86_64_16             12      /* Direct 16 bit zero extended */
00689 #define R_X86_64_PC16           13      /* 16 bit sign extended pc relative */
00690 #define R_X86_64_8              14      /* Direct 8 bit sign extended  */
00691 #define R_X86_64_PC8            15      /* 8 bit sign extended pc relative */
00692 #define R_X86_64_DTPMOD64       16      /* ID of module containing symbol */
00693 #define R_X86_64_DTPOFF64       17      /* Offset in module's TLS block */
00694 #define R_X86_64_TPOFF64        18      /* Offset in initial TLS block */
00695 #define R_X86_64_TLSGD          19      /* 32 bit signed PC relative offset
00696                                            to two GOT entries for GD symbol */
00697 #define R_X86_64_TLSLD          20      /* 32 bit signed PC relative offset
00698                                            to two GOT entries for LD symbol */
00699 #define R_X86_64_DTPOFF32       21      /* Offset in TLS block */
00700 #define R_X86_64_GOTTPOFF       22      /* 32 bit signed PC relative offset
00701                                            to GOT entry for IE symbol */
00702 #define R_X86_64_TPOFF32        23      /* Offset in initial TLS block */
00703 
00704 #define R_X86_64_NUM            24
00705 
00706 /* Symbol Table Entry - page 1-17, figure 1-16 */
00707 
00708 #define STN_UNDEF       0
00709 
00711 typedef struct {
00712     Elf32_Word          st_name;        
00713     Elf32_Addr          st_value;       
00714     Elf32_Word          st_size;        
00715     unsigned char       st_info;        
00716     unsigned char       st_other;       
00717     Elf32_Half          st_shndx;       
00718 } Elf32_Sym;
00719 
00721 typedef struct {
00722     Elf64_Word          st_name;        
00723     unsigned char       st_info;        
00724     unsigned char       st_other;       
00725     Elf64_Half          st_shndx;       
00726     Elf64_Addr          st_value;       
00727     Elf64_Xword         st_size;        
00728 } Elf64_Sym;
00729 
00730 #define ELF32_ST_BIND(i)    ((i)>>4)
00731 #define ELF32_ST_TYPE(i)    ((i)&0xf)
00732 #define ELF32_ST_INFO(b,t)  (((b)<<4)+((t)&0xf))
00733 
00734 #define ELF64_ST_BIND(i)    ((i)>>4)
00735 #define ELF64_ST_TYPE(i)    ((i)&0xf)
00736 #define ELF64_ST_INFO(b,t)  (((b)<<4)+((t)&0xf))
00737 
00738 /* Symbol Binding - page 1-18, figure 1-17 */
00739 
00740 #define STB_LOCAL       0       
00741 #define STB_GLOBAL      1       
00742 #define STB_WEAK        2       
00743 #define STB_LOOS        10      
00744 #define STB_HIOS        12      
00745 #define STB_LOPROC      13      
00746 #define STB_HIPROC      15      
00748 /* Symbol Types - page 1-19, figure 1-18 */
00749 
00750 #define STT_NOTYPE      0       
00751 #define STT_OBJECT      1       
00752 #define STT_FUNC        2       
00753 #define STT_SECTION     3       
00754 #define STT_FILE        4       
00755 #define STT_LOOS        10      
00756 #define STT_HIOS        12      
00757 #define STT_LOPROC      13      
00758 #define STT_HIPROC      15      
00760 /* Some helpers */
00761 static inline int l4util_elf_check_magic(ElfW(Ehdr) *hdr);
00762 static inline int l4util_elf_check_arch(ElfW(Ehdr) *hdr);
00763 static inline ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr);
00764 
00765 
00766 /* Implemeantions */
00767 static inline
00768 int l4util_elf_check_magic(ElfW(Ehdr) *hdr)
00769 {
00770   return    hdr->e_ident[EI_MAG0] == ELFMAG0
00771          && hdr->e_ident[EI_MAG1] == ELFMAG1
00772          && hdr->e_ident[EI_MAG2] == ELFMAG2
00773          && hdr->e_ident[EI_MAG3] == ELFMAG3;
00774 }
00775 
00776 static inline
00777 int l4util_elf_check_arch(ElfW(Ehdr) *hdr)
00778 {
00779   return    hdr->e_ident[EI_CLASS] == L4_ARCH_EI_CLASS
00780          && hdr->e_ident[EI_DATA]  == L4_ARCH_EI_DATA
00781          && hdr->e_machine         == L4_ARCH_E_MACHINE;
00782 }
00783 
00784 static inline
00785 ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr)
00786 {
00787   return (ElfW(Phdr) *)((char *)hdr + hdr->e_phoff);
00788 }
00789 
00790 #endif /* _L4_EXEC_ELF_H */

L4 Utilities, part of DROPS  © 2000-2003