1.1 --- a/epoc32/include/tools/elfdefs.h Wed Mar 31 12:27:01 2010 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,812 +0,0 @@
1.4 -// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 -// All rights reserved.
1.6 -// This component and the accompanying materials are made available
1.7 -// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.8 -// which accompanies this distribution, and is available
1.9 -// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 -//
1.11 -// Initial Contributors:
1.12 -// Nokia Corporation - initial contribution.
1.13 -//
1.14 -// Contributors:
1.15 -//
1.16 -// Description:
1.17 -// lifted from the ARMELF spec
1.18 -//
1.19 -//
1.20 -
1.21 -#ifndef __ELFDEFS_H__
1.22 -#define __ELFDEFS_H__
1.23 -
1.24 -
1.25 -// ARMELF 3.1.2
1.26 -// Data Representation
1.27 -typedef unsigned int Elf32_Addr; //Unsigned program address
1.28 -typedef unsigned short Elf32_Half; //Unsigned medium integer
1.29 -typedef unsigned int Elf32_Off; //Unsigned file offset
1.30 -typedef signed int Elf32_Sword; //Signed large integer
1.31 -typedef unsigned int Elf32_Word; //Unsigned large integer
1.32 -typedef unsigned char UChar; //Unsigned small integer
1.33 -
1.34 -typedef char* MemAddr;
1.35 -/*
1.36 -3.2 ELF Header
1.37 -Some object file control structures can grow, because the ELF header
1.38 -contains their actual sizes. If the object file format changes, a
1.39 -program may encounter control structures that are larger or smaller
1.40 -than expected. Programs might therefore ignore extra information. The
1.41 -treatment of missing information depends on context and will be
1.42 -specified when and if extensions are defined.
1.43 -*/
1.44 -#define EI_NIDENT 16
1.45 -typedef struct {
1.46 -
1.47 - // marks the file as an object file and provide machine-independent
1.48 - // data with which to decode and interpret the file's contents.
1.49 - unsigned char e_ident[EI_NIDENT];
1.50 -
1.51 - // identifies the object file type.
1.52 - Elf32_Half e_type;
1.53 -
1.54 - // specifies the required architecture for an individual file.
1.55 - Elf32_Half e_machine;
1.56 -
1.57 - // identifies the object file version.
1.58 - Elf32_Word e_version;
1.59 -
1.60 - // gives the virtual address to which the system first transfers
1.61 - // control, thus starting the process. If the file has no associated
1.62 - // entry point, this member holds zero.
1.63 - Elf32_Addr e_entry;
1.64 -
1.65 - // holds the program header table's file offset in bytes. If the
1.66 - // file has no program header table, this member holds zero.
1.67 - Elf32_Off e_phoff;
1.68 -
1.69 - // holds the section header table's file offset in bytes. If the
1.70 - // file has no section header table, this member holds zero.
1.71 - Elf32_Off e_shoff;
1.72 -
1.73 - // holds processor-specific flags associated with the file. Flag
1.74 - // names take the form EF_machine_flag.
1.75 - Elf32_Word e_flags;
1.76 -
1.77 - // holds the ELF header's size in bytes.
1.78 - Elf32_Half e_ehsize;
1.79 -
1.80 - // holds the size in bytes of one entry in the file's program
1.81 - // header table; all entries are the same size.
1.82 - Elf32_Half e_phentsize;
1.83 -
1.84 - // holds the number of entries in the program header table.
1.85 - // Thus the product of e_phentsize and e_phnum gives the table's
1.86 - // size in bytes. If a file has no program header table, e_phnum
1.87 - // holds the value zero.
1.88 - Elf32_Half e_phnum;
1.89 -
1.90 - // holds a section header's size in bytes. A section header is
1.91 - // one entry in the section header table; all entries are the same size.
1.92 - Elf32_Half e_shentsize;
1.93 -
1.94 - // holds the number of entries in the section header table. Thus
1.95 - // the product of e_shentsize and e_shnum gives the section header
1.96 - // table's size in bytes. If a file has no section header table,
1.97 - // e_shnum holds the value zero.
1.98 - Elf32_Half e_shnum;
1.99 -
1.100 - // holds the section header table index of the entry associated
1.101 - // with the section name string table. If the file has no section
1.102 - // name string table, this member holds the value SHN_UNDEF.
1.103 - Elf32_Half e_shstrndx;
1.104 -
1.105 -} Elf32_Ehdr;
1.106 -
1.107 -// values for e_type
1.108 -#define ET_NONE 0 // No file type
1.109 -#define ET_REL 1 // Re-locatable
1.110 -#define ET_EXEC 2 // Executable file
1.111 -#define ET_DYN 3 // Shared object
1.112 -#define ET_CORE 4 // Core file
1.113 -#define ET_LOPROC 0xff00 // Processor-specific
1.114 -#define ET_HIPROC 0xffff // Processor-specific
1.115 -
1.116 -//values for e_machine
1.117 -#define EM_NONE 0 // No machine
1.118 -#define EM_M32 1 // AT&T WE 32100
1.119 -#define EM_SPARC 2 // SPARC
1.120 -#define EM_386 3 // Intel Architecture
1.121 -#define EM_68K 4 // Moto 68000
1.122 -#define EM_88K 5 // Moto 88000
1.123 -#define EM_860 7 // Intel 80860
1.124 -#define EM_MIPS 8 // MIPS RS3000 Big-Endian
1.125 -#define EM_MIPS_RS4_BE 10 // MIPS RS4000 Big-Endian
1.126 -//#define RESERVED 11-16 Reserved for future use
1.127 -#define EM_ARM 40 //ARM/Thumb Architecture
1.128 -
1.129 -// values for e_version
1.130 -#define EV_NONE 0 // Invalid version
1.131 -#define EV_CURRENT 1 // Current version
1.132 -
1.133 -// ELF Identification
1.134 -#define EI_MAG0 0 // File identification
1.135 -#define EI_MAG1 1 // File identification
1.136 -#define EI_MAG2 2 // File identification
1.137 -#define EI_MAG3 3 // File identification
1.138 -#define EI_CLASS 4 // File class
1.139 -#define EI_DATA 5 // Data encoding
1.140 -#define EI_VERSION 6 // File version
1.141 -#define EI_PAD 7 // Start of padding bytes
1.142 -
1.143 -// values for e_ident[0-3]
1.144 -#define ELFMAG0 0x7f // e_ident[EI_MAG0]
1.145 -#define ELFMAG1 'E' // e_ident[EI_MAG1]
1.146 -#define ELFMAG2 'L' // e_ident[EI_MAG2]
1.147 -#define ELFMAG3 'F' // e_ident[EI_MAG3]
1.148 -
1.149 -// values for e_ident[EI_CLASS]- identifies the file's class, or capacity.
1.150 -#define ELFCLASSNONE 0 // Invalid class
1.151 -#define ELFCLASS32 1 // 32-bit objects
1.152 -#define ELFCLASS64 2 // 64-bit objects
1.153 -
1.154 -// values for e_ident[EI_DATA] - specifies the data encoding of the
1.155 -// processor-specific data in the object file.
1.156 -#define ELFDATANONE 0 // Invalid data encoding
1.157 -#define ELFDATA2LSB 1 // 2's complement , with LSB at lowest address.
1.158 -#define ELFDATA2MSB 2 // 2's complement , with MSB at lowest address.
1.159 -
1.160 -// ARM/THUMB specific values for e_flags
1.161 -
1.162 -// e_entry contains a program-loader entry point
1.163 -#define EF_ARM_HASENTRY 0x02
1.164 -// Each subsection of the symbol table is sorted by symbol value
1.165 -#define EF_ARM_SYMSARESORTED 0x04
1.166 -// Symbols in dynamic symbol tables that are defined in sections
1.167 -// included in program segment n have st_shndx = n+ 1.
1.168 -#define EF_ARM_DYNSYMSUSESEGIDX 0x8
1.169 -// Mapping symbols precede other local symbols in the symbol table
1.170 -#define EF_ARM_MAPSYMSFIRST 0x10
1.171 -// This masks an 8-bit version number, the version of the ARM EABI to
1.172 -// which this ELF file conforms. This EABI is version 2. A value of 0
1.173 -// denotes unknown conformance. (current version is 0x02000000)
1.174 -#define EF_ARM_EABIMASK 0xFF000000
1.175 -
1.176 -#define EF_ARM_EABI_VERSION 0x02000000
1.177 -#define EF_ARM_BPABI_VERSION 0x04000000
1.178 -
1.179 -/*
1.180 -3.3 Sections
1.181 -
1.182 -An object file's section header table lets one locate all the file's
1.183 -sections. The section header table is an array of Elf32_Shdr
1.184 -structures as described below. A section header table index is a
1.185 -subscript into this array. The ELF header's e_shoff member gives the
1.186 -byte offset from the beginning of the file to the section header
1.187 -table; e_shnum tells how many entries the section header table
1.188 -contains; e_shentsize gives the size in bytes of each entry.
1.189 -*/
1.190 -
1.191 -// Some section header table indexes are reserved; an object file will
1.192 -// not have sections for these special indexes.
1.193 -
1.194 -// marks an undefined, missing, irrelevant, or otherwise meaningless
1.195 -// section reference.
1.196 -#define SHN_UNDEF 0
1.197 -// specifies the lower bound of the range of reserved indexes.
1.198 -#define SHN_LORESERVE 0xff00
1.199 -// SHN_LOPROC-SHN_HIPRO - this inclusive range reserved for
1.200 -// processor-specific semantics.
1.201 -#define SHN_LOPROC 0xff00
1.202 -#define SHN_HIPROC 0xff1f
1.203 -// Specifies absolute values for the corresponding reference.
1.204 -// For example, symbols defined relative to section number SHN_ABS have
1.205 -// absolute values and are not affected by relocation.
1.206 -#define SHN_ABS 0xfff1
1.207 -// Symbols defined relative to this section are common symbols,
1.208 -// such as FORTRAN COMMON or unallocated C external variables.
1.209 -#define SHN_COMMON 0xfff2
1.210 -// specifies the upper bound of the range of reserved indexes.
1.211 -#define SHN_HIRESERVE 0xffff
1.212 -
1.213 -typedef struct {
1.214 -
1.215 - // specifies the name of the section. Its value is an index into the
1.216 - // section header string table section [see String Tablebelow],
1.217 - // giving the location of a null-terminated string.
1.218 - Elf32_Word sh_name;
1.219 -
1.220 - // categorizes the section's contents and semantics. Section types
1.221 - // and their descriptions appear below.
1.222 - Elf32_Word sh_type;
1.223 -
1.224 - // Sections support 1-bit flags that describe miscellaneous
1.225 - // attributes. Flag definitions appear below.
1.226 - Elf32_Word sh_flags;
1.227 -
1.228 - // If the section will appear in the memory image of a process, this
1.229 - // member gives the address at which the section's first byte should
1.230 - // reside. Otherwise, the member contains 0.
1.231 - Elf32_Addr sh_addr;
1.232 -
1.233 - // gives the byte offset from the beginning of the file to the first
1.234 - // byte in the section.One section type, SHT_NOBITS described below,
1.235 - // occupies no space in the file, and its sh_offset member locates
1.236 - // the conceptual placement in the file.
1.237 - Elf32_Off sh_offset;
1.238 -
1.239 - // gives the section's size in bytes. Unless the section type is
1.240 - // SHT_NOBITS, the section occupies sh_size bytes in the file. A
1.241 - // section of type SHT_NOBITS may have a non-zero size, but it
1.242 - // occupies no space in the file.
1.243 - Elf32_Word sh_size;
1.244 -
1.245 - // holds a section header table index link, whose interpretation
1.246 - // depends on the section type. A table below describes the values.
1.247 - Elf32_Word sh_link;
1.248 -
1.249 - // holds extra information, whose interpretation depends on the
1.250 - // section type. A table below describes the values.
1.251 - Elf32_Word sh_info;
1.252 -
1.253 - // Some sections have address alignment constraints. For example, if
1.254 - // a section holds a doubleword, the system must ensure double-word
1.255 - // alignment for the entire section. That is, the value of sh_addr
1.256 - // must be congruent to 0, modulo the value of
1.257 - // sh_addralign. Currently, only 0 and positive integral powers of
1.258 - // two are allowed. Values 0 and 1 mean the section has no alignment
1.259 - // constraints.
1.260 - Elf32_Word sh_addralign;
1.261 -
1.262 - // Some sections hold a table of fixed-size entries, such as a
1.263 - // symbol table. For such a section, this member gives the size in
1.264 - // bytes of each entry. The member contains 0 if the section does
1.265 - // not hold a table of fixedsize entries. A section header's sh_type
1.266 - // member specifies the section's semantics.
1.267 - Elf32_Word sh_entsize;
1.268 -
1.269 -} Elf32_Shdr;
1.270 -
1.271 -// values for sh_type
1.272 -
1.273 -#define SHT_NULL 0 // marks the section header as inactive; it does
1.274 - // not have an associated section. Other members of the section
1.275 - // header have undefined values.
1.276 -#define SHT_PROGBITS 1 // The section holds information defined by the
1.277 - // program, whose format and meaning are determined solely by the
1.278 - // program.
1.279 -#define SHT_SYMTAB 2 //These sections hold a symbol table.
1.280 -#define SHT_STRTAB 3 // The section holds a string table.
1.281 -#define SHT_RELA 4 // The section holds relocation entries with
1.282 - // explicit addends, such as type Elf32_Rela for the 32-bit class of
1.283 - // object files. An object file may have multiple relocation
1.284 - // sections. See Relocationbelow for details.
1.285 -#define SHT_HASH 5 // The section holds a symbol hash table.
1.286 -#define SHT_DYNAMIC 6 // The section holds information for dynamic
1.287 - // linking.
1.288 -#define SHT_NOTE 7 // This section holds information that marks the
1.289 - // file in some way.
1.290 -#define SHT_NOBITS 8 // A section of this type occupies no space in
1.291 - // the file but otherwise resembles SHT_PROGBITS. Although this
1.292 - // section contains no bytes, the sh_offset member contains the
1.293 - // conceptual file offset.
1.294 -#define SHT_REL 9 // The section holds relocation entries without
1.295 - // explicit addends, such as type Elf32_Rel for the 32-bit class of
1.296 - // object files. An object file may have multiple relocation
1.297 - // sections. See Relocationbelow for details.
1.298 -#define SHT_SHLIB 10 // This section type is reserved but has
1.299 - // unspecified semantics.
1.300 -#define SHT_DYNSYM 11 // This section hold dynamic symbol information
1.301 -// SHT_LOPROC through SHT_HIPROC - Values in this inclusive range are
1.302 -// reserved for processor-specific semantics.
1.303 -#define SHT_LOPROC 0x70000000
1.304 -#define SHT_ARM_EXIDX 0x70000001
1.305 -#define SHT_HIPROC 0x7fffffff
1.306 -// Section types between SHT_LOUSER and SHT_HIUSER may be used by the
1.307 -// application, without conflicting with current or future
1.308 -// system-defined section types.
1.309 -#define SHT_LOUSER 0x80000000 // This value specifies the lower bound
1.310 - // of the range of indexes reserved for application programs.
1.311 -#define SHT_HIUSER 0xffffffff // This value specifies the upper bound
1.312 - // of the range of indexes reserved for application programs.
1.313 -
1.314 -// values for sh_flags
1.315 -
1.316 -// The section contains data that should be writable during process execution
1.317 -#define SHF_WRITE 0x1
1.318 -// The section occupies memory during process execution. Some control
1.319 -// sections do not reside in the memory image of an object file; this
1.320 -// attribute is off for those sections
1.321 -#define SHF_ALLOC 0x2
1.322 -// The section contains executable machine instructions.
1.323 -#define SHF_EXECINSTR 0x4
1.324 -// Bits in this mask are reserved for processor-specific semantics.
1.325 -#define SHF_MASKPROC 0xf0000000
1.326 -
1.327 -
1.328 -typedef struct {
1.329 -
1.330 - // holds an index into the object file's symbol string table, which
1.331 - // holds the character representations of the symbol names.
1.332 - Elf32_Word st_name;
1.333 -
1.334 - // gives the value of the associated symbol. Depending on the
1.335 - // context this may be an absolute value, an address, and so on
1.336 - Elf32_Addr st_value;
1.337 -
1.338 - // Many symbols have associated sizes. For example, a data object's
1.339 - // size is the number of bytes contained in the object. This member
1.340 - // holds 0 if the symbol has no size or an unknown size.
1.341 - Elf32_Word st_size;
1.342 -
1.343 - // This member specifies the symbol's type and binding
1.344 - // attributes. The following code shows how to manipulate the
1.345 - // values.
1.346 -#define ELF32_ST_BIND(i) ((i)>>4)
1.347 -#define ELF32_ST_TYPE(i) ((i)&0xf)
1.348 -#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
1.349 - unsigned char st_info;
1.350 -
1.351 - // This member currently holds 0 and has no defined meaning.
1.352 - unsigned char st_other;
1.353 -
1.354 -
1.355 -#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
1.356 -#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
1.357 -
1.358 - // Every symbol table entry is defined in relation to some section;
1.359 - // this member holds the relevant section header table index.
1.360 - Elf32_Half st_shndx;
1.361 -
1.362 -} Elf32_Sym;
1.363 -
1.364 -// Local symbols are not visible outside the object file containing
1.365 -// their definition. Local symbols of the same name may exist in
1.366 -// multiple files without interfering with each other.
1.367 -#define STB_LOCAL 0
1.368 -// Global symbols are visible to all object files being combined. One
1.369 -// file's definition of a global symbol will satisfy another file's
1.370 -// undefined reference to the same global symbol.
1.371 -#define STB_GLOBAL 1
1.372 -// Weak symbols resemble global symbols, but their definitions have
1.373 -// lower precedence. Undefined weak symbols (weak references) may have
1.374 -// processor- or OS-specific semantics
1.375 -#define STB_WEAK 2
1.376 -// STB_LOPROC through STB_HIPROC - values in this inclusive range are
1.377 -// reserved for processor-specific semantics.
1.378 -#define STB_LOPROC 13
1.379 -#define STB_HIPROC 15
1.380 -
1.381 -// The symbol's type is not specified.
1.382 -#define STT_NOTYPE 0
1.383 -// The symbol is associated with a data object, such as a variable, an
1.384 -// array, and so on.
1.385 -#define STT_OBJECT 1
1.386 -// The symbol is associated with a function or other executable code.
1.387 -#define STT_FUNC 2
1.388 -// The symbol is associated with a section. Symbol table entries of
1.389 -// this type exist primarily for relocation and normally have
1.390 -// STB_LOCAL binding.
1.391 -#define STT_SECTION 3
1.392 -// A file symbol has STB_LOCAL binding, its section index is SHN_A BS,
1.393 -// and it precedes the other STB_LOCAL symbols for the file, if it is
1.394 -// present.
1.395 -#define STT_FILE 4
1.396 -// Values in this inclusive range are reserved for processor-specific
1.397 -// semantics. If a symbol's value refers to a specific location within
1.398 -// a section, its section index member, st_shndx, holds an index into
1.399 -// the section header table. As the section moves during relocation,
1.400 -// the symbol's value changes as well, and references to the symbol
1.401 -// continue to point to the same location in the program. Some special
1.402 -// section index values give other semantics.
1.403 -#define STT_LOPROC 13
1.404 -#define STT_HIPROC 15
1.405 -
1.406 -/*
1.407 -STV_DEFAULT
1.408 -The visibility of symbols with the STV_DEFAULT attribute is as specified by the symbol's
1.409 -binding type. That is, global and weak symbols are visible outside of their defining
1.410 -component, the executable file or shared object. Local symbols are hidden. Global and weak
1.411 - symbols can also be preempted, that is, they may by interposed by definitions of the same
1.412 - name in another component.
1.413 -
1.414 -STV_PROTECTED
1.415 -A symbol defined in the current component is protected if it is visible in other components
1.416 - but cannot be preempted. Any reference to such a symbol from within the defining component
1.417 - must be resolved to the definition in that component, even if there is a definition in
1.418 - another component that would interpose by the default rules. A symbol with STB_LOCAL binding
1.419 - will not have STV_PROTECTED visibility.
1.420 -
1.421 -STV_HIDDEN
1.422 -A symbol defined in the current component is hidden if its name is not visible to other
1.423 - components. Such a symbol is necessarily protected. This attribute is used to control
1.424 - the external interface of a component. An object named by such a symbol may still be
1.425 - referenced from another component if its address is passed outside.
1.426 -
1.427 -A hidden symbol contained in a relocatable object is either removed or converted to
1.428 -STB_LOCAL binding by the link-editor when the relocatable object is included in an
1.429 - executable file or shared object.
1.430 -
1.431 -STV_INTERNAL
1.432 -This visibility attribute is currently reserved.
1.433 -*/
1.434 -#define STV_DEFAULT 0
1.435 -#define STV_INTERNAL 1
1.436 -#define STV_HIDDEN 2
1.437 -#define STV_PROTECTED 3
1.438 -
1.439 -// Relocation Entries
1.440 -
1.441 -typedef struct {
1.442 -
1.443 - // r_offset gives the location at which to apply the relocation
1.444 - // action. For a relocatable file, the value is the byte offset from
1.445 - // the beginning of the section to the storage unit affected by the
1.446 - // relocation. For an executable file or a shared object, the value
1.447 - // is the virtual address of the storage unit affected by the
1.448 - // relocation.
1.449 - Elf32_Addr r_offset;
1.450 -
1.451 - // r_info gives both the symbol table index with respect to which
1.452 - // the relocation must be made, and the type of relocation to
1.453 - // apply. For example, a call instruction's relocation entry would
1.454 - // hold the symbol table index of the function being called. If the
1.455 - // index is STN_UNDEF, the undefined symbol index, the relocation
1.456 - // uses 0 as the symbol value. Relocation types are
1.457 - // processor-specific; descriptions of their behavior appear in
1.458 - // section 4.5, Relocation types. When the text in section 4.5
1.459 - // refers to a relocation entry's relocation type or symbol table
1.460 - // index, it means the result of applying ELF32_R_TYPE or
1.461 - // ELF32_R_SYM, respectively, to the entry's r_info member.
1.462 -
1.463 -#define ELF32_R_SYM(i) ((i)>>8)
1.464 -#define ELF32_R_TYPE(i) ((unsigned char)(i))
1.465 -#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
1.466 -
1.467 - Elf32_Word r_info;
1.468 -} Elf32_Rel;
1.469 -
1.470 -typedef struct {
1.471 - Elf32_Addr r_offset;
1.472 - Elf32_Word r_info;
1.473 - Elf32_Sword r_addend;
1.474 -} Elf32_Rela;
1.475 -
1.476 -// Program Header
1.477 -
1.478 -typedef struct {
1.479 -
1.480 - // p_type tells what kind of segment this array element describes or
1.481 - // how to interpret the array element's information. Type values and
1.482 - // their meanings are given below.
1.483 - Elf32_Word p_type;
1.484 -
1.485 - // p_offset gives the offset from the start of the file at which the
1.486 - // first byte of the segment resides.
1.487 - Elf32_Off p_offset;
1.488 -
1.489 - // p_vaddr gives the virtual address at which the first byte of the
1.490 - // segment resides in memory.
1.491 - Elf32_Addr p_vaddr;
1.492 -
1.493 - // p_paddr - On systems for which physical addressing is relevant,
1.494 - // this member is reserved for the segment's physical address. This
1.495 - // member requires operating system specific information.
1.496 - Elf32_Addr p_paddr;
1.497 -
1.498 - // p_filesz gives the number of bytes in the file image of the
1.499 - // segment; it may be zero.
1.500 - Elf32_Word p_filesz;
1.501 -
1.502 - // p_memsz gives the number of bytes in the memory image of the
1.503 - // segment; it may be zero.
1.504 - Elf32_Word p_memsz;
1.505 -
1.506 - // p_flags gives flags relevant to the segment. Defined flag values
1.507 - // are given below.
1.508 - Elf32_Word p_flags;
1.509 -
1.510 - // p_align - Loadable process segments must have congruent values
1.511 - // for p_vaddr and p_offset, modulo the page size. This member gives
1.512 - // the value to which the segments are aligned in memory and in the
1.513 - // file. Values 0 and 1 mean that no alignment is
1.514 - // required. Otherwise, p_align should be a positive, integral power
1.515 - // of 2, and p_vaddr should equal p_offset, modulo p_align.
1.516 - Elf32_Word p_align;
1.517 -
1.518 -} Elf32_Phdr;
1.519 -
1.520 -// Segment types - values for p_type
1.521 -
1.522 -// The array element is unused; other members' values are
1.523 -// undefined. This type lets the program header table have ignored
1.524 -// entries.
1.525 -#define PT_NULL 0
1.526 -// The array element specifies a loadable segment, described by
1.527 -// p_filesz and p_memsz (for additional explanation, see
1.528 -// PT_LOAD below).
1.529 -#define PT_LOAD 1
1.530 -// The array element specifies dynamic linking information. See
1.531 -// subsection 4.7.
1.532 -#define PT_DYNAMIC 2
1.533 -// The array element specifies the location and size of a
1.534 -// null-terminated pathname to invoke as an interpreter.
1.535 -#define PT_INTERP 3
1.536 -// The array element specifies the location and size of auxiliary
1.537 -// information.
1.538 -#define PT_NOTE 4
1.539 -// This segment type is reserved but has unspecified semantics.
1.540 -#define PT_SHLIB 5
1.541 -// The array element, if present, specifies the location and size of
1.542 -// the program header table itself (for additional explanation, see
1.543 -// PT_ PHDR below).
1.544 -#define PT_PHDR 6
1.545 -// Values in the inclusive [PT_LOPROC, PT_HIPROC] range are reserved
1.546 -// for processor-specific semantics.
1.547 -#define PT_LOPROC 0x70000000
1.548 -#define PT_HIPROC 0x7fffffff
1.549 -
1.550 -// values for p_flags
1.551 -// The segment may be executed.
1.552 -#define PF_X 1
1.553 -// The segment may be written to.
1.554 -#define PF_W 2
1.555 -// The segment may be read.
1.556 -#define PF_R 4
1.557 -// Reserved for processor-specific purposes (see 4.6, Program
1.558 -// headers).
1.559 -#define PF_MASKPROC 0xf0000000
1.560 -#define PF_ARM_ENTRY 0x80000000
1.561 -
1.562 -
1.563 -// Relocation types
1.564 -
1.565 -// ELF defines two sorts of relocation directive, SHT_REL, and
1.566 -// SHT_RELA. Both identify:
1.567 -//
1.568 -// o A section containing the storage unit - byte, half-word, word, or
1.569 -// instruction - being relocated.
1.570 -// o An offset within the section - or the address within an
1.571 -// executable program - of the storage unit itself.
1.572 -// o A symbol,the value of which helps to define a new value for the
1.573 -// storage unit.
1.574 -// o A relocation typethat defines the computation to be
1.575 -// performed. Computations are performed using 2's complement, 32-bit,
1.576 -// unsigned arithmetic with silent overflow.
1.577 -// o An addend, that also helps to define a new value for the storage
1.578 -// unit.
1.579 -//
1.580 -// The addend may be encoded wholly in a field of the storage unit
1.581 -// being relocated - relocation sort SHT_REL - or partly there and
1.582 -// partly in the addendfield of the relocation directive - relocation
1.583 -// sort SHT_RELA. Tables below describe the computation associated
1.584 -// with each relocation type, using the following notation:
1.585 -//
1.586 -// A - denotes the addend used to compute the new value of the storage
1.587 -// unit being relocated.
1.588 -// - It is the value extracted from the storage unit being relocated
1.589 -// (relocation directives of sort SHT_REL) or the sum of that
1.590 -// value and the r_addend field of the relocation directive (sort
1.591 -// SHT_RELA).
1.592 -// - If it has a unit, the unit is bytes. An encoded address or
1.593 -// offset value is converted to bytes on extraction from a storage
1.594 -// unit and re-encoded on insertion into a storage unit.
1.595 -//
1.596 -// P - denotes the place (section offset or address of the storage
1.597 -// unit) being re-located. It is the sum of the r_offset field of
1.598 -// the relocation directive and the base address of the section
1.599 -// being re-located.
1.600 -//
1.601 -// S - denotes the value of the symbol whose symbol table index is
1.602 -// given in the r_info field of the relocation directive.
1.603 -//
1.604 -// B - denotes the base address of the consolidated section in which
1.605 -// the symbol is defined. For relocations of type R_ARM_SBREL32,
1.606 -// this is the least static data address (the static base).
1.607 -//
1.608 -// relocation types 0-16 are generic
1.609 -// Name Type Field Computation
1.610 -//====================================================================
1.611 -#define R_ARM_NONE 0 // Any No relocation.
1.612 -#define R_ARM_PC24 1 // ARM B/BL S - P + A
1.613 -#define R_ARM_ABS32 2 // 32-bit word S + A
1.614 -#define R_ARM_REL32 3 // 32-bit word S - P + A
1.615 -#define R_ARM_PC13 4 // ARM LDR r, [pc,...] S - P + A
1.616 -#define R_ARM_ABS16 5 // 16-bit half-word S + A
1.617 -#define R_ARM_ABS12 6 // ARM LDR/STR S + A
1.618 -#define R_ARM_THM_ABS5 7 // Thumb LDR/STR S + A
1.619 -#define R_ARM_ABS8 8 // 8-bit byte S + A
1.620 -#define R_ARM_SBREL32 9 // 32-bit word S - B + A
1.621 -#define R_ARM_THM_PC22 10 // Thumb BL pair S - P + A
1.622 -#define R_ARM_THM_PC8 11 // Thumb LDR r, [pc,...] S - P + A
1.623 -#define R_ARM_AMP_VCALL9 12 // AMP VCALL Obsolete - SA-1500
1.624 -#define R_ARM_SWI24 13 // ARM SWI S + A
1.625 -#define R_ARM_THM_SWI8 14 // Thumb SWI S + A
1.626 -#define R_ARM_XPC25 15 // ARM BLX S - P + A
1.627 -#define R_ARM_THM_XPC22 16 // Thumb BLX pair S - P + A
1.628 -
1.629 -// relocation types 17-31 are reserved for ARM Linux
1.630 -#define R_ARM_GLOB_DAT 21 // PLT related S + A
1.631 -#define R_ARM_JUMP_SLOT 22 // PLT related S + A
1.632 -#define R_ARM_RELATIVE 23 // 32-bit word B(S) + A
1.633 -
1.634 -#define R_ARM_GOT_BREL 26 //
1.635 -
1.636 -#define R_ARM_ALU_PCREL_7_0 32 // ARM ADD/SUB (S - P + A) & 0x000000FF
1.637 -#define R_ARM_ALU_PCREL_15_8 33 // ARM ADD/SUB (S - P + A) & 0x0000FF00
1.638 -#define R_ARM_ALU_PCREL_23_15 34 // ARM ADD/SUB (S - P + A) & 0x00FF0000
1.639 -#define R_ARM_LDR_SBREL_11_0 35 // ARM ADD/SUB (S - B + A) & 0x00000FFF
1.640 -#define R_ARM_ALU_SBREL_19_12 36 // ARM ADD/SUB (S - B + A) & 0x000FF000
1.641 -#define R_ARM_ALU_SBREL_27_20 37 // ARM ADD/SUB (S - B + A) & 0x0FF00000
1.642 -
1.643 -// Dynamic relocation types
1.644 -
1.645 -// A small set of relocation types supports relocating executable ELF
1.646 -// files. They are used only in a relocation section embedded in a
1.647 -// dynamic segment (see section 4.7, Dynamic linking and
1.648 -// relocation). They cannot be used in a relocation section in a
1.649 -// re-locatable ELF file. In Figure 4-13 below:
1.650 -//
1.651 -// .S is the displacement from its statically linked virtual address
1.652 -// of the segment containing the symbol definition.
1.653 -//
1.654 -// .P is the displacement from its statically linked virtual address
1.655 -// of the segment containing the place to be relocated.
1.656 -//
1.657 -// .SB is the displacement of the segment pointed to by the static
1.658 -// base (PF_ARM_SB is set in the p_flags field of this segment's
1.659 -// program header - see 4.6, Program headers).
1.660 -
1.661 -
1.662 -// types 249 - 255 are dynamic relocation types and are only used in dynamic sections
1.663 -#define R_ARM_RXPC25 249 // ARM BLX (.S - .P) + A
1.664 - // For calls between program segments.
1.665 -#define R_ARM_RSBREL32 250 // Word (.S - .SB) + A
1.666 - // For an offset from SB, the static base.
1.667 -#define R_ARM_THM_RPC22 251 // Thumb BL/BLX pair (.S - .P) + A
1.668 - // For calls between program segments.
1.669 -#define R_ARM_RREL32 252 // Word (.S - .P) + A
1.670 - // For on offset between two segments.
1.671 -#define R_ARM_RABS32 253 // Word .S + A
1.672 - // For the address of a location in the target segment.
1.673 -#define R_ARM_RPC24 254 // ARM B/BL (.S - .P) + A
1.674 - // For calls between program segments.
1.675 -#define R_ARM_RBASE 255 // None Identifies the segment being relocated by
1.676 - // the following relocation directives.
1.677 -// DYNAMIC SEGMENT
1.678 -// The dynamic segment begins with a dynamic section containing an array of structures of type:
1.679 -typedef struct Elf32_Dyn {
1.680 - Elf32_Sword d_tag;
1.681 - Elf32_Word d_val;
1.682 -} Elf32_Dyn;
1.683 -
1.684 -// This entry marks the end of the dynamic array. mandatory
1.685 -#define DT_NULL 0
1.686 -// Index in the string table of the name of a needed library. multiple
1.687 -#define DT_NEEDED 1
1.688 -// These entries are unused by versions 1-2 of the ARM EABI. unused
1.689 -#define DT_PLTRELSZ 2
1.690 -#define DT_PLTGOT 3
1.691 -// The offset of the hash table section in the dynamic segment. mandatory
1.692 -#define DT_HASH 4
1.693 -// The offset of the string table section in the dynamic segment. mandatory
1.694 -#define DT_STRTAB 5
1.695 -// The offset of the symbol table section in the dynamic segment. mandatory
1.696 -#define DT_SYMTAB 6
1.697 -// The offset in the dynamic segment of an SHT_RELA relocation
1.698 -// section, Its bytesize,and the byte size of an ARMRELA-type
1.699 -// relocation entry. optional
1.700 -#define DT_RELA 7
1.701 -#define DT_RELASZ 8
1.702 -#define DT_RELAENT 9
1.703 -// The byte size of the string table section. mandatory
1.704 -#define DT_STRSZ 10
1.705 -// The byte size of an ARM symbol table entry. mandatory
1.706 -#define DT_SYMENT 11
1.707 -// These entries are unused by versions 1-2 of the ARM EABI. unused
1.708 -#define DT_INIT 12
1.709 -#define DT_FINI 13
1.710 -// The Index in the string table of the name of this shared object. mandatory
1.711 -#define DT_SONAME 14
1.712 -// Unused by the ARM EABI. unused
1.713 -#define DT_RPATH 15
1.714 -#define DT_SYMBOLIC 16
1.715 -//The offset in the dynamic segment of an SHT_REL relocation section,
1.716 -//Its bytesize, and the byte size of an ARMREL-type relocation
1.717 -//entry. optional
1.718 -#define DT_REL 17
1.719 -#define DT_RELSZ 18
1.720 -#define DT_RELENT 19
1.721 -// These entries are unused by versions 1-2 of the ARM EABI. unused
1.722 -#define DT_PLTREL 20
1.723 -#define DT_DEBUG 21
1.724 -#define DT_TEXTREL 22
1.725 -#define DT_JMPREL 23
1.726 -#define DT_BIND_NOW 24
1.727 -#define DT_INIT_ARRAY 25
1.728 -#define DT_FINI_ARRAY 26
1.729 -#define DT_INIT_ARRAYSZ 27
1.730 -#define DT_FINI_ARRAYSZ 28
1.731 -
1.732 -#define DT_VERSYM 0x6ffffff0 /* see section 3.3.3.1 in bpabi*/
1.733 -#define DT_RELCOUNT 0x6ffffffa
1.734 -#define DT_VERDEF 0x6ffffffc /* Address of version definition
1.735 - table */
1.736 -#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */
1.737 -#define DT_VERNEED 0x6ffffffe /* Address of table with needed
1.738 - versions */
1.739 -#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */
1.740 -
1.741 -// Values in this range are reserved to the ARM EABI. unused
1.742 -#define DT_LOPROC 0x70000000
1.743 -#define DT_HIPROC 0x7fffffff
1.744 -#define DT_ARM_RESERVED1 0x70000000
1.745 -/* Number of entries in the dynamic symbol table, including the initial dummy symbol. */
1.746 -#define DT_ARM_SYMTABSZ_21 0x70000000 // For RVCT 2.1
1.747 -#define DT_ARM_SYMTABSZ 0x70000001 // The DT_ARM_SYMTABSZ tag value has been changed from RVCT2.2
1.748 -/* Holds the address of the pre-emption map for platforms that use the DLL static binding model. */
1.749 -#define DT_ARM_PREEMPTMAP 0x70000002
1.750 -#define DT_ARM_RESERVED2 0x70000003
1.751 -#define DT_ARM_PLTGOTBASE 0x70000004
1.752 -#define DT_ARM_PLTGOTLIMIT 0x70000005
1.753 -
1.754 -// What the hash table looks like in the dynamic segment
1.755 -typedef struct Elf32_HashTable {
1.756 - Elf32_Word nBuckets;
1.757 - Elf32_Word nChains;
1.758 - // Elf32_Word bucket[nBuckets];
1.759 - // Elf32_Word chain[nChains];
1.760 -} Elf32_HashTable;
1.761 -
1.762 -
1.763 -typedef struct
1.764 -{
1.765 - Elf32_Half vd_version; /* Version revision */
1.766 - Elf32_Half vd_flags; /* Version information */
1.767 - Elf32_Half vd_ndx; /* Version Index */
1.768 - Elf32_Half vd_cnt; /* Number of associated aux entries */
1.769 - Elf32_Word vd_hash; /* Version name hash value */
1.770 - Elf32_Word vd_aux; /* Offset in bytes to verdaux array */
1.771 - Elf32_Word vd_next; /* Offset in bytes to next verdef
1.772 - entry */
1.773 -} Elf32_Verdef;
1.774 -
1.775 -typedef struct
1.776 -{
1.777 - Elf32_Word vda_name; /* Version or dependency names */
1.778 - Elf32_Word vda_next; /* Offset in bytes to next verdaux
1.779 - entry */
1.780 -} Elf32_Verdaux;
1.781 -
1.782 -
1.783 -typedef struct
1.784 -{
1.785 - Elf32_Half vn_version; /* Version of structure */
1.786 - Elf32_Half vn_cnt; /* Number of associated aux entries */
1.787 - Elf32_Word vn_file; /* Offset of filename for this
1.788 - dependency */
1.789 - Elf32_Word vn_aux; /* Offset in bytes to vernaux array */
1.790 - Elf32_Word vn_next; /* Offset in bytes to next verneed
1.791 - entry */
1.792 -} Elf32_Verneed;
1.793 -
1.794 -typedef struct {
1.795 - Elf32_Word vna_hash;
1.796 - Elf32_Half vna_flags;
1.797 - Elf32_Half vna_other;
1.798 - Elf32_Word vna_name;
1.799 - Elf32_Word vna_next;
1.800 -} Elf32_Vernaux;
1.801 -
1.802 -
1.803 -enum ESegmentType
1.804 -{
1.805 - ESegmentUndefined = SHN_UNDEF, // undefined or meaningless section/segment reference
1.806 - ESegmentRO, // Read Only (text) segment
1.807 - ESegmentRW, // Read Write (data) segment
1.808 - ESegmentDynamic, // Dynamic segment
1.809 - ESegmentABS = SHN_ABS, // Symbols defined relative to section number SHN_ABS have
1.810 - // absolute values and are not affected by relocation.
1.811 - ESegmentCommon = SHN_COMMON, // Symbols defined relative to section number SHN_ABS have
1.812 - // absolute values and are not affected by relocation.
1.813 -};
1.814 -
1.815 -#endif