[API Proposal]: Optional export of UnmanagedCallersOnlyAttribute

Open
#114,733 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp, csharp
Domain
api

Research direction

Start with the UnmanagedCallersOnlyAttribute API proposal and its C# and C++ usage examples. Determine how the requested Export value should affect native symbol exposure while retaining the specified entry point. Done means the proposed API behavior is agreed and validated for the interop scenarios described.

Written by the indexing model from the issue text.

Description

api-suggestion area-Interop-coreclr
Background and motivation

Some funcs are only used for native interop with static libraries and we don't want them exported, so we need a new field to UnmanagedCallersOnlyAttribute to control whether the method is exported.

API Proposal
    [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)]
    public sealed class UnmanagedCallersOnlyAttribute : System.Attribute
    {
         public UnmanagedCallersOnlyAttribute() { }
         public System.Type[]? CallConvs;
         public string? EntryPoint;
+        public bool Export = true;
     }
API Usage
[UnmanagedCallersOnly(EntryPoint = "InternalSum", Export = false)]
public static int InternalSum(int a, int b) => a + b;
extern "C" int InternalSum(int a, int b);

extern "C" __declspec(dllexport) capi_get_number() {
    return InternalSum(114, 514);
}
Alternative Designs

No response

Risks

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.