8183149: [AOT] SEGV in AMD64MathStub.pow: alignment for ArrayDataPointerConstant is not honored
authorbobv
Tue, 08 Aug 2017 11:44:23 -0400
changeset 46774 427f3511c490
parent 46773 fb17cc9a6847
child 46775 d0af9e47df69
child 46776 6f3aae38bad3
8183149: [AOT] SEGV in AMD64MathStub.pow: alignment for ArrayDataPointerConstant is not honored Reviewed-by: kvn
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/ElfSection.java	Tue Aug 08 11:44:23 2017 -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);
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/elf/JELFRelocObject.java	Tue Aug 08 11:44:23 2017 -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<ElfSection> sections = new ArrayList<ElfSection>();
 
         // 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());
@@ -435,13 +440,14 @@
                 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());
+                                                                    relname,
+                                                                    elfRelocTable.getRelocData(i),
+                                                                    false,
+                                                                    8,
+                                                                    0,
+                                                                    Elf64_Shdr.SHT_RELA);
+                        relocSection.setLink(symtabsectidx);
+                        relocSection.setInfo(sect.getSectionId());
             }
         }
     }
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/JMachORelocObject.java	Tue Aug 08 11:44:23 2017 -0400
@@ -96,7 +96,8 @@
                                              segName,
                                              c.getByteArray(),
                                              scnFlags,
-                                             c.hasRelocations());
+                                             c.hasRelocations(),
+                                             segmentSize);
         // Add this section to our list
         sections.add(sect);
 
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java	Tue Aug 08 11:44:23 2017 -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,8 @@
 
         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,
+                       31 - Integer.numberOfLeadingZeros(align));
 
         section.putInt(section_64.flags.off, sectFlags);
 
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/JPECoffRelocObject.java	Tue Aug 08 11:44:23 2017 -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(ArrayList<PECoffSection>sections,
@@ -97,20 +100,20 @@
     private void createCodeSection(ArrayList<PECoffSection>sections, 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(ArrayList<PECoffSection>sections, 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(ArrayList<PECoffSection>sections, 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;
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java	Tue Aug 08 09:53:52 2017 -0400
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/pecoff/PECoff.java	Tue Aug 08 11:44:23 2017 -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;