src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.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/macho

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java

Print this page




   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.macho;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.macho.MachO;
  30 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
  31 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
  32 
  33 public class MachOSection {
  34     ByteBuffer section;
  35     byte [] data;
  36     boolean hasrelocations;
  37 
  38     public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations, int align) {
  39         section = MachOByteBuffer.allocate(section_64.totalsize);
  40 
  41         // TODO: Hotspot uses long section names.
  42         //       They are getting truncated.
  43         //       Is this a problem??
  44         byte[] sectNameBytes = sectName.getBytes();
  45         int sectNameMax = section_64.sectname.sz < sectNameBytes.length ?
  46                          section_64.sectname.sz : sectNameBytes.length;
  47 
  48         for (int i = 0; i < sectNameMax; i++)
  49             section.put(section_64.sectname.off+i, sectNameBytes[i]);
  50 



  51         byte[] segNameBytes = segName.getBytes();
  52         int segNameMax = section_64.segname.sz < segNameBytes.length ?
  53                          section_64.segname.sz : segNameBytes.length;
  54 
  55         for (int i = 0; i < segNameMax; i++)
  56             section.put(section_64.segname.off+i, segNameBytes[i]);
  57 



  58         section.putLong(section_64.size.off, sectData.length);
  59 
  60         section.putInt(section_64.align.off,
  61                        31 - Integer.numberOfLeadingZeros(align));
  62 
  63         section.putInt(section_64.flags.off, sectFlags);
  64 
  65         data = sectData;
  66 
  67         hasrelocations = hasRelocations;
  68     }
  69 
  70     public long getSize() {
  71         return section.getLong(section_64.size.off);
  72     }
  73 
  74     public int getAlign() {
  75         return (1 << section.getInt(section_64.align.off));
  76     }
  77 
  78     public byte[] getArray() {
  79         return section.array();
  80     }
  81 
  82     public byte[] getDataArray() {
  83         return data;
  84     }
  85 
  86     public void setAddr(long addr) {
  87         section.putLong(section_64.addr.off, addr);
  88     }
  89 
  90     public long getAddr() {
  91         return (section.getLong(section_64.addr.off));
  92     }
  93 
  94     public void setOffset(int offset) {
  95         section.putInt(section_64.offset.off, offset);
  96     }
  97 
  98     public int getOffset() {
  99         return (section.getInt(section_64.offset.off));
 100     }
 101 
 102     public void setReloff(int offset) {
 103         section.putInt(section_64.reloff.off, offset);
 104     }
 105 
 106     public void setRelcount(int count) {
 107         section.putInt(section_64.nreloc.off, count);
 108     }
 109 
 110     public boolean hasRelocations() {
 111         return hasrelocations;
 112     }
 113 }
 114 
 115 


   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.macho;
  25 
  26 import java.nio.ByteBuffer;

  27 

  28 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
  29 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
  30 
  31 final class MachOSection {
  32     private final ByteBuffer section;
  33     private final byte[] data;
  34     private final boolean hasrelocations;
  35 
  36     MachOSection(String sectName, String segName, byte[] sectData, int sectFlags, boolean hasRelocations, int align) {
  37         section = MachOByteBuffer.allocate(section_64.totalsize);
  38 
  39         // TODO: Hotspot uses long section names.
  40         // They are getting truncated.
  41         // Is this a problem??
  42         byte[] sectNameBytes = sectName.getBytes();
  43         int sectNameMax = section_64.sectname.sz < sectNameBytes.length ? section_64.sectname.sz : sectNameBytes.length;




  44 
  45         for (int i = 0; i < sectNameMax; i++) {
  46             section.put(section_64.sectname.off + i, sectNameBytes[i]);
  47         }
  48         byte[] segNameBytes = segName.getBytes();
  49         int segNameMax = section_64.segname.sz < segNameBytes.length ? section_64.segname.sz : segNameBytes.length;




  50 
  51         for (int i = 0; i < segNameMax; i++) {
  52             section.put(section_64.segname.off + i, segNameBytes[i]);
  53         }
  54         section.putLong(section_64.size.off, sectData.length);
  55 
  56         section.putInt(section_64.align.off, 31 - Integer.numberOfLeadingZeros(align));

  57 
  58         section.putInt(section_64.flags.off, sectFlags);
  59 
  60         data = sectData;
  61 
  62         hasrelocations = hasRelocations;
  63     }
  64 
  65     long getSize() {
  66         return section.getLong(section_64.size.off);
  67     }
  68 
  69     int getAlign() {
  70         return (1 << section.getInt(section_64.align.off));
  71     }
  72 
  73     byte[] getArray() {
  74         return section.array();
  75     }
  76 
  77     byte[] getDataArray() {
  78         return data;
  79     }
  80 
  81     void setAddr(long addr) {
  82         section.putLong(section_64.addr.off, addr);
  83     }
  84 
  85     long getAddr() {
  86         return (section.getLong(section_64.addr.off));
  87     }
  88 
  89     void setOffset(int offset) {
  90         section.putInt(section_64.offset.off, offset);
  91     }
  92 
  93     int getOffset() {
  94         return (section.getInt(section_64.offset.off));
  95     }
  96 
  97     void setReloff(int offset) {
  98         section.putInt(section_64.reloff.off, offset);
  99     }
 100 
 101     void setRelcount(int count) {
 102         section.putInt(section_64.nreloc.off, count);
 103     }
 104 
 105     boolean hasRelocations() {
 106         return hasrelocations;
 107     }
 108 }


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