-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Should we mark MethodBase.GetCurrentMethod() and friends RequiresUnreferencedCode? #53242
Comments
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer Issue DetailsIllink started trimming bits of metadata off things that are not seen as reflected on. We have APIs that allow reflecting on basically everything in the program (e.g. While MethodBase.GetCurrentMethod is not "trim unsafe" per se, the MethodInfos returned from it might be "damaged" and will result in different runtime behavior. We have been tagging places like that so that the developer can decide whether it's acceptable. Tagging ParameterInfo.Name as trim-unsafe feels like unnecessarily big hammer - it will work if the MethodBase was retrieved through more standard means. It feels more appropriate to just tag MethodBase.GetCurrentMethod and friends as RequiresUnreferenced. E.g. the Illinker optimization is going to cause different behavior in this code. I expect we're fine with a different behavior there, but it should be a conscious decision, not a random result of an unsafe optimization. E.g. we might want to revise what happens when the parameter name was null in that codepath. runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs Lines 286 to 303 in 57bdb95
This would apply to APIs like:
|
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @vitek-karas, @agocke, @CoffeeFlux, @VSadov Issue DetailsIllink started trimming bits of metadata off things that are not seen as reflected on. We have APIs that allow reflecting on basically everything in the program (e.g. While MethodBase.GetCurrentMethod is not "trim unsafe" per se, the MethodInfos returned from it might be "damaged" and will result in different runtime behavior. We have been tagging places like that so that the developer can decide whether it's acceptable. Tagging ParameterInfo.Name as trim-unsafe feels like unnecessarily big hammer - it will work if the MethodBase was retrieved through more standard means. It feels more appropriate to just tag MethodBase.GetCurrentMethod and friends as RequiresUnreferenced. E.g. the Illinker optimization is going to cause different behavior in this code. I expect we're fine with a different behavior there, but it should be a conscious decision, not a random result of an unsafe optimization. E.g. we might want to revise what happens when the parameter name was null in that codepath. runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs Lines 286 to 303 in 57bdb95
This would apply to APIs like:
|
I think it makes sense to annotate these. We'll see how widespread the usage is. If it's too bad we may consider supporting some of these view instrinsics if possible to avoid warnings (For example the |
Fixes dotnet#53242. Saddened this didn't make .NET 6.0. Stack traces in trimmed apps look ugly without this fix: ``` Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'id') at System.TimeZoneInfo.ValidateTimeZoneInfo(String , TimeSpan , AdjustmentRule[] , Boolean& ) at System.TimeZoneInfo..ctor(String , TimeSpan , String , String , String , AdjustmentRule[] , Boolean , Boolean ) at System.TimeZoneInfo.CreateCustomTimeZone(String , TimeSpan , String , String ) at Program.<Main>$(String[] args) in C:\stacktrace\Program.cs:line 3 ```
Fixes #53242. Saddened this didn't make .NET 6.0. Stack traces in trimmed apps look ugly without this fix: ``` Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'id') at System.TimeZoneInfo.ValidateTimeZoneInfo(String , TimeSpan , AdjustmentRule[] , Boolean& ) at System.TimeZoneInfo..ctor(String , TimeSpan , String , String , String , AdjustmentRule[] , Boolean , Boolean ) at System.TimeZoneInfo.CreateCustomTimeZone(String , TimeSpan , String , String ) at Program.<Main>$(String[] args) in C:\stacktrace\Program.cs:line 3 ```
Illink started trimming bits of metadata off things that are not seen as reflected on. We have APIs that allow reflecting on basically everything in the program (e.g.
MethodBase.GetCurrentMethod()
). One of the bits illinker strips is parameter names.While MethodBase.GetCurrentMethod is not "trim unsafe" per se, the MethodInfos returned from it might be "damaged" and will result in different runtime behavior. We have been tagging places like that so that the developer can decide whether it's acceptable. Tagging ParameterInfo.Name as trim-unsafe feels like unnecessarily big hammer - it will work if the MethodBase was retrieved through more standard means. It feels more appropriate to just tag MethodBase.GetCurrentMethod and friends as RequiresUnreferenced.
E.g. the Illinker optimization is going to cause different behavior in this code. I expect we're fine with a different behavior there, but it should be a conscious decision, not a random result of an unsafe optimization. E.g. we might want to revise what happens when the parameter name was null in that codepath.
runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs
Lines 286 to 303 in 57bdb95
This would apply to APIs like:
Exception.TargetSite
andStackFrame.GetMethod
too.The text was updated successfully, but these errors were encountered: