1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.tools.jaotc.binformat.pecoff; 25 26 /** 27 * 28 * Support for the creation of Coff files. 29 * Current support is limited to 64 bit x86_64. 30 * 31 */ 32 33 public class PECoff { 34 35 /** 36 * IMAGE_FILE_HEADER structure defines 37 */ 38 public enum IMAGE_FILE_HEADER { 39 Machine( 0, 2), 40 NumberOfSections( 2, 2), 41 TimeDateStamp( 4, 4), 42 PointerToSymbolTable( 8, 4), 43 NumberOfSymbols(12, 4), 44 SizeOfOptionalHeader(16, 2), 45 Characteristics(18, 2); 46 47 public final int off; 48 public final int sz; 49 50 IMAGE_FILE_HEADER(int offset, int size) { 51 this.off = offset; 52 this.sz = size; 53 } 54 55 public static int totalsize = 20; 56 57 /** 58 * IMAGE_FILE_HEADER defines 59 */ 60 61 /** 62 * Machine 63 */ 64 public static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0; 65 public static final char IMAGE_FILE_MACHINE_AMD64 = 0x8664; 66 67 } 68 69 /** 70 * IMAGE_SECTION_HEADER structure defines 71 */ 72 public enum IMAGE_SECTION_HEADER { 73 Name( 0, 8), 74 PhysicalAddress( 8, 4), 75 VirtualSize( 8, 4), 76 VirtualAddress(12, 4), 77 SizeOfRawData(16, 4), 78 PointerToRawData(20, 4), 79 PointerToRelocations(24, 4), 80 PointerToLinenumbers(28, 4), 81 NumberOfRelocations(32, 2), 82 NumberOfLinenumbers(34, 2), 83 Characteristics(36, 4); 84 85 public final int off; 86 public final int sz; 87 88 IMAGE_SECTION_HEADER(int offset, int size) { 89 this.off = offset; 90 this.sz = size; 91 } 92 93 public static int totalsize = 40; 94 95 /** 96 * IMAGE_SECTION_HEADER defines 97 */ 98 99 /** 100 * Characteristics 101 */ 102 public static final int IMAGE_SCN_CNT_CODE = 0x20; 103 public static final int IMAGE_SCN_CNT_INITIALIZED_DATA = 0x40; 104 public static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80; 105 public static final int IMAGE_SCN_LNK_COMDAT = 0x1000; 106 public static final int IMAGE_SCN_LNK_INFO = 0x200; 107 public static final int IMAGE_SCN_LNK_REMOVE = 0x800; 108 109 public static final int IMAGE_SCN_ALIGN_1BYTES = 0x100000; 110 public static final int IMAGE_SCN_ALIGN_2BYTES = 0x200000; 111 public static final int IMAGE_SCN_ALIGN_4BYTES = 0x300000; 112 public static final int IMAGE_SCN_ALIGN_8BYTES = 0x400000; 113 public static final int IMAGE_SCN_ALIGN_16BYTES = 0x500000; 114 public static final int IMAGE_SCN_ALIGN_32BYTES = 0x600000; 115 public static final int IMAGE_SCN_ALIGN_64BYTES = 0x700000; 116 public static final int IMAGE_SCN_ALIGN_MASK = 0xf00000; 117 public static final int IMAGE_SCN_ALIGN_SHIFT = 20; 118 119 public static final int IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000; 120 121 public static final int IMAGE_SCN_MEM_SHARED = 0x10000000; 122 public static final int IMAGE_SCN_MEM_EXECUTE = 0x20000000; 123 public static final int IMAGE_SCN_MEM_READ = 0x40000000; 124 public static final int IMAGE_SCN_MEM_WRITE = 0x80000000; 125 126 } 127 128 /** 129 * Symbol table entry definitions 130 * 131 * IMAGE_SYMBOL structure defines 132 */ 133 public enum IMAGE_SYMBOL { 134 ShortName( 0, 8), 135 Short( 0, 4), 136 Long( 4, 4), 137 Value( 8, 4), 138 SectionNumber(12, 2), 139 Type(14, 2), 140 StorageClass(16, 1), 141 NumberOfAuxSymbols(17, 1); 142 143 public final int off; 144 public final int sz; 145 146 IMAGE_SYMBOL(int offset, int size) { 147 this.off = offset; 148 this.sz = size; 149 } 150 151 public static int totalsize = 18; 152 153 /** 154 * Type 155 */ 156 public static final int IMAGE_SYM_DTYPE_NONE = 0x0; 157 public static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20; 158 159 /** 160 * StorageClass 161 */ 162 public static final int IMAGE_SYM_CLASS_NULL = 0x0; 163 public static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2; 164 public static final int IMAGE_SYM_CLASS_STATIC = 0x3; 165 public static final int IMAGE_SYM_CLASS_LABEL = 0x6; 166 167 } 168 169 /** 170 * IMAGE_RELOCATION structure defines 171 */ 172 public enum IMAGE_RELOCATION { 173 VirtualAddress( 0, 4), 174 SymbolTableIndex( 4, 4), 175 Type( 8, 2); 176 177 public final int off; 178 public final int sz; 179 180 IMAGE_RELOCATION(int offset, int size) { 181 this.off = offset; 182 this.sz = size; 183 } 184 185 public static int totalsize = 10; 186 187 /** 188 * Relocation types 189 */ 190 public static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0; 191 public static final int IMAGE_REL_AMD64_ADDR32 = 0x2; 192 public static final int IMAGE_REL_AMD64_ADDR64 = 0x1; 193 public static final int IMAGE_REL_AMD64_REL32 = 0x4; 194 public static final int IMAGE_REL_AMD64_REL32_1 = 0x5; 195 public static final int IMAGE_REL_AMD64_REL32_2 = 0x6; 196 public static final int IMAGE_REL_AMD64_REL32_3 = 0x7; 197 public static final int IMAGE_REL_AMD64_REL32_4 = 0x8; 198 public static final int IMAGE_REL_AMD64_REL32_5 = 0x9; 199 200 } 201 202 }