aboutsummaryrefslogtreecommitdiffstats
path: root/elf
diff options
context:
space:
mode:
authorStefan Bucur <stefanb@zytor.com>2008-06-06 20:34:53 +0300
committerStefan Bucur <stefanb@zytor.com>2008-06-06 20:34:53 +0300
commit98b8be55d69b18ad6bfc76ee6a432e29314c7b9c (patch)
treef738d5c6457edde8ab70b1e75fc9220e645341ea /elf
parent7a6eedf7c031dd8abb33130af71441de5b914716 (diff)
downloadsyslinux-elf-98b8be55d69b18ad6bfc76ee6a432e29314c7b9c.tar.gz
syslinux-elf-98b8be55d69b18ad6bfc76ee6a432e29314c7b9c.tar.xz
syslinux-elf-98b8be55d69b18ad6bfc76ee6a432e29314c7b9c.zip
Implemented section and symbol table headers.
Diffstat (limited to 'elf')
-rw-r--r--elf/elf.h128
-rwxr-xr-xelf/elftestbin0 -> 8431 bytes
-rw-r--r--elf/elftest.c2
3 files changed, 125 insertions, 5 deletions
diff --git a/elf/elf.h b/elf/elf.h
index eaa0f0c8..36186f74 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -3,6 +3,10 @@
#ifndef ELF_H_
#define ELF_H_
+
+////////////////////////////////////////////////////////////////////////////////
+// GENERAL ELF FORMAT DECLARATIONS
+
// ELF data types
typedef unsigned long Elf32_Addr;
typedef unsigned short Elf32_Half;
@@ -10,8 +14,37 @@ typedef unsigned long Elf32_Off;
typedef long Elf32_Sword;
typedef unsigned long Elf32_Word;
-// Size of the magic section
-#define EI_NIDENT 16
+
+////////////////////////////////////////////////////////////////////////////////
+// ELF HEADER DECLARATIONS
+
+// Relevant indices in the identification section
+enum e_ident_indices_enum {
+ // Magic indices
+ EI_MAG0 = 0,
+ EI_MAG1 = 1,
+ EI_MAG2 = 2,
+ EI_MAG3 = 3,
+
+ EI_CLASS = 4,
+ EI_DATA = 5,
+ EI_VERSION = 6,
+ EI_PAD = 7,
+ EI_NIDENT = 16 // Total size of the identification information
+};
+
+enum ei_class_enum {
+ ELFCLASSNONE = 0,
+ ELFCLASS32 = 1,
+ ELFCLASS64 = 2
+};
+
+enum ei_data_enum {
+ ELFDATANONE = 0,
+ ELFDATA2LSB = 1,
+ ELFDATA2MSB = 2
+};
+
// Object file types
enum e_type_enum {
@@ -43,7 +76,7 @@ enum e_version_enum {
// The ELF header
typedef struct {
- unsigned char e_ident[EI_NIDENT]; // Magic
+ unsigned char e_ident[EI_NIDENT]; // Identification
Elf32_Half e_type; // Object file type
Elf32_Half e_machine; // Machine type
Elf32_Word e_version; // Object file version
@@ -56,9 +89,96 @@ typedef struct {
Elf32_Half e_phnum; // Number of entries in PHT
Elf32_Half e_shentsize; // Size of an header in SHT
Elf32_Half e_shnum; // Number of entries in SHT
- Elf32_Half shstrndx; // Section name string table index
+ Elf32_Half e_shstrndx; // Section name string table index
} Elf32_Ehdr;
+////////////////////////////////////////////////////////////////////////////////
+// ELF SECTION DECLARATIONS
+
+// Special section indices
+enum sh_special_enum {
+ SHN_UNDEF = 0, // Undefined
+ SHN_LORESERVE = 0xFF00, // Lower index of reserved range
+ SHN_LOPROC = 0xFF00, // Processor specific semantics interval
+ SHN_HIPROC = 0xFF1F, // *
+ SHN_ABS = 0xFFF1, // Absolute values for the reference
+ SHN_COMMON = 0xFFF2, // Common symbols
+ SHN_HIRESERVE = 0xFFFF // Upper index of reserved range
+};
+
+// Section type
+enum sh_type_enum {
+ SHT_NULL = 0, // Inactive
+ SHT_PROGBITS = 1, // Program specific information
+ SHT_SYMTAB = 2, // Symbol table
+ SHT_STRTAB = 3, // String table
+ SHT_RELA = 4, // Relocation entries with explicit addends
+ SHT_HASH = 5, // Symbol hash table
+ SHT_DYNAMIC = 6, // Dynamic linking information
+ SHT_NOTE = 7, // Marking information
+ SHT_NOBITS = 8, // No space occupied
+ SHT_REL = 9, // Relocation entries w/o explicit addends
+ SHT_SHLIB = 10, // Reserved
+ SHT_DYNSYM = 11, // Symbol table
+ SHT_LOPROC = 0x70000000, // Processor specific semantics
+ SHT_HIPROC = 0x7FFFFFFF, // *
+ SHT_LOUSER = 0x80000000, // Application programs
+ SHT_HIUSER = 0xFFFFFFFF // *
+};
+
+// Section flags
+enum sh_flags_enum {
+ SHF_WRITE = 0x1, // Writable data
+ SHF_ALLOC = 0x2, // Section occupies memory during execution
+ SHF_EXECINSTR = 0x4, // Executable code
+ SHF_MASKPROC = 0xF0000000 // Processor specific semantics
+};
+
+// The section header
+typedef struct {
+ Elf32_Word sh_name; // Index into section header string table
+ Elf32_Word sh_type; // Section type and semantic
+ Elf32_Word sh_flags; // Section flags
+ Elf32_Addr sh_addr; // Address of the memory mapping (or 0)
+ Elf32_Off sh_offset; // Section location in the file
+ Elf32_Word sh_size; // Section size in the file
+ Elf32_Word sh_link; // Section header table index link
+ Elf32_Word sh_info; // Extra information
+ Elf32_Word sh_addralign; // Alignment constraint
+ Elf32_Word sh_entsize; // Entry size for table-like sections
+} Elf32_Shdr;
+
+
+////////////////////////////////////////////////////////////////////////////////
+// SYMBOL TABLE DECLARATIONS
+
+// Special symbol indices
+enum st_special_enum {
+ STN_UNDEF = 0 // Undefined symbol index
+};
+
+// Macros for manipulating a symbol table entry information field
+#define ELF32_ST_BIND(i) ((i) >> 4)
+#define ELF32_ST_TYPE(i) ((i) & 0xF)
+#define ELF32_ST_INFO(b,t) ((b) << 4) + ((t) & 0xF))
+
+enum st_bind_enum {
+ STB_LOCAL = 0,
+ STB_GLOBAL = 1,
+ STB_WEAK = 2,
+ STB_LOPROC = 13,
+ STB_HIPROC = 15
+};
+
+// Symbol table entry
+typedef struct {
+ Elf32_Word st_name; // Index in the name table
+ Elf32_Addr st_value; // Value associated with the symbol
+ Elf32_Word st_size; // Symbol data size
+ unsigned char st_info; // Type and binding attrs.
+ unsigned char st_other; // Reserved (zero)
+ Elf32_Half st_shndx; // Relevant section header table index
+} Elf32_Sym;
#endif /*ELF_H_*/
diff --git a/elf/elftest b/elf/elftest
new file mode 100755
index 00000000..7f8fcf18
--- /dev/null
+++ b/elf/elftest
Binary files differ
diff --git a/elf/elftest.c b/elf/elftest.c
index 154708d6..047537ed 100644
--- a/elf/elftest.c
+++ b/elf/elftest.c
@@ -40,7 +40,7 @@ void print_elf_info(const char *file_name) {
elf_header = (Elf32_Ehdr*)elf_addr;
- printf("Magic:\t\t");
+ printf("Identification:\t");
for (i=0; i < EI_NIDENT; i++) {
printf("%d ", elf_header->e_ident[i]);
}