Fix RVA field alignment #888

Merged
sbomer merged 6 commits from fixAlignmentUpstream into master 2023-01-18 13:19:24 -06:00
sbomer commented 2022-12-27 12:07:34 -06:00 (Migrated from github.com)

Upstreaming the change from https://github.com/dotnet/cecil/pull/55.

Fixes https://github.com/dotnet/runtime/issues/79477, specifically, the problem described in https://github.com/dotnet/runtime/issues/79477#issuecomment-1354917614.

This ensures that section starts are aligned by adjusting the previous Range's length to ensure the computed start of a new Range meets the alignment requirements. It was done this way rather than just computing an aligned start for the new Range, because the TextMap assumes that the Ranges are contiguous - see for example GetNextRVA.

Upstreaming the change from https://github.com/dotnet/cecil/pull/55. Fixes https://github.com/dotnet/runtime/issues/79477, specifically, the problem described in https://github.com/dotnet/runtime/issues/79477#issuecomment-1354917614. This ensures that section starts are aligned by adjusting the previous `Range`'s length to ensure the computed start of a new `Range` meets the alignment requirements. It was done this way rather than just computing an aligned start for the new `Range`, because the `TextMap` assumes that the `Range`s are contiguous - see for example `GetNextRVA`.
sbomer commented 2022-12-27 15:21:53 -06:00 (Migrated from github.com)

@jbevain I'm updating the pipeline to use ubuntu-20.04 instead of ubuntu-latest. The ubuntu job was failing because the ubuntu-latest images no longer include the older versions of .NET Core: https://github.com/actions/runner-images/issues/6399.

Testhost process for source(s) '/home/runner/work/cecil/cecil/symbols/mdb/Test/bin/Debug/netcoreapp3.1/Mono.Cecil.Mdb.Tests.dll' exited with error: You must install or update .NET to run this application.
App: /home/runner/.nuget/packages/microsoft.testplatform.testhost/15.9.0/lib/netstandard1.5/testhost.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '3.1.0' (x64)
.NET location: /usr/share/dotnet/
The following frameworks were found:
  6.0.11 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  7.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

The windows job is also failing when running peverify on some unrelated exes in this repo:

Failed X64Module [61 ms]
  Error Message:
   [IL]: Error: [C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe : Program::.ctor]  [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format.[IL]: Error: [C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe : Program::Main]  [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format.2 Error(s) Verifying C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe
  Stack Trace:
     at Mono.Cecil.Tests.CompilationService.Verify(String name) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\CompilationService.cs:line 123
   at Mono.Cecil.Tests.TestRunner.RoundTrip(String location, ReaderParameters reader_parameters, String folder) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 326
   at Mono.Cecil.Tests.TestRunner.GetModule() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 275
   at Mono.Cecil.Tests.TestRunner.RunTest() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 333
   at Mono.Cecil.Tests.BaseTestFixture.Run(TestCase testCase) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 152
   at Mono.Cecil.Tests.BaseTestFixture.TestModule(String file, Action`1 test, Boolean verify, Boolean readOnly, Type symbolReaderProvider, Type symbolWriterProvider, IAssemblyResolver assemblyResolver, Boolean applyWindowsRuntimeProjections, String sourceFilePath) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 127
   at Mono.Cecil.Tests.ImageReadTests.X64Module() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\ImageReadTests.cs:line 97

I'm not sure why this is - it appears unrelated to this recent change to windows-latest, since it fails the same way when using windows-2019.

@jbevain I'm updating the pipeline to use `ubuntu-20.04` instead of `ubuntu-latest`. The ubuntu job was failing because the `ubuntu-latest` images no longer include the older versions of .NET Core: https://github.com/actions/runner-images/issues/6399. ``` Testhost process for source(s) '/home/runner/work/cecil/cecil/symbols/mdb/Test/bin/Debug/netcoreapp3.1/Mono.Cecil.Mdb.Tests.dll' exited with error: You must install or update .NET to run this application. App: /home/runner/.nuget/packages/microsoft.testplatform.testhost/15.9.0/lib/netstandard1.5/testhost.dll Architecture: x64 Framework: 'Microsoft.NETCore.App', version '3.1.0' (x64) .NET location: /usr/share/dotnet/ The following frameworks were found: 6.0.11 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 7.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] ``` The windows job is also failing when running peverify on some unrelated exes in this repo: ``` Failed X64Module [61 ms] Error Message: [IL]: Error: [C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe : Program::.ctor] [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format.[IL]: Error: [C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe : Program::Main] [HRESULT 0x8007000B] - An attempt was made to load a program with an incorrect format.2 Error(s) Verifying C:\Users\runneradmin\AppData\Local\Temp\cecil-drt\hello.x64.exe Stack Trace: at Mono.Cecil.Tests.CompilationService.Verify(String name) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\CompilationService.cs:line 123 at Mono.Cecil.Tests.TestRunner.RoundTrip(String location, ReaderParameters reader_parameters, String folder) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 326 at Mono.Cecil.Tests.TestRunner.GetModule() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 275 at Mono.Cecil.Tests.TestRunner.RunTest() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 333 at Mono.Cecil.Tests.BaseTestFixture.Run(TestCase testCase) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 152 at Mono.Cecil.Tests.BaseTestFixture.TestModule(String file, Action`1 test, Boolean verify, Boolean readOnly, Type symbolReaderProvider, Type symbolWriterProvider, IAssemblyResolver assemblyResolver, Boolean applyWindowsRuntimeProjections, String sourceFilePath) in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\BaseTestFixture.cs:line 127 at Mono.Cecil.Tests.ImageReadTests.X64Module() in D:\a\cecil\cecil\Test\Mono.Cecil.Tests\ImageReadTests.cs:line 97 ``` I'm not sure why this is - it appears unrelated to this recent change to `windows-latest`, since it fails the same way when using `windows-2019`.
sbomer commented 2023-01-09 20:12:00 -06:00 (Migrated from github.com)

Fixed the test failures, which were of course related to my change (I had somehow convinced myself they were unrelated, but in retrospect it is obvious). The problem was the use of GetNextRVA to compute the Code RVA, before adding that segment to the TextMap.

Fixed the test failures, which were of course related to my change (I had somehow convinced myself they were unrelated, but in retrospect it is obvious). The problem was the use of `GetNextRVA` to compute the `Code` RVA, before adding that segment to the TextMap.
jbevain commented 2023-01-18 13:19:33 -06:00 (Migrated from github.com)

Thanks @sbomer!

Thanks @sbomer!
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!888
No description provided.