--- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java 2017-07-25 15:15:55.504734446 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java 2017-07-25 15:15:54.188658769 -0400 @@ -53,9 +53,8 @@ private static int shStrTabNrOfBytes = 0; public ElfSection(String sectName, byte [] sectData, int sectFlags, - int sectType, boolean hasRelocations, int sectIndex) { - - long align; + int sectType, boolean hasRelocations, int align, + int sectIndex) { section = ElfByteBuffer.allocate(Elf64_Shdr.totalsize); @@ -90,35 +89,19 @@ section.putLong(Elf64_Shdr.sh_entsize.off, 0); - // Determine the alignment and entrysize + // Determine the entrysize // based on type of section switch (sectType) { - case Elf64_Shdr.SHT_PROGBITS: - if ((sectFlags & Elf64_Shdr.SHF_EXECINSTR) != 0) - align = 16; - else - align = 4; - break; case Elf64_Shdr.SHT_SYMTAB: - align = 8; section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Sym.totalsize); break; - case Elf64_Shdr.SHT_STRTAB: - align = 1; - break; case Elf64_Shdr.SHT_RELA: - align = 8; section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rela.totalsize); break; case Elf64_Shdr.SHT_REL: - align = 8; section.putLong(Elf64_Shdr.sh_entsize.off, Elf64_Rel.totalsize); break; - case Elf64_Shdr.SHT_NOBITS: - align = 4; - break; default: - align = 8; break; } section.putLong(Elf64_Shdr.sh_addralign.off, align); --- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java 2017-07-25 15:15:59.576968608 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java 2017-07-25 15:15:58.272893622 -0400 @@ -69,6 +69,7 @@ String sectName, byte [] scnData, boolean hasRelocs, + int align, int scnFlags, int scnType) { @@ -77,6 +78,7 @@ scnFlags, scnType, hasRelocs, + align, sections.size()); // Add this section to our list sections.add(sect); @@ -91,7 +93,7 @@ byte[] scnData = c.getByteArray(); int scnType = Elf64_Shdr.SHT_PROGBITS; - boolean zeros = hasRelocs; + boolean zeros = !hasRelocs; if (zeros) { for (byte b : scnData) { if (b != 0) { @@ -105,7 +107,7 @@ } sect = createByteSection(sections, c.getContainerName(), - scnData, hasRelocs, + scnData, hasRelocs, segmentSize, scnFlags, scnType); c.setSectionId(sect.getSectionId()); } @@ -136,7 +138,7 @@ ArrayList sections = new ArrayList(); // Create the null section - createByteSection(sections, null, null, false, 0, 0); + createByteSection(sections, null, null, false, 1, 0, 0); // Create text section createCodeSection(sections, binContainer.getCodeContainer()); @@ -170,6 +172,7 @@ ".strtab", symtab.getStrtabArray(), false, + 1, 0, Elf64_Shdr.SHT_STRTAB); @@ -181,6 +184,7 @@ ".symtab", symtab.getSymtabArray(), false, + 8, 0, Elf64_Shdr.SHT_SYMTAB); symTabSection.setLink(strTabSection.getSectionId()); @@ -196,6 +200,7 @@ ".shstrtab", null, false, + 1, 0, Elf64_Shdr.SHT_STRTAB); eh.setSectionStrNdx(shStrTabSection.getSectionId()); @@ -434,15 +439,16 @@ if (elfRelocTable.getNumRelocs(i) > 0) { ElfSection sect = sections.get(i); String relname = ".rela" + sect.getName(); - ElfSection relocSection = createByteSection(sections, - relname, - elfRelocTable.getRelocData(i), - false, - 0, - Elf64_Shdr.SHT_RELA); - relocSection.setLink(symtabsectidx); - relocSection.setInfo(sect.getSectionId()); - } - } - } + ElfSection relocSection = createByteSection(sections, + relname, + elfRelocTable.getRelocData(i), + false, + 8, + 0, + Elf64_Shdr.SHT_RELA); + relocSection.setLink(symtabsectidx); + relocSection.setInfo(sect.getSectionId()); + } + } + } } --- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java 2017-07-25 15:16:03.937219325 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java 2017-07-25 15:16:02.605142730 -0400 @@ -96,7 +96,8 @@ segName, c.getByteArray(), scnFlags, - c.hasRelocations()); + c.hasRelocations(), + segmentSize); // Add this section to our list sections.add(sect); --- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java 2017-07-25 15:16:07.997452790 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java 2017-07-25 15:16:06.677376885 -0400 @@ -35,7 +35,7 @@ byte [] data; boolean hasrelocations; - public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations) { + public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations, int align) { section = MachOByteBuffer.allocate(section_64.totalsize); // TODO: Hotspot uses long section names. @@ -57,8 +57,7 @@ section.putLong(section_64.size.off, sectData.length); - // For now use 8 byte alignment - section.putInt(section_64.align.off, 3); + section.putInt(section_64.align.off, align); section.putInt(section_64.flags.off, sectFlags); --- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java 2017-07-25 15:16:12.137690856 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java 2017-07-25 15:16:10.837616100 -0400 @@ -62,6 +62,9 @@ this.binContainer = binContainer; this.pecoffContainer = new PECoffContainer(outputFileName, aotVersion); this.segmentSize = binContainer.getCodeSegmentSize(); + if (segmentSize != 64) { + System.out.println("binContainer alignment size not 64 bytes, update JPECoffRelocObject"); + } } private PECoffSection createByteSection(ArrayListsections, @@ -97,20 +100,20 @@ private void createCodeSection(ArrayListsections, CodeContainer c) { createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_EXECUTE | - IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES | + IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_64BYTES | IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_CODE); } private void createReadOnlySection(ArrayListsections, ReadOnlyDataContainer c) { createByteSection(sections, c, IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | - IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_16BYTES | + IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_64BYTES | IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA); } private void createReadWriteSection(ArrayListsections, ByteContainer c) { int scnFlags = IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_READ | IMAGE_SECTION_HEADER.IMAGE_SCN_MEM_WRITE | - IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_8BYTES; + IMAGE_SECTION_HEADER.IMAGE_SCN_ALIGN_64BYTES; if (c.getByteArray().length > 0) scnFlags |= IMAGE_SECTION_HEADER.IMAGE_SCN_CNT_INITIALIZED_DATA; --- old/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java 2017-07-25 15:16:16.145921328 -0400 +++ new/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java 2017-07-25 15:16:14.853847033 -0400 @@ -111,6 +111,8 @@ public static final int IMAGE_SCN_ALIGN_4BYTES = 0x300000; public static final int IMAGE_SCN_ALIGN_8BYTES = 0x400000; public static final int IMAGE_SCN_ALIGN_16BYTES = 0x500000; + public static final int IMAGE_SCN_ALIGN_32BYTES = 0x600000; + public static final int IMAGE_SCN_ALIGN_64BYTES = 0x700000; public static final int IMAGE_SCN_ALIGN_MASK = 0xf00000; public static final int IMAGE_SCN_ALIGN_SHIFT = 20;