1 /* 2 * Copyright (c) 2016, 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; 25 26 public class Relocation { 27 28 public enum RelocType { 29 UNDEFINED, 30 JAVA_CALL_INDIRECT, 31 JAVA_CALL_DIRECT, 32 FOREIGN_CALL_INDIRECT, 33 FOREIGN_CALL_INDIRECT_GOT, // Call to address in GOT cell 34 FOREIGN_CALL_DIRECT, 35 FOREIGN_CALL_DIRECT_FAR, 36 STUB_CALL_DIRECT, 37 STUB_CALL_INDIRECT, 38 EXTERNAL_DATA_REFERENCE_FAR, 39 METASPACE_GOT_REFERENCE, 40 EXTERNAL_GOT_TO_PLT, 41 EXTERNAL_PLT_TO_GOT, 42 STATIC_STUB_TO_STATIC_METHOD, 43 STATIC_STUB_TO_HOTSPOT_LINKAGE_GOT, 44 LOADTIME_ADDRESS 45 } 46 47 private final RelocType type; 48 49 /** 50 * Byte offset from the beginning of the file affected by relocation. 51 */ 52 private final int offset; 53 54 /** 55 * Size of relocation. 56 */ 57 private final int size; 58 59 /** 60 * Symbol associated with this relocation. 61 */ 62 private final Symbol symbol; 63 64 /** 65 * Section this relocation entry modifies. 66 */ 67 private final ByteContainer section; 68 69 public Relocation(int offset, RelocType type, int size, ByteContainer section, Symbol sym) { 70 if (sym == null) { 71 throw new InternalError("must have symbol"); 72 } 73 this.offset = offset; 74 this.type = type; 75 this.size = size; 76 this.symbol = sym; 77 this.section = section; 78 section.setHasRelocations(); 79 } 80 81 public RelocType getType() { 82 return type; 83 } 84 85 public int getOffset() { 86 return offset; 87 } 88 89 public int getSize() { 90 return size; 91 } 92 93 public Symbol getSymbol() { 94 return symbol; 95 } 96 97 public ByteContainer getSection() { 98 return section; 99 } 100 101 }