Skip to content

[cDAC] Statically link in native dependencies #113627

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
merged 11 commits into from
Mar 25, 2025

Conversation

max-charlamb
Copy link
Contributor

@max-charlamb max-charlamb commented Mar 17, 2025

Resolves #112416

  • Creates cdac cmake component for native cdac dependencies which is built with tools.cdacreader

  • Removes Windows only load flag allowing dynamic linking of cdacreader dependencies.

  • Factors out unwinder base static library and modifies platform specific libraries to be static.

  • Links in static libraries on supported platforms

  • Reverts INSTALL_ALL_ARTIFACTS implemented in [cDAC] Implement core stackwalking #111759

@steveisok
Copy link
Member

In the unwinder cmake and in cdacreader.csproj you have proper guarding around not including unwinder_cdac_amd64.a outside of x64 targets. However, the build will fail on non-windows platforms because it'll try to static link at

What I think you'll have to do is follow through with guarding in .cs spots like you did in cmake / csproj.

That means #if TARGET_WINDOWS around:

[LibraryImport("unwinder_cdac_amd64", EntryPoint = "amd64Unwind")]
private static partial int AMD64Unwind(
ref AMD64Context context,
delegate* unmanaged<ulong, void*, int, void*, int> readFromTarget,
delegate* unmanaged<int, void**, void*, int> getAllocatedBuffer,
delegate* unmanaged<ulong, void*, void*, void*, void> getStackWalkInfo,
delegate* unmanaged<void> unwinderFail,
void* callbackContext);
public static int AMD64Unwind(
ref AMD64Context context,
Target target)
{
using CallbackContext callbackContext = new(target);
GCHandle handle = GCHandle.Alloc(callbackContext);
int ret = AMD64Unwind(
ref context,
&ReadFromTarget,
&GetAllocatedBuffer,
&GetStackWalkInfo,
&UnwinderFail,
GCHandle.ToIntPtr(handle).ToPointer());
handle.Free();
return ret;
}

You may want to throw a PNSE in the latter block.

@max-charlamb
Copy link
Contributor Author

max-charlamb commented Mar 24, 2025

In the unwinder cmake and in cdacreader.csproj you have proper guarding around not including unwinder_cdac_amd64.a outside of x64 targets. However, the build will fail on non-windows platforms because it'll try to static link at

What I think you'll have to do is follow through with guarding in .cs spots like you did in cmake / csproj.

That means #if TARGET_WINDOWS around:

[LibraryImport("unwinder_cdac_amd64", EntryPoint = "amd64Unwind")]
private static partial int AMD64Unwind(
ref AMD64Context context,
delegate* unmanaged<ulong, void*, int, void*, int> readFromTarget,
delegate* unmanaged<int, void**, void*, int> getAllocatedBuffer,
delegate* unmanaged<ulong, void*, void*, void*, void> getStackWalkInfo,
delegate* unmanaged<void> unwinderFail,
void* callbackContext);
public static int AMD64Unwind(
ref AMD64Context context,
Target target)
{
using CallbackContext callbackContext = new(target);
GCHandle handle = GCHandle.Alloc(callbackContext);
int ret = AMD64Unwind(
ref context,
&ReadFromTarget,
&GetAllocatedBuffer,
&GetStackWalkInfo,
&UnwinderFail,
GCHandle.ToIntPtr(handle).ToPointer());
handle.Free();
return ret;
}

You may want to throw a PNSE in the latter block.

Fixed by adding conditions to the <DirectPInvoke> blocks in cdacreader.csproj.

@max-charlamb max-charlamb marked this pull request as ready for review March 24, 2025 18:40
@max-charlamb max-charlamb requested review from jkoritzinsky, davidwrighton and a team March 24, 2025 18:41
@max-charlamb
Copy link
Contributor Author

/ba-g System.Net timeout #113883

@max-charlamb max-charlamb merged commit 889d514 into dotnet:main Mar 25, 2025
147 of 149 checks passed
@max-charlamb
Copy link
Contributor Author

/azp run runtime-diagnostics

@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support linking native libraries to cDAC on non-Windows platforms
3 participants