-
Notifications
You must be signed in to change notification settings - Fork 565
[illink] set $(StartupHookSupport)=false *only* for Release mode
#10670
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
Conversation
|
@rolfbjarne do you know if this works on iOS/Catalyst? |
tests/Mono.Android-Tests/Mono.Android-Tests/System/StartupHookTest.cs
Outdated
Show resolved
Hide resolved
I did a quick test, and it doesn't seem to work, so I filed an issue: dotnet/macios#24492 |
Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md .NET has a concept of a "startup hook", which appears to work fine on Mono if you set: env.txt DOTNET_STARTUP_HOOKS=StartupHook (MSBuild) <StartupHookSupport>true</StartupHookSupport> <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" /> The startup hook is a managed assembly with a static method, in the "global" namespace: class StartupHook { public static void Initialize() { // ... } } When the runtime starts, it will call `StartupHook.Initialize()` before any other managed code is executed. `dotnet watch` (Hot Reload) relies on this feature. I added a test to `Mono.Android-Tests` to verify that the startup hook was called. This is not yet working on CoreCLR on Android, investigation ongoing.
a09103f to
17176cd
Compare
| return; | ||
| } | ||
|
|
||
| var method = type.GetMethod (methodName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use the [UnsafeAccessor] attribute to avoid using reflection here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you can only do that if a type is public, and it's internal in System.Private.CoreLib.
| } | ||
|
|
||
| [RequiresUnreferencedCode ("Uses reflection to access System.StartupHookProvider.")] | ||
| static void RunStartupHooks () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a test to ensure this method is really trimmed away for a Release build (or when startuphook support is not enabled)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we run the new test in both trimmed, AOT, all runtimes, etc.
They have a line in dotnet/runtime to preserve it, too:

Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md
.NET has a concept of a "startup hook", which appears to work fine
on Mono if you set:
The startup hook is a managed assembly with a static method, in the
"global" namespace:
When the runtime starts, it will call
StartupHook.Initialize()beforeany other managed code is executed.
dotnet watch(Hot Reload) relies on this feature.I added a test to
Mono.Android-Teststo verify that the startup hookwas called.
This is not yet working on CoreCLR on Android, investigation ongoing.