Skip to content
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

Add support for emitting Source Link data #110270

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

MichalStrehovsky
Copy link
Member

Fixes #81415.

We read the source link data from the portable PDB, map file names to URLs, and emit into a JSON file. Then pass the JSON file to link.exe. We make no effort to make the source link data more compact. We could attempt to find common prefixes and emit as * but I left that as a future potential extension. The extra data in the expanded form is nothing compared to the size of native PDBs.

Cc @dotnet/ilc-contrib

Fixes dotnet#81415.

We read the source link data from the portable PDB, map file names to URLs, and emit into a JSON file. Then pass the JSON file to link.exe. We make no effort to make the source link data more compact. We could attempt to find common prefixes and emit as `*` but I left that as a future potential extension. The extra data in the expanded form is nothing compared to the size of native PDBs.
/// <summary>
/// Source Link URL map. Maps file paths matching Source Link patterns to URLs.
/// </summary>
internal readonly struct SourceLinkMap
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is basically https://github.com/dotnet/sourcelink/blob/928f459936292b3128b949957c7b46ae5ed59e4c/src/SourceLink.Tools/SourceLinkMap.cs, but fixed up not to trigger warnings.

We can't use this in the NuGet form because for whatever reason this is a source code nuget (doesn't have an assembly, it contains C# source code) that triggers tons of warnings in our build. So a fork it is.

Copy link
Member

Choose a reason for hiding this comment

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

@tmat - would it be possible to update the original to comply with the runtime build environment? It would be obviously much cleaner to not have to fork it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be preferable if it was not a source code nuget. This will be an ongoing problem in source form.

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@@ -87,6 +87,7 @@ The .NET Foundation licenses this file to you under the MIT license.
</ItemGroup>

<ItemGroup>
<LinkerArg Condition="$(EnableSourceLink) == 'true'" Include="/SOURCELINK:$(NativeIntermediateOutputPath)%(ManagedBinary.Filename).sourcelink" />
Copy link
Member

Choose a reason for hiding this comment

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

EnableSourceLink is from the SDK, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, if there's a property that controls this behavior for non-AOT cases, we tend to just reuse that. SDK already defined this.

public override unsafe ReadOnlySpan<byte> GetSourceLinkData()
{
// {CC110556-A091-4D38-9FEC-25AB9A351A6A}
Guid sourceLinkDataGuid = new Guid(0xCC110556, 0xA091, 0x4D38, 0x9F, 0xEC, 0x25, 0xAB, 0x9A, 0x35, 0x1A, 0x6A);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to be a static read-only field?

Copy link
Member Author

Choose a reason for hiding this comment

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

RyuJIT might already optimize this to constant data. If it doesn't, it doesn't matter anyway, this is not perf critical and it's only a couple instructions to initialize.

@MichalStrehovsky
Copy link
Member Author

/ba-g infra signing issue on apple devices

@MichalStrehovsky MichalStrehovsky merged commit 1407892 into dotnet:main Dec 4, 2024
84 of 88 checks passed
@MichalStrehovsky MichalStrehovsky deleted the sourcelink branch December 4, 2024 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NativeAOT Populate source link information in the final PDB
5 participants