rev 52889 : 8214023: Update Graal

   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 
  25 
  26 package jdk.tools.jaotc.binformat.macho;
  27 
  28 //@formatter:off
  29 //@Checkstyle: stop
  30 
  31 /**
  32  *
  33  * Support for the creation of Mach-o Object files. Current support is limited to 64 bit x86_64.
  34  *
  35  * File Format Overview:
  36  *
  37  *   mach_header
  38  *   load_commands
  39  *      Typical Mac OSX 64-bit object files have these 4 load_commands
  40  *      (LC_SEGMENT_64, LC_SYMTAB, LC_VERSIN_MIN_MACOSX, LC_DYSYMTAB)
  41  *   Segments corresponding to load_commands
  42  *      (which each include multiple Sections)
  43  */
  44 
  45 final class MachO {
  46 
  47     /**
  48      * mach_header_64 structure defines
  49      */
  50     enum mach_header_64 {
  51                  magic( 0, 4),
  52                cputype( 4, 4),
  53             cpusubtype( 8, 4),
  54               filetype(12, 4),
  55                  ncmds(16, 4),
  56             sizeofcmds(20, 4),
  57                  flags(24, 4),
  58               reserved(28, 4);
  59 
  60         final int off;
  61         final int sz;
  62 
  63         mach_header_64(int offset, int size) {
  64             this.off = offset;
  65             this.sz = size;
  66         }
  67 
  68         static int totalsize = 32;
  69 
  70         /**
  71          * mach_header_64 defines
  72          */
  73         static final int MH_MAGIC                   = 0xfeedface;
  74         static final int MH_MAGIC_64                = 0xfeedfacf;
  75         static final int MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000;
  76 
  77         /**
  78          * filetype
  79          */
  80         static final int MH_OBJECT = 0x1;
  81 
  82         /**
  83          * cputype
  84          */
  85         static final int CPU_TYPE_ANY              = -1;
  86         static final int CPU_ARCH_ABI64            = 0x1000000;
  87         static final int CPU_TYPE_X86_64           = 0x1000007;
  88         static final int CPU_TYPE_ARM64            = 0x100000c;
  89         /**
  90          * cpusubtype
  91          */
  92         static final int CPU_SUBTYPE_I386_ALL      = 3;
  93         static final int CPU_SUBTYPE_ARM64_ALL     = 0;
  94         static final int CPU_SUBTYPE_LITTLE_ENDIAN = 0;
  95         static final int CPU_SUBTYPE_BIG_ENDIAN    = 1;
  96 
  97     }
  98 
  99     /**
 100      * segment_command_64 structure defines
 101      */
 102     enum segment_command_64 {
 103                    cmd( 0, 4),
 104                cmdsize( 4, 4),
 105                segname( 8,16),
 106                 vmaddr(24, 8),
 107                 vmsize(32, 8),
 108                fileoff(40, 8),
 109               filesize(48, 8),
 110                maxprot(56, 4),
 111               initprot(60, 4),
 112                 nsects(64, 4),
 113                  flags(68, 4);
 114 
 115         final int off;
 116         final int sz;
 117 
 118         segment_command_64(int offset, int size) {
 119             this.off = offset;
 120             this.sz = size;
 121         }
 122 
 123         static int totalsize = 72;
 124 
 125         static final int LC_SEGMENT_64           = 0x19;
 126     }
 127 
 128     /**
 129      * section_64 structure defines
 130      */
 131     enum section_64 {
 132               sectname( 0,16),
 133                segname(16,16),
 134                   addr(32, 8),
 135                   size(40, 8),
 136                 offset(48, 4),
 137                  align(52, 4),
 138                 reloff(56, 4),
 139                 nreloc(60, 4),
 140                  flags(64, 4),
 141              reserved1(68, 4),
 142              reserved2(72, 4),
 143              reserved3(76, 4);
 144 
 145         final int off;
 146         final int sz;
 147 
 148         section_64(int offset, int size) {
 149             this.off = offset;
 150             this.sz = size;
 151         }
 152 
 153         static int totalsize = 80;
 154 
 155         static int S_REGULAR                = 0x0;
 156         static int S_CSTRING_LITERALS       = 0x2;
 157         static int S_ATTR_PURE_INSTRUCTIONS = 0x80000000;
 158         static int S_ATTR_SOME_INSTRUCTIONS = 0x400;
 159     }
 160 
 161     /**
 162      * version_min_command structure defines
 163      */
 164     enum version_min_command {
 165                    cmd( 0, 4),
 166                cmdsize( 4, 4),
 167                version( 8, 4),
 168                    sdk(12, 4);
 169 
 170         final int off;
 171         final int sz;
 172 
 173         version_min_command(int offset, int size) {
 174             this.off = offset;
 175             this.sz = size;
 176         }
 177 
 178         static int totalsize = 16;
 179 
 180         static final int LC_VERSION_MIN_MACOSX   = 0x24;
 181         static final int LC_VERSION_MIN_IPHONEOS = 0x25;
 182     }
 183 
 184     /**
 185      * symtab_command structure defines
 186      */
 187     enum symtab_command {
 188                    cmd( 0, 4),
 189                cmdsize( 4, 4),
 190                 symoff( 8, 4),
 191                  nsyms(12, 4),
 192                 stroff(16, 4),
 193                strsize(20, 4);
 194 
 195         final int off;
 196         final int sz;
 197 
 198         symtab_command(int offset, int size) {
 199             this.off = offset;
 200             this.sz = size;
 201         }
 202 
 203         static int totalsize = 24;
 204 
 205         static final int LC_SYMTAB               = 0x2;
 206     }
 207 
 208     /**
 209      * Symbol table entry definitions
 210      *
 211      * nlist_64 structure defines
 212      */
 213     enum nlist_64 {
 214                 n_strx( 0, 4),
 215                 n_type( 4, 1),
 216                 n_sect( 5, 1),
 217                 n_desc( 6, 2),
 218                n_value( 8, 8);
 219 
 220         final int off;
 221         final int sz;
 222 
 223         nlist_64(int offset, int size) {
 224             this.off = offset;
 225             this.sz = size;
 226         }
 227 
 228         static int totalsize = 16;
 229 
 230         static final int N_EXT                = 0x1;
 231         static final int N_TYPE               = 0xe;
 232         static final int N_UNDF               = 0x0;
 233         static final int N_SECT               = 0xe;
 234     }
 235 
 236     /**
 237      * dysymtab_command structure defines
 238      */
 239     enum dysymtab_command {
 240                    cmd( 0, 4),
 241                cmdsize( 4, 4),
 242              ilocalsym( 8, 4),
 243              nlocalsym(12, 4),
 244             iextdefsym(16, 4),
 245             nextdefsym(20, 4),
 246              iundefsym(24, 4),
 247              nundefsym(28, 4),
 248                 tocoff(32, 4),
 249                   ntoc(36, 4),
 250              modtaboff(40, 4),
 251                nmodtab(44, 4),
 252           extrefsymoff(48, 4),
 253            nextrefsyms(52, 4),
 254         indirectsymoff(56, 4),
 255          nindirectsyms(60, 4),
 256              extreloff(64, 4),
 257                nextrel(68, 4),
 258              locreloff(72, 4),
 259                nlocrel(76, 4);
 260 
 261         final int off;
 262         final int sz;
 263 
 264         dysymtab_command(int offset, int size) {
 265             this.off = offset;
 266             this.sz = size;
 267         }
 268 
 269         static int totalsize = 80;
 270 
 271         static final int LC_DYSYMTAB             = 0xb;
 272     }
 273 
 274     /**
 275      * relocation_info structure defines
 276      */
 277     enum reloc_info {
 278              r_address( 0, 4),
 279            r_relocinfo( 4, 4);
 280 
 281         final int off;
 282         final int sz;
 283 
 284         reloc_info(int offset, int size) {
 285             this.off = offset;
 286             this.sz = size;
 287         }
 288 
 289         static int totalsize = 8;
 290 
 291         static final int REL_SYMNUM_MASK         = 0xffffff;
 292         static final int REL_SYMNUM_SHIFT        = 0x0;
 293         static final int REL_PCREL_MASK          = 0x1;
 294         static final int REL_PCREL_SHIFT         = 0x18;
 295         static final int REL_LENGTH_MASK         = 0x3;
 296         static final int REL_LENGTH_SHIFT        = 0x19;
 297         static final int REL_EXTERN_MASK         = 0x1;
 298         static final int REL_EXTERN_SHIFT        = 0x1b;
 299         static final int REL_TYPE_MASK           = 0xf;
 300         static final int REL_TYPE_SHIFT          = 0x1c;
 301 
 302         /* reloc_type_x86_64 defines */
 303 
 304         static final int X86_64_RELOC_NONE      = 0x0;
 305         static final int X86_64_RELOC_BRANCH    = 0x2;
 306         static final int X86_64_RELOC_GOT       = 0x4;
 307         static final int X86_64_RELOC_GOT_LOAD  = 0x3;
 308         static final int X86_64_RELOC_SIGNED    = 0x1;
 309         static final int X86_64_RELOC_UNSIGNED  = 0x0;
 310     }
 311 }
--- EOF ---