diff --git a/src/DotNet/Writer/NativeModuleWriter.cs b/src/DotNet/Writer/NativeModuleWriter.cs index df61a815f..7fba11f0e 100644 --- a/src/DotNet/Writer/NativeModuleWriter.cs +++ b/src/DotNet/Writer/NativeModuleWriter.cs @@ -354,6 +354,12 @@ void ReuseIfPossible(PESection section, IReuseChunk chunk, RVA origRva, uint ori if (((uint)origRva & (requiredAlignment - 1)) != 0) return; + var origEnd = origRva + origSize; + foreach (var reusedChunk in reusedChunks) { + if (origRva < reusedChunk.RVA + reusedChunk.Chunk.GetVirtualSize() && origEnd > reusedChunk.RVA) + return; + } + if (section.Remove(chunk) is null) throw new InvalidOperationException(); reusedChunks.Add(new ReusedChunkInfo(chunk, origRva));