1 // Copyright Yazan Dabain 2014. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 module elf.low; 7 8 import elf.low32, elf.low64; 9 import elf.meta; 10 11 import std.conv : to; 12 13 alias ELF_Half = ELF64_Half; 14 alias ELF_Word = ELF64_Word; 15 alias ELF_SWord = ELF64_SWord; 16 alias ELF_XWord = ELF64_XWord; 17 alias ELF_Addr = ELF64_Addr; 18 alias ELF_Off = ELF64_Off; 19 alias ELF_Section = ELF64_Section; 20 21 align(1) struct ELFIdent { 22 align(1): 23 char mag0; 24 char mag1; 25 char mag2; 26 char mag3; 27 ubyte class_; 28 ubyte data; 29 ubyte version_; 30 ubyte osabi; 31 ubyte abiversion; 32 ubyte[6] pad; 33 ubyte nident; 34 } 35 36 static assert(ELFIdent.sizeof == 16); 37 38 struct Identifier { 39 ELFIdent data; 40 41 FileClass fileClass() { 42 return cast(FileClass) data.class_; 43 } 44 45 DataEncoding dataEncoding() { 46 return cast(DataEncoding) data.data; 47 } 48 49 OSABI osABI() { 50 return cast(OSABI) data.osabi; 51 } 52 53 ubyte abiVersion() { 54 return data.abiversion; 55 } 56 } 57 58 enum FileClass : ubyte { 59 class32 = 1, class64 = 2, 60 } 61 62 enum DataEncoding : ubyte { 63 littleEndian = 1, bigEndian = 2, 64 } 65 66 enum OSABI : ubyte { 67 sysv = 0x00, 68 hpux = 0x01, 69 netBSD = 0x02, 70 linux = 0x03, 71 solaris = 0x06, 72 aix = 0x07, 73 irix = 0x08, 74 freeBSD = 0x09, 75 openBSD = 0x0C, 76 standalone = 0xFF, 77 } 78 79 enum ObjectFileType : ELF_Half { 80 none = 0x0000, 81 relocatable = 0x0001, 82 executable = 0x0002, 83 shared_ = 0x0003, 84 core = 0x0004, 85 lowOS = 0xFE00, 86 highOS = 0xFEFF, 87 lowProccessor = 0xFF00, 88 highProcessor = 0xFFFF, 89 } 90 91 enum SectionType : ELF_Word { 92 null_ = 0x0000_0000, 93 programBits = 0x0000_0001, 94 symbolTable = 0x0000_0002, 95 stringTable = 0x0000_0003, 96 relocation = 0x0000_0004, 97 symbolHashTable = 0x0000_0005, 98 dynamicLinkingTable = 0x0000_0006, 99 note = 0x0000_0007, 100 noBits = 0x0000_0008, 101 rel = 0x0000_0009, 102 shlib = 0x0000_000A, 103 dynamicLoaderSymbolTable = 0x0000_000B, 104 lowOS = 0x6000_0000, 105 highOS = 0x6FFF_FFFF, 106 lowProcessor = 0x7000_0000, 107 highProcessor = 0x7FFF_FFFF, 108 } 109 110 // TODO: Review this 111 enum SectionFlag : ELF64_XWord { 112 write = 0x0000_0001, 113 alloc = 0x0000_0002, 114 executable = 0x0000_0004, 115 maskOS = 0x0F00_0000, 116 maskProcessor = 0xF000_0000, 117 } 118 119 enum TargetISA : ELF_Word { 120 sparc = 0x02, 121 x86 = 0x03, 122 mips = 0x08, 123 powerpc = 0x14, 124 arm = 0x28, 125 superh = 0x2A, 126 ia64 = 0x32, 127 x86_64 = 0x3E, 128 aarch64 = 0xB7, 129 }