Ensure relocation blocks are 4-byte aligned (#54668)
authorAnton Lapounov <antonl@microsoft.com>
Thu, 24 Jun 2021 19:09:36 +0000 (12:09 -0700)
committerGitHub <noreply@github.com>
Thu, 24 Jun 2021 19:09:36 +0000 (12:09 -0700)
src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs

index 608ba52..1e02a78 100644 (file)
@@ -703,6 +703,13 @@ namespace ILCompiler.PEWriter
         /// <param name="offsetsAndTypes">16-bit entries encoding offset relative to the base RVA (low 12 bits) and relocation type (top 4 bite)</param>
         private static void FlushRelocationBlock(BlobBuilder builder, int baseRVA, List<ushort> offsetsAndTypes)
         {
+            // Ensure blocks are 4-byte aligned. This is required by kernel memory manager
+            // on Windows 8.1 and earlier.
+            if ((offsetsAndTypes.Count & 1) == 1)
+            {
+                offsetsAndTypes.Add(0);
+            }
+
             // First, emit the block header: 4 bytes starting RVA,
             builder.WriteInt32(baseRVA);
             // followed by the total block size comprising this header