Skip to content

Commit

Permalink
Do not fold exported UnmanagedCallersOnly symbols (#103884)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored Jun 24, 2024
1 parent b112eac commit 81441a1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ private void EnsureMap(NodeFactory factory)
if (body is ISpecialUnboxThunkNode unboxThunk && unboxThunk.IsSpecialUnboxingThunk)
continue;

// Bodies that are visible from outside should not be folded because we don't know
// if they're address taken.
if (factory.GetSymbolAlternateName(body) != null)
continue;

var key = new MethodInternKey(body, factory);
if (methodHash.TryGetValue(key, out MethodInternKey found))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

class BodyFoldingTest
{
[UnmanagedCallersOnly(EntryPoint = "FoldableMethod1")]
static void FoldableMethod1() { }

[UnmanagedCallersOnly(EntryPoint = "FoldableMethod2")]
static void FoldableMethod2() { }

class SimpleDelegateTargets
{
public static object Return1DelStatic() => new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<Compile Include="StackTraceMetadata.cs" />
<Compile Include="BodyFoldingTest.cs" />
</ItemGroup>

<ItemGroup>
<IlcArg Include="--export-unmanaged-entrypoints" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
<Compile Include="StackTraceMetadata.cs" />
<Compile Include="BodyFoldingTest.cs" />
</ItemGroup>

<ItemGroup>
<IlcArg Include="--export-unmanaged-entrypoints" />
</ItemGroup>
</Project>

0 comments on commit 81441a1

Please sign in to comment.