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