src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File hotspot Sdiff src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java

Print this page




   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.elf;
  25 
  26 import java.util.ArrayList;
  27 import java.nio.ByteBuffer;
  28 import java.nio.ByteOrder;
  29 
  30 import jdk.tools.jaotc.binformat.elf.ElfRelocEntry;
  31 import jdk.tools.jaotc.binformat.elf.ElfTargetInfo;
  32 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;
  33 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Ehdr;
  34 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
  35 
  36 public class ElfRelocTable {
  37     ArrayList<ArrayList<ElfRelocEntry>> relocEntries;
  38 
  39     public ElfRelocTable(int numsects) {
  40         relocEntries = new ArrayList<ArrayList<ElfRelocEntry>>(numsects);
  41         for (int i = 0; i < numsects; i++)
  42             relocEntries.add(new ArrayList<ElfRelocEntry>());
  43     }

  44 
  45     public void createRelocationEntry(int sectindex,
  46                                       int offset,
  47                                       int symno,
  48                                       int type,
  49                                       int addend) {
  50 
  51         ElfRelocEntry entry = new ElfRelocEntry(offset,
  52                                                 symno,
  53                                                 type,
  54                                                 addend);
  55         relocEntries.get(sectindex).add(entry);
  56     }
  57 
  58     public int getNumRelocs(int section_index) {
  59         return relocEntries.get(section_index).size();
  60     }
  61 
  62     // Return the relocation entries for a single section
  63     //   or null if no entries added to section
  64     public byte [] getRelocData(int section_index) {
  65         ArrayList<ElfRelocEntry> entryList = relocEntries.get(section_index);
  66 
  67         if (entryList.size() == 0)
  68             return null;
  69 
  70         ByteBuffer relocData = ElfByteBuffer.allocate(entryList.size() * Elf64_Rela.totalsize);
  71 
  72         // Copy each entry to a single ByteBuffer
  73         for (int i = 0; i < entryList.size(); i++) {
  74             ElfRelocEntry entry = entryList.get(i);
  75             relocData.put(entry.getArray());
  76         }
  77 
  78         return (relocData.array());
  79     }
  80 }
  81 


   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.elf;
  25 
  26 import java.util.ArrayList;
  27 import java.nio.ByteBuffer;

  28 
  29 import jdk.tools.jaotc.binformat.elf.ElfRelocEntry;

  30 import jdk.tools.jaotc.binformat.elf.Elf.Elf64_Rela;

  31 import jdk.tools.jaotc.binformat.elf.ElfByteBuffer;
  32 
  33 final class ElfRelocTable {
  34     private final ArrayList<ArrayList<ElfRelocEntry>> relocEntries;
  35 
  36     ElfRelocTable(int numsects) {
  37         relocEntries = new ArrayList<>(numsects);
  38         for (int i = 0; i < numsects; i++) {
  39             relocEntries.add(new ArrayList<ElfRelocEntry>());
  40         }
  41     }
  42 
  43     void createRelocationEntry(int sectindex, int offset, int symno, int type, int addend) {
  44         ElfRelocEntry entry = new ElfRelocEntry(offset, symno, type, addend);








  45         relocEntries.get(sectindex).add(entry);
  46     }
  47 
  48     int getNumRelocs(int section_index) {
  49         return relocEntries.get(section_index).size();
  50     }
  51 
  52     // Return the relocation entries for a single section
  53     // or null if no entries added to section
  54     byte[] getRelocData(int section_index) {
  55         ArrayList<ElfRelocEntry> entryList = relocEntries.get(section_index);
  56 
  57         if (entryList.size() == 0) {
  58             return null;
  59         }
  60         ByteBuffer relocData = ElfByteBuffer.allocate(entryList.size() * Elf64_Rela.totalsize);
  61 
  62         // Copy each entry to a single ByteBuffer
  63         for (int i = 0; i < entryList.size(); i++) {
  64             ElfRelocEntry entry = entryList.get(i);
  65             relocData.put(entry.getArray());
  66         }
  67 
  68         return (relocData.array());
  69     }
  70 }

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfRelocTable.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File