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.pecoff;
  27 
  28 import java.nio.ByteBuffer;
  29 import java.util.ArrayList;
  30 
  31 import jdk.tools.jaotc.binformat.pecoff.PECoff.IMAGE_RELOCATION;
  32 
  33 final class PECoffRelocTable {
  34     ArrayList<ArrayList<PECoffRelocEntry>> relocEntries;
  35 
  36     PECoffRelocTable(int numsects) {
  37         relocEntries = new ArrayList<>(numsects);
  38         for (int i = 0; i < numsects; i++) {
  39             relocEntries.add(new ArrayList<PECoffRelocEntry>());
  40         }
  41     }
  42 
  43     void createRelocationEntry(int sectindex, int offset, int symno, int type) {
  44         PECoffRelocEntry entry = new PECoffRelocEntry(offset, symno, type);
  45         relocEntries.get(sectindex).add(entry);
  46     }
  47 
  48     static int getAlign() {
  49         return (4);
  50     }
  51 
  52     int getNumRelocs(int sectionIndex) {
  53         return relocEntries.get(sectionIndex).size();
  54     }
  55 
  56     // Return the relocation entries for a single section
  57     // or null if no entries added to section
  58     byte[] getRelocData(int sectionIndex) {
  59         ArrayList<PECoffRelocEntry> entryList = relocEntries.get(sectionIndex);
  60         int entryCount = entryList.size();
  61         int allocCount = entryCount;
  62 
  63         if (entryCount == 0) {
  64             return null;
  65         }
  66         if (entryCount > 0xFFFF) {
  67             allocCount++;
  68         }
  69         ByteBuffer relocData = PECoffByteBuffer.allocate(allocCount * IMAGE_RELOCATION.totalsize);
  70 
  71         // If number of relocs exceeds 65K, add the real size
  72         // in a dummy first reloc entry
  73         if (entryCount > 0xFFFF) {
  74             PECoffRelocEntry entry = new PECoffRelocEntry(allocCount, 0, 0);
  75             relocData.put(entry.getArray());
  76         }
  77 
  78         // Copy each entry to a single ByteBuffer
  79         for (int i = 0; i < entryCount; i++) {
  80             PECoffRelocEntry entry = entryList.get(i);
  81             relocData.put(entry.getArray());
  82         }
  83 
  84         return (relocData.array());
  85     }
  86 }
--- EOF ---