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

Encode calling convention in mangled function pointer representation #81122

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

trylek
Copy link
Member

@trylek trylek commented Jan 24, 2023

This fixes the recently introduced issue #81106 tracking Crossgen2 crash due to not being able to distinguish two function pointers differing only by calling convention (one of the pointers is Static and the other is Static | UnmanagedCallingConvention).

Thanks

Tomas

Fixes: #81106

/cc @dotnet/crossgen-contrib

@trylek trylek added this to the 8.0.0 milestone Jan 24, 2023
@trylek trylek requested a review from jkotas January 24, 2023 20:41
@ghost ghost assigned trylek Jan 24, 2023
@trylek
Copy link
Member Author

trylek commented Jan 24, 2023

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

var fnPtrType = (FunctionPointerType)type;
mangledName = "__FnPtr" + EnterNameScopeSequence;
mangledName = "__FnPtr_" + ((int)fnPtrType.Signature.Flags).ToString("X2") + EnterNameScopeSequence;
Copy link
Member

Choose a reason for hiding this comment

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

@steveharter what was the decision about function pointer type identity within the runtime? Do we only consider the value of the legacy "calling convention flags" or do we also include calling conventions from modopts, or do we consider all modopts everywhere in the signature?

(I admit I dropped the ball on following the discussion. I'll need to read up on it to actually implement this in nativeaot but can't spend time on it right now.)

This fix looks good if we only consider the legacy calling convention flags.

Copy link
Member

Choose a reason for hiding this comment

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

Are runtime tests running with NativeAOT? It seems that there is a gap in NativeAOT as well. I don't recall seeing the function pointer tests failing for NativeAOT.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fanyang-mono I defer to Michal to elaborate in more detail, according to the running times and the logs I'm seeing for the NativeAOT legs in the runtime (PR / CI) pipeline I'm guessing that right now just a small subset of Pri0 tests gets run on a regular basis in NativeAOT mode.

Copy link
Member

Choose a reason for hiding this comment

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

This codepath is only exercised in obscure cases in NativeAOT - #71749. Most of the time function pointers are treated as IntPtr right now. It will have to change for .NET 8.

And yes, we don't run regular Pri0/Pri1 CoreCLR test suite runs right now. Another thing getting addressed for 8.0.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha!

Copy link
Member

@jkotas jkotas Jan 30, 2023

Choose a reason for hiding this comment

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

@steveharter what was the decision about function pointer type identity within the runtime?

@steveharter is on vacation.

In current main, the function pointer runtime type identity includes calling convention from signature. Modopts are not included in the function pointer runtime type identity.

After #81006, the function pointer runtime type identity is only going to include managed vs. unmanaged. The full calling convention details and modopts are not going to be part of function pointer runtime type identity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Jan and Michal for your feedback. I have deleted the superfluous comment per Michal's suggestion in the 2nd commit.

@trylek
Copy link
Member Author

trylek commented Jan 27, 2023

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@trylek
Copy link
Member Author

trylek commented Jan 30, 2023

@steveharter - could you please respond to @MichalStrehovsky's question when you have a chance? We're trying to stay on top of customer bug escalations and I'm having an active Teams thread with Mono folks who need the fix getting backported to .NET 7 so I'm trying to figure out how to make it at least to main.

This fixes the recently introduced issue dotnet#81106 tracking Crossgen2
crash due to not being able to distinguish two function pointers
differing only by calling convention (one of the pointers is Static
and the other is Static | UnmanagedCallingConvention).

Thanks

Tomas
@trylek
Copy link
Member Author

trylek commented Jan 30, 2023

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@trylek trylek closed this Jan 31, 2023
@trylek trylek reopened this Jan 31, 2023
@trylek
Copy link
Member Author

trylek commented Jan 31, 2023

/azp runtime-coreclr outerloop

@azure-pipelines
Copy link

Command 'runtime-coreclr' is not supported by Azure Pipelines.

Supported commands
  • help:
    • Get descriptions, examples and documentation about supported commands
    • Example: help "command_name"
  • list:
    • List all pipelines for this repository using a comment.
    • Example: "list"
  • run:
    • Run all pipelines or specific pipelines for this repository using a comment. Use this command by itself to trigger all related pipelines, or specify specific pipelines to run.
    • Example: "run" or "run pipeline_name, pipeline_name, pipeline_name"
  • where:
    • Report back the Azure DevOps orgs that are related to this repository and org
    • Example: "where"

See additional documentation.

@trylek
Copy link
Member Author

trylek commented Jan 31, 2023

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@trylek
Copy link
Member Author

trylek commented Jan 31, 2023

The one failure in the DictionaryExpansion test on Windows x86 is known,

#75244

I'll probably take the bug as it's currently assigned to @davidwrighton who's expected to be OOF for a prolonged period of time. I'm going to merge this in assuming no other untracked issues pop up in the remaining outerloop jobs.

@trylek
Copy link
Member Author

trylek commented Jan 31, 2023

OK, there's one more bug but that's also known, #81109, I'm actually investigating it right now, that's obviously unrelated to this change, merging in.

@trylek trylek merged commit f70d8a9 into dotnet:main Jan 31, 2023
@trylek trylek deleted the 81106 branch January 31, 2023 20:52
@trylek
Copy link
Member Author

trylek commented Jan 31, 2023

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/4058243565

@github-actions
Copy link
Contributor

@trylek backporting to release/7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Encode calling convention in mangled function pointer representation
Applying: Delete superfluous comment per Michal's PR feedback
Applying: Remove issues.targets exclusion for the function pointer test
Using index info to reconstruct a base tree...
M	src/tests/issues.targets
Falling back to patching base and 3-way merge...
Auto-merging src/tests/issues.targets
CONFLICT (content): Merge conflict in src/tests/issues.targets
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0003 Remove issues.targets exclusion for the function pointer test
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@trylek an error occurred while backporting to release/7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

trylek added a commit that referenced this pull request Feb 2, 2023
Based on tactical discussion with Fan and Sam I have backported
the PR #81122 including the removal of the issues.targets entry
for function pointer tests as an extra commit on top of
the backport of Fan's PR #80855.

Thanks

Tomas
carlossanlop pushed a commit that referenced this pull request Feb 8, 2023
* Fix function pointer check

* Make is_monomorphic_array return false when the element is function pointer

* Move test to a better location

* Disable function pointer test for crossgen due to an existing issue

* Backport of PR #81122 to .NET 7.0, revert change to issues.targets

Based on tactical discussion with Fan and Sam I have backported
the PR #81122 including the removal of the issues.targets entry
for function pointer tests as an extra commit on top of
the backport of Fan's PR #80855.

Thanks

Tomas

---------

Co-authored-by: Fan Yang <yangfan@microsoft.com>
Co-authored-by: Fan Yang <52458914+fanyang-mono@users.noreply.github.com>
Co-authored-by: Tomas <trylek@microsoft.com>
@ghost ghost locked as resolved and limited conversation to collaborators Mar 3, 2023
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.

Test failure Loader\\classloader\\Casting\\Functionpointer\\Functionpointer.cmd
4 participants