From 7cb47629a859e24e04431010dcd95d68fa49a035 Mon Sep 17 00:00:00 2001 From: Anton Lapounov Date: Thu, 24 Jun 2021 12:09:36 -0700 Subject: [PATCH] Ensure relocation blocks are 4-byte aligned (#54668) --- .../tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs index 608ba52..1e02a78 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs @@ -703,6 +703,13 @@ namespace ILCompiler.PEWriter /// 16-bit entries encoding offset relative to the base RVA (low 12 bits) and relocation type (top 4 bite) private static void FlushRelocationBlock(BlobBuilder builder, int baseRVA, List 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 -- 2.7.4