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.macho; 25 26 import java.util.ArrayList; 27 import java.nio.ByteBuffer; 28 import java.nio.ByteOrder; 29 30 import jdk.tools.jaotc.binformat.macho.MachORelocEntry; 31 import jdk.tools.jaotc.binformat.macho.MachOTargetInfo; 32 import jdk.tools.jaotc.binformat.macho.MachO.reloc_info; 33 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer; 34 35 public class MachORelocTable { 36 ArrayList<ArrayList<MachORelocEntry>> relocEntries; 37 int fileOffset; 38 39 public MachORelocTable(int numsects) { 40 relocEntries = new ArrayList<ArrayList<MachORelocEntry>>(numsects); 41 for (int i = 0; i < numsects; i++) 42 relocEntries.add(new ArrayList<MachORelocEntry>()); 43 } 44 45 public void createRelocationEntry(int sectindex, 46 int offset, 47 int symno, 48 int pcrel, 49 int length, 50 int isextern, 51 int type) { 52 53 MachORelocEntry entry = new MachORelocEntry(offset, 54 symno, 55 pcrel, 56 length, 57 isextern, 58 type); 59 relocEntries.get(sectindex).add(entry); 60 } 61 62 public int getAlign() { 63 return (4); 64 } 65 66 public int getNumRelocs(int section_index) { 67 return relocEntries.get(section_index).size(); 68 } 69 70 // Return the relocation entries for a single section 71 // or null if no entries added to section 72 public byte [] getRelocData(int section_index) { 73 ArrayList<MachORelocEntry> entryList = relocEntries.get(section_index); 74 75 if (entryList.size() == 0) 76 return null; 77 78 ByteBuffer relocData = MachOByteBuffer.allocate(entryList.size() * reloc_info.totalsize); 79 80 // Copy each entry to a single ByteBuffer 81 for (int i = 0; i < entryList.size(); i++) { 82 MachORelocEntry entry = entryList.get(i); 83 relocData.put(entry.getArray()); 84 } 85 86 return (relocData.array()); 87 } 88 } 89 | 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.macho; 25 26 import java.util.ArrayList; 27 import java.nio.ByteBuffer; 28 29 import jdk.tools.jaotc.binformat.macho.MachORelocEntry; 30 import jdk.tools.jaotc.binformat.macho.MachO.reloc_info; 31 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer; 32 33 final class MachORelocTable { 34 private final ArrayList<ArrayList<MachORelocEntry>> relocEntries; 35 int fileOffset; 36 37 MachORelocTable(int numsects) { 38 relocEntries = new ArrayList<>(numsects); 39 for (int i = 0; i < numsects; i++) { 40 relocEntries.add(new ArrayList<MachORelocEntry>()); 41 } 42 } 43 44 void createRelocationEntry(int sectindex, int offset, int symno, int pcrel, int length, int isextern, int type) { 45 MachORelocEntry entry = new MachORelocEntry(offset, symno, pcrel, length, isextern, type); 46 relocEntries.get(sectindex).add(entry); 47 } 48 49 static int getAlign() { 50 return (4); 51 } 52 53 int getNumRelocs(int section_index) { 54 return relocEntries.get(section_index).size(); 55 } 56 57 // Return the relocation entries for a single section 58 // or null if no entries added to section 59 byte[] getRelocData(int section_index) { 60 ArrayList<MachORelocEntry> entryList = relocEntries.get(section_index); 61 62 if (entryList.size() == 0) { 63 return null; 64 } 65 ByteBuffer relocData = MachOByteBuffer.allocate(entryList.size() * reloc_info.totalsize); 66 67 // Copy each entry to a single ByteBuffer 68 for (int i = 0; i < entryList.size(); i++) { 69 MachORelocEntry entry = entryList.get(i); 70 relocData.put(entry.getArray()); 71 } 72 73 return (relocData.array()); 74 } 75 } |