-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[NativeAOT] Support exporting methods from referenced assemblies in a formal way #83396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ivanpovazan
merged 20 commits into
dotnet:main
from
ivanpovazan:exports-from-ref-assemblies
Mar 22, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0897d10
[naot] Export methods from referenced assemblies
ivanpovazan ef7bf05
[naot] Adding test case
ivanpovazan baf20d6
[naot] Enable the feature for all configurations
ivanpovazan 6383518
[naot] Introduce better naming
ivanpovazan 230bfa9
[naot] Updating the test case based on the feedback
ivanpovazan b8ff7c7
[naot] Use the new feature to export SPC unmanaged entry points inste…
ivanpovazan 9d73b20
[naot] Cleanup
ivanpovazan db91bb7
[naot] Given a more appropriate name for the unmanaged entry points r…
ivanpovazan 18c0c59
[naot] Adjust repro.csproj to generate the new compiler switch
ivanpovazan 0dab9ec
[naot] Skip adding System.Private.CoreLib as a UnmanagedEntryPointsRo…
ivanpovazan e9593b0
[naot] Test cleanup
ivanpovazan 549ed66
[naot] Include exporting SPC entry points only if system module is no…
ivanpovazan dc45d4c
[naot] Switching the test to be a single executable
ivanpovazan ba51637
[naot] Match the ordering from .targets file
ivanpovazan ea71b8c
[naot] Explicitly export symbols from an executable via IlcExportUnma…
ivanpovazan 87bac10
[naot] Enable overriding IlcExportUnmanagedEntrypoints
ivanpovazan 5ddc135
[naot] Test cleanup
ivanpovazan a5a1c0a
[naot] Using more general approach to avoid adding the same module mu…
ivanpovazan cdbc605
[naot] Fix for including exported symbols in the dynamic symbol table…
ivanpovazan 24a530e
[naot] Using a more appropriate condition
ivanpovazan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/tests/nativeaot/GenerateUnmanagedEntryPoints/GenerateUnmanagedEntryPoints.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace GenerateUnmanagedEntryPoints | ||
| { | ||
| unsafe class Program | ||
| { | ||
| [UnmanagedCallersOnly(EntryPoint = "MainAssemblyMethod")] | ||
| static void MainAssemblyMethod() => Console.WriteLine($"Hello from {nameof(MainAssemblyMethod)}"); | ||
|
|
||
| static int Main() | ||
| { | ||
| IntPtr methodAddress = IntPtr.Zero; | ||
| IntPtr programHandle = IntPtr.Zero; | ||
|
|
||
| programHandle = NativeLibrary.GetMainProgramHandle(); | ||
| if (programHandle == IntPtr.Zero) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| if (NativeLibrary.TryGetExport(programHandle, "MainAssemblyMethod", out methodAddress)) | ||
| { | ||
| var MainAssemblyMethodPtr = (delegate* unmanaged <void>) methodAddress; | ||
| MainAssemblyMethodPtr(); | ||
| } | ||
| else | ||
| { | ||
| return 2; | ||
| } | ||
|
|
||
| if (NativeLibrary.TryGetExport(programHandle, "ReferencedAssembly1Method", out methodAddress)) | ||
| { | ||
| var ReferencedAssembly1MethodPtr = (delegate* unmanaged <void>) methodAddress; | ||
| ReferencedAssembly1MethodPtr(); | ||
| } | ||
| else | ||
| { | ||
| return 3; | ||
| } | ||
|
|
||
| if (NativeLibrary.TryGetExport(programHandle, "ReferencedAssembly2Method", out methodAddress)) | ||
| { | ||
| // must not be exposed from ReferencedAssembly2 assembly | ||
| return 4; | ||
| } | ||
|
|
||
| return 100; | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/tests/nativeaot/GenerateUnmanagedEntryPoints/GenerateUnmanagedEntryPoints.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <CLRTestKind>BuildAndRun</CLRTestKind> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="GenerateUnmanagedEntryPoints.cs" /> | ||
| <ProjectReference Include="$(MSBuildThisFileDirectory)ReferencedAssembly1\ReferencedAssembly1.csproj" /> | ||
| <ProjectReference Include="$(MSBuildThisFileDirectory)ReferencedAssembly2\ReferencedAssembly2.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Expose additional unmanaged entry points from ReferencedAssembly1 --> | ||
| <ItemGroup> | ||
| <UnmanagedEntryPointsAssembly Include="ReferencedAssembly1" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
15 changes: 15 additions & 0 deletions
15
src/tests/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly1/ReferencedAssembly1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace ReferencedAssembly1 | ||
| { | ||
| public class ClassLibrary | ||
| { | ||
| [UnmanagedCallersOnly(EntryPoint = "ReferencedAssembly1Method")] | ||
| public static void ReferencedAssembly1Method() => Console.WriteLine($"Hello from {nameof(ReferencedAssembly1Method)}"); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...sts/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly1/ReferencedAssembly1.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="ReferencedAssembly1.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
15 changes: 15 additions & 0 deletions
15
src/tests/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly2/ReferencedAssembly2.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace ReferencedAssembly2 | ||
| { | ||
| public class ClassLibrary | ||
| { | ||
| [UnmanagedCallersOnly(EntryPoint = "ReferencedAssembly2Method")] | ||
| public static void ReferencedAssembly2Method() => Console.WriteLine($"Hello from {nameof(ReferencedAssembly2Method)}"); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...sts/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly2/ReferencedAssembly2.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="ReferencedAssembly2.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.