Skip to content

Conversation

radekdoulik
Copy link
Member

Fixes #120319

@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 15:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes an issue where MarkPrecodeAsStableEntrypoint was being called on portable entrypoints, which is not appropriate behavior. The fix adds conditional compilation to ensure this method is only called when FEATURE_PORTABLE_ENTRYPOINTS is not defined.

  • Added #ifndef FEATURE_PORTABLE_ENTRYPOINTS guard around MarkPrecodeAsStableEntrypoint call

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@radekdoulik
Copy link
Member Author

We were reaching that for instantiating stubs.

I assume we don't want to call MarkPrecodeAsStableEntrypoint for portable entrypoints, because we don't have the real precodes.

@AaronRobinsonMSFT @jkotas Are there any other cases which might be relevant? I think if we reach a path, where we don't have IL, we will fail later when trying to call the method and it will be more clear.

{
// The rest of the system assumes that certain methods always have stable entrypoints.
// Mark the precode as such
MarkPrecodeAsStableEntrypoint();
Copy link
Member

Choose a reason for hiding this comment

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

This is needed. See the implementation in MarkPrecodeAsStableEntrypoint().

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem related to the referenced issue, #120319, that states Precode::GetPrecodeFromEntryPoint(). We should be examining the callsite of Precode::GetPrecodeFromEntryPoint() and understand its intent.

Copy link
Member

@jkotas jkotas Oct 8, 2025

Choose a reason for hiding this comment

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

I agree with Aaron that we should be cleaning this up more aggressively so that we do not have to be finding and fixing Precode paths one at a time.

For example, can we place all occurrences of HasPrecode/GetPrecode/enum_flag3_HasPrecode under #ifndef FEATURE_PORTABLE_ENTRYPOINTS? If we are not ready this yet, change HasPrecode to return unconditional false and ifdef out enum_flag3_HasPrecode flag at least?

Copy link
Member Author

@radekdoulik radekdoulik Oct 8, 2025

Choose a reason for hiding this comment

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

This is needed. See the implementation in MarkPrecodeAsStableEntrypoint().

Could you give me more context here? Besides asserts, it sets the HasStableEntryPoint and HasPrecode flags. My assumption was that we don't want any of these flags set as the portable entrypoints are stable once we pass DoPrestub(...) and we don't have real precode, so we don't want to have that flag set either.

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 doesn't seem related to the referenced issue, #120319, that states Precode::GetPrecodeFromEntryPoint(). We should be examining the callsite of Precode::GetPrecodeFromEntryPoint() and understand its intent.

What is happening here is that we set HasStableEntrypoint and HasPrecode in MethodDesc::MarkPrecodeAsStableEntrypoint(). Later we reach the assert in Precode::GetPrecodeFromEntryPoint() when MethodDesc::IsPointingToPrestub() checks these flags and because they are set and it calls GetPrecode()->IsPointingToPrestub(). The end of stacktrace looks like this:

Precode::GetPrecodeFromEntryPoint(unsigned long, int) (/Users/rodo/git/runtime-main/src/coreclr/vm/precode_portable.cpp:170)
MethodDesc::GetPrecode() (/Users/rodo/git/runtime-main/src/coreclr/vm/method.hpp:387)
MethodDesc::IsPointingToPrestub() (/Users/rodo/git/runtime-main/src/coreclr/vm/method.cpp:2395)
CallPreStub(MethodDesc*) (/Users/rodo/git/runtime-main/src/coreclr/vm/interpexec.cpp:684)
InterpExecMethod(InterpreterFrame*, InterpMethodContextFrame*, InterpThreadContext*, ExceptionClauseArgs*) 
...

It makes the failing test from #120319 pass.

Copy link
Member

Choose a reason for hiding this comment

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

@radekdoulik I see what you're saying here. This is part of the work that didn't get completed during the initial work I was doing. If you look at precode_portable.hpp, there are many dummy implemntations for the Precode infrastructure. We should work on removing all of those and defining them away. I will work on this tomorrow too.

Copy link
Member Author

Choose a reason for hiding this comment

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

@AaronRobinsonMSFT This sounds great. Do you want me to make more changes here, so we can merge it or do you want to make it part of your changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

How many GetOrCreatePrecode calls are left in FEATURE_PORTABLE_ENTRYPOINTS build? Is it hard to ifdef them?

There are still few places, when I ifdef it out, I am getting

wasm-ld: error: ../../dlls/mscoree/coreclr/libcoreclr_static.a(jitinterface.cpp.o): undefined symbol: MethodDesc::GetOrCreatePrecode()
wasm-ld: error: ../../dlls/mscoree/coreclr/libcoreclr_static.a(jitinterface.cpp.o): undefined symbol: MethodDesc::GetOrCreatePrecode()
wasm-ld: error: ../../dlls/mscoree/coreclr/libcoreclr_static.a(method.cpp.o): undefined symbol: MethodDesc::GetOrCreatePrecode()
wasm-ld: error: ../../dlls/mscoree/coreclr/libcoreclr_static.a(prestub.cpp.o): undefined symbol: MethodDesc::GetOrCreatePrecode()
wasm-ld: error: ../../dlls/mscoree/coreclr/libcoreclr_static.a(dllimport.cpp.o): undefined symbol: MethodDesc::GetOrCreatePrecode()

Copy link
Member

Choose a reason for hiding this comment

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

@AaronRobinsonMSFT This sounds great. Do you want me to make more changes here, so we can merge it or do you want to make it part of your changes?

I would close this PR. There is a non-trivial amount of clean-up here and I've already got a head start on some of it. Thanks for pushing on the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great, thanks for looking at it.

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.

[wasm][coreclr] bc.GenericVirtualMethod<string> failing in the interpreter test

3 participants