Skip to content

Conversation

@vitek-karas
Copy link
Member

While linker can recognize the hardcoded type name in the InitializeSoruceInfo it sometimes fails to resolve the type as the System.Diagnostics.StackTrace is not directly referenced by most assemblies. This is partially an internal linker limitation and the attribute is a workaround.

That said linker would not be able to recognize the GetMethod or CreateInstance calls which follow and in member-level trimming mode would not correctly keep the GetSourceLineInfo nor the .ctor of the type.

This comes with a tradeoff for small apps. Console Hello World gains almost 200K in size when trimmed aggressively (member-level trimming), because the System.Diagnostics.StackTrace has dependencies on System.IO and System.Reflection.Metadata. But without this change linker effectively breaks the functionality of showing source file information in stack traces.

See dotnet/sdk#4017 for customer issue.

@vitek-karas vitek-karas self-assigned this Feb 10, 2020
@vitek-karas
Copy link
Member Author

FYI @marek-safar: From a correctness perspective this is a good change, but it may come with non-trivial size cost.

@marek-safar
Copy link
Contributor

I am not concerned as this is coreclr specific part but could https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.StackTrace/src/ILLinkTrim.xml be now removed?

Alternatively, think about folding System.Diagnostics.StackTrace into System.Private.CoreLib to avoid all complexity caused by external assembly with 2 types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the per-assembly linking used by CoreFX build going to keep the type around without this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will as libraries are built with coreclr by default for packaging but this raises good point about handling runtime specific dependencies during libraries illinker optimization pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failures in System.Tests.ExceptionTests.VerifyCallStack tests that are popping up in the CI suggest that the type is not kept around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - I reverted the deletion of ILLinkTrim.xml.

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but I don't see how this is going to solve the reported issue. It looks to me like MarkUserDependency in the linker's MarkStep will also only look in the context's assembly cache, not add new assemblies to the closure. Did you confirm whether this works?

edit: Never mind, I forgot about the earlier step that adds assemblies referenced from these attributes to the closure. Thanks!

While linker can recognize the hardcoded type name in the InitializeSoruceInfo it sometimes fails to resolve the type as the System.Diagnostics.StackTrace is not directly referenced by most assemblies. This is partially an internal linker limitation and the attribute is a workaround.

That said linker would not be able to recognize the GetMethod or CreateInstance calls which follow and in member-level trimming mode would not correctly keep the GetSourceLineInfo nor the .ctor of the type.
This reverts commit c554f2c392a46b5d65f49a304e1ed15e1b91b852.
@vitek-karas vitek-karas force-pushed the StackFrameHelperPreserveDep branch from c554f2c to 98b8015 Compare February 17, 2020 13:12
@jkotas
Copy link
Member

jkotas commented Feb 17, 2020

The test failure is infrastructure issue: The test succeeded, but reporting the results back through helix failed.

@jkotas jkotas merged commit 768c6fc into dotnet:master Feb 17, 2020
@vitek-karas vitek-karas deleted the StackFrameHelperPreserveDep branch February 18, 2020 20:31
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants