dotnet / runtime-assets

Assets that are required by the runtime repository, and referenced as nuget packages.
MIT License
31 stars 58 forks source link

[Mono.Cecil] Enforce empty body when a MethodDefinition's rva value is 0 #475

Closed steveisok closed 3 months ago

steveisok commented 3 months ago

The prior behavior assumed a MethodDefinition's RVA value of 0 meant an effectively empty body with a single RET instruction. This change removes the RET insertion and leaves the method completely empty. This is important for mono's UnsafeAccessor detection around methods specified as extern as it uses a quicker method of an empty vs non-empty body to bypass loading / checking custom attributes.

Fixes https://github.com/dotnet/runtime/issues/102045

akoeplinger commented 3 months ago

@steveisok this will need some changes to tests once it flows to runtime since we detect the ret pattern, see https://github.com/dotnet/runtime/pull/88167/files for the cases.